-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #613 from OneCommunityGlobal/rhea/newlesson_backend
Rhea create newLessom routes and controller
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters