Skip to content

Commit

Permalink
Merge pull request #755 from OneCommunityGlobal/rhea/buildingIssue
Browse files Browse the repository at this point in the history
rhea latest commit on issue backend
  • Loading branch information
one-community authored Feb 27, 2024
2 parents 6e41aa0 + 9bfc47f commit cd1d8ea
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/controllers/bmdashboard/bmIssueController.js
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions src/models/bmdashboard/buildingIssue.js
Original file line number Diff line number Diff line change
@@ -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');
13 changes: 13 additions & 0 deletions src/routes/bmdashboard/bmIssueRouter.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
};

0 comments on commit cd1d8ea

Please sign in to comment.