diff --git a/src/controllers/bmdashboard/bmIssueController.js b/src/controllers/bmdashboard/bmIssueController.js new file mode 100644 index 000000000..3341be22d --- /dev/null +++ b/src/controllers/bmdashboard/bmIssueController.js @@ -0,0 +1,29 @@ +const mongoose = require('mongoose'); + +const bmIssueController = function (BuildingIssue) { + const bmGetIssue = async (req, res) => { + try { + BuildingIssue + .find() + .populate() + .then(result => res.status(200).send(result)) + .catch(error => res.status(500).send(error)); + } catch (err) { + res.json(err); + } + }; + + const bmPostIssue = async (req, res) => { + try { + const newIssue = BuildingIssue.create(req.body) + .then(result => res.status(201).send(result)) + .catch(error => res.status(500).send(error)); + } catch (err) { + res.json(err); + } + }; + + return { bmGetIssue, bmPostIssue }; +}; + +module.exports = bmIssueController; diff --git a/src/models/bmdashboard/buildingIssue.js b/src/models/bmdashboard/buildingIssue.js new file mode 100644 index 000000000..089117ce1 --- /dev/null +++ b/src/models/bmdashboard/buildingIssue.js @@ -0,0 +1,17 @@ +const mongoose = require('mongoose'); + +const { Schema } = mongoose; + +const buildingIssue = new Schema({ + createdDate: { type: Date, required: true, default: Date.now() }, + issueDate: { type: String, required: true }, + createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile', required: true }, + staffInvolved: [{ type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' }], + issueTitle: [{ type: String, required: true, maxLength: 50 }], + issueText: [{ type: String, required: true, maxLength: 500 }], + imageUrl: [{ type: String }], + // not sure if we still need related lesson here: + // relatedLesson: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingNewLesson', required: true }, +}); + +module.exports = mongoose.model('buildingIssue', buildingIssue, 'buildingIssues'); \ No newline at end of file diff --git a/src/routes/bmdashboard/bmIssueRouter.js b/src/routes/bmdashboard/bmIssueRouter.js new file mode 100644 index 000000000..99c4c022d --- /dev/null +++ b/src/routes/bmdashboard/bmIssueRouter.js @@ -0,0 +1,13 @@ +const express = require('express'); + +const routes = function (buildingIssue) { + const IssueRouter = express.Router(); + const controller = require('../../controllers/bmdashboard/bmIssueController')(buildingIssue); + + IssueRouter.route('/issues') + .get(controller.bmGetIssue); + IssueRouter.route('/issue/add') + .post(controller.bmPostIssue); + return IssueRouter; +}; +module.exports = routes; diff --git a/src/startup/routes.js b/src/startup/routes.js index 6d44726e3..b650ef824 100644 --- a/src/startup/routes.js +++ b/src/startup/routes.js @@ -25,6 +25,7 @@ const permissionChangeLog = require('../models/permissionChangeLog'); const mapLocations = require('../models/mapLocation'); const buildingProject = require('../models/bmdashboard/buildingProject'); const buildingNewLesson = require('../models/bmdashboard/buildingNewLesson'); +const buildingIssue = require('../models/bmdashboard/buildingIssue'); const { invTypeBase, materialType, @@ -123,6 +124,9 @@ const bmInventoryTypeRouter = require('../routes/bmdashboard/bmInventoryTypeRout const bmToolRouter = require('../routes/bmdashboard/bmToolRouter')( buildingTool, ); +const bmIssueRouter = require('../routes/bmdashboard/bmIssueRouter')( + buildingIssue, +); module.exports = function (app) { app.use('/api', forgotPwdRouter); @@ -165,4 +169,5 @@ module.exports = function (app) { app.use('/api/bm', bmToolRouter); app.use('/api/bm', bmConsumablesRouter); app.use('/api', timeOffRequestRouter); + app.use('api', bmIssueRouter); };