Skip to content

Commit

Permalink
Merge pull request #613 from OneCommunityGlobal/rhea/newlesson_backend
Browse files Browse the repository at this point in the history
Rhea create newLessom routes and controller
  • Loading branch information
tdkent authored Jan 18, 2024
2 parents ac674f2 + 7be6b64 commit 0c4f24a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/controllers/bmdashboard/bmNewLessonController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const mongoose = require('mongoose');

const bmNewLessonController = function (BuildingNewLesson) {
const bmGetLessonList = async (req, res) => {
try {
BuildingNewLesson
.find()
.populate()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};
const bmPostLessonList = async (req, res) => {
try {
const newLesson = BuildingNewLesson.create(req.body)
.then(result => res.status(201).send(result))
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};
return { bmPostLessonList, bmGetLessonList };
};

module.exports = bmNewLessonController;
14 changes: 14 additions & 0 deletions src/models/bmdashboard/buildingNewLesson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const mongoose = require('mongoose');

const { Schema } = mongoose;

const buildingNewLesson = new Schema({
title: { type: String, required: true, maxLength: 20 },
content: { type: String, required: true, maxLength: 500 },
date: { type: Date, required: true, default: Date.now() },
author: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile', required: true },
tags: [{ type: String, required: true, maxLength: 10 }],
relatedProject: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingProject', required: true },
});

module.exports = mongoose.model('buildingNewLesson', buildingNewLesson, 'buildingNewLessons');
15 changes: 15 additions & 0 deletions src/routes/bmdashboard/bmNewLessonRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require('express');

const routes = function (buildingNewLesson) {
const NewLessonRouter = express.Router();
const controller = require('../../controllers/bmdashboard/bmNewLessonController')(buildingNewLesson);

// having GET request just for testing:
NewLessonRouter.route('/lessons')
.get(controller.bmGetLessonList);

NewLessonRouter.route('/lessons/new')
.post(controller.bmPostLessonList);
return NewLessonRouter;
};
module.exports = routes;
5 changes: 4 additions & 1 deletion src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const mouseoverText = require('../models/mouseoverText');
// const inventoryItemMaterial = require('../models/inventoryItemMaterial');
const mapLocations = require('../models/mapLocation');
const buildingProject = require('../models/bmdashboard/buildingProject');
const buildingNewLesson = require('../models/bmdashboard/buildingNewLesson');
// const buildingMaterial = require('../models/bmdashboard/buildingMaterial');
const {
invTypeBase,
Expand Down Expand Up @@ -78,6 +79,7 @@ const mapLocationRouter = require('../routes/mapLocationsRouter')(mapLocations);
const bmLoginRouter = require('../routes/bmdashboard/bmLoginRouter')();
const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(buildingMaterial);
const bmProjectRouter = require('../routes/bmdashboard/bmProjectRouter')(buildingProject);
const bmNewLessonRouter = require('../routes/bmdashboard/bmNewLessonRouter')(buildingNewLesson);
const bmConsumablesRouter = require('../routes/bmdashboard/bmConsumablesRouter')(buildingConsumable);
const bmInventoryTypeRouter = require('../routes/bmdashboard/bmInventoryTypeRouter')(invTypeBase, materialType, consumableType, reusableType, toolType, equipmentType);
const bmToolRouter = require('../routes/bmdashboard/bmToolRouter')(buildingTool);
Expand Down Expand Up @@ -116,7 +118,8 @@ module.exports = function (app) {
app.use('/api/bm', bmLoginRouter);
app.use('/api/bm', bmMaterialsRouter);
app.use('/api/bm', bmProjectRouter);
app.use('/api/bm', bmNewLessonRouter);
app.use('/api/bm', bmInventoryTypeRouter);
app.use('/api/bm', bmToolRouter);
app.use('/api/bm', bmConsumablesRouter);
};
};

0 comments on commit 0c4f24a

Please sign in to comment.