Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rhea create newLessom routes and controller #613

Merged
merged 87 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
457d02a
Merge pull request #428 from OneCommunityGlobal/development
one-community Jun 29, 2023
7ee4602
Merge pull request #433 from OneCommunityGlobal/development
one-community Jul 2, 2023
5bbbfaf
Merge pull request #436 from OneCommunityGlobal/development
one-community Jul 6, 2023
71cb810
Merge pull request #442 from OneCommunityGlobal/development
one-community Jul 16, 2023
e9739e0
Merge pull request #444 from OneCommunityGlobal/development
one-community Jul 18, 2023
76deba3
Revert "Backend Release to Main [0.78]"
one-community Jul 19, 2023
d4ae934
Merge pull request #447 from OneCommunityGlobal/revert-444-development
one-community Jul 19, 2023
891d1c7
Revert "Revert "Backend Release to Main [0.78]""
one-community Jul 19, 2023
5154595
Merge pull request #448 from OneCommunityGlobal/revert-447-revert-444…
one-community Jul 19, 2023
ee27ecb
Merge pull request #462 from OneCommunityGlobal/development
one-community Jul 26, 2023
8dd903f
Merge pull request #463 from OneCommunityGlobal/development
one-community Jul 29, 2023
b8fc5bf
Merge pull request #469 from OneCommunityGlobal/development
one-community Aug 7, 2023
91a0e66
Merge pull request #471 from OneCommunityGlobal/development
one-community Aug 12, 2023
af8b47e
Merge pull request #475 from OneCommunityGlobal/development
one-community Aug 19, 2023
2be1879
Merge pull request #477 from OneCommunityGlobal/development
one-community Aug 21, 2023
3ae790e
Merge pull request #478 from OneCommunityGlobal/development
one-community Aug 21, 2023
95ac172
Merge pull request #483 from OneCommunityGlobal/development
one-community Aug 24, 2023
feb9c91
Merge pull request #487 from OneCommunityGlobal/development
one-community Aug 26, 2023
a6acd9e
Revert "Backend Release to Main [0.87]"
one-community Aug 26, 2023
bedfb7a
Merge pull request #488 from OneCommunityGlobal/revert-487-development
one-community Aug 26, 2023
db38be4
Merge pull request #491 from OneCommunityGlobal/development
one-community Aug 27, 2023
94de9b9
Merge pull request #492 from OneCommunityGlobal/development
one-community Aug 29, 2023
dedb3a2
Merge pull request #497 from OneCommunityGlobal/development
one-community Sep 1, 2023
805d377
Merge pull request #500 from OneCommunityGlobal/development
one-community Sep 2, 2023
bc296eb
Merge pull request #502 from OneCommunityGlobal/development
one-community Sep 2, 2023
16a605c
Merge pull request #504 from OneCommunityGlobal/development
one-community Sep 2, 2023
3611ace
Merge pull request #509 from OneCommunityGlobal/development
one-community Sep 3, 2023
b5058c5
Revert "Backend Release to Main [0.94]"
one-community Sep 3, 2023
bf63506
Merge pull request #510 from OneCommunityGlobal/revert-509-development
one-community Sep 3, 2023
c1bbc9b
Merge pull request #514 from OneCommunityGlobal/development
one-community Sep 3, 2023
69415b9
Merge pull request #516 from OneCommunityGlobal/development
one-community Sep 3, 2023
336c4e1
Revert "Backend Release to Main [0.96]"
one-community Sep 3, 2023
23c1ecf
Merge pull request #517 from OneCommunityGlobal/revert-516-development
one-community Sep 3, 2023
97abf31
Revert "Revert "Backend Release to Main [0.96]""
one-community Sep 3, 2023
5cb9fa1
Merge pull request #520 from OneCommunityGlobal/revert-517-revert-516…
one-community Sep 3, 2023
7a7d717
Merge pull request #521 from OneCommunityGlobal/development
one-community Sep 3, 2023
3df5e48
Revert "Backend Release to Main [0.97]"
one-community Sep 3, 2023
80ad009
Merge pull request #522 from OneCommunityGlobal/revert-521-development
one-community Sep 3, 2023
3759010
Revert "Revert "Revert "Backend Release to Main [0.96]"""
one-community Sep 3, 2023
33e075c
Merge pull request #524 from OneCommunityGlobal/revert-520-revert-517…
one-community Sep 3, 2023
db73657
Merge pull request #525 from OneCommunityGlobal/development
one-community Sep 3, 2023
f6ca186
Merge pull request #528 from OneCommunityGlobal/development
one-community Sep 6, 2023
58689de
Merge pull request #535 from OneCommunityGlobal/development
one-community Sep 13, 2023
59f02c7
Merge pull request #538 from OneCommunityGlobal/development
one-community Sep 19, 2023
7281e5d
Merge pull request #542 from OneCommunityGlobal/development
one-community Sep 20, 2023
010a0eb
Merge pull request #544 from OneCommunityGlobal/development
one-community Sep 21, 2023
e80c4f3
Merge pull request #548 from OneCommunityGlobal/development
one-community Sep 26, 2023
2c07013
Merge pull request #554 from OneCommunityGlobal/development
one-community Sep 30, 2023
1d6ff78
Merge pull request #557 from OneCommunityGlobal/development
one-community Oct 1, 2023
47ec9e4
Merge pull request #558 from OneCommunityGlobal/development
one-community Oct 2, 2023
ffa9aa9
Merge pull request #564 from OneCommunityGlobal/development
one-community Oct 9, 2023
7ecbca5
Merge pull request #568 from OneCommunityGlobal/development
one-community Oct 12, 2023
2351efb
Merge pull request #573 from OneCommunityGlobal/development
one-community Oct 18, 2023
0e8d59e
Merge pull request #578 from OneCommunityGlobal/development
one-community Oct 19, 2023
3aab006
Merge pull request #579 from OneCommunityGlobal/development
one-community Oct 20, 2023
2d9bc69
Merge pull request #581 from OneCommunityGlobal/development
one-community Oct 21, 2023
8b51775
Merge pull request #584 from OneCommunityGlobal/development
one-community Oct 24, 2023
539c618
Merge pull request #589 from OneCommunityGlobal/development
one-community Oct 27, 2023
1a95807
Merge pull request #593 from OneCommunityGlobal/development
one-community Oct 31, 2023
d45e601
Merge pull request #598 from OneCommunityGlobal/development
one-community Nov 7, 2023
faf0cce
Merge pull request #607 from OneCommunityGlobal/development
one-community Nov 11, 2023
e86c747
rhea create newLessom routes and controller
RheaWu1212 Nov 15, 2023
f1d91c7
Merge pull request #615 from OneCommunityGlobal/development
one-community Nov 17, 2023
81c38ae
Merge pull request #617 from OneCommunityGlobal/development
one-community Nov 19, 2023
dac03d4
Merge pull request #620 from OneCommunityGlobal/development
one-community Nov 28, 2023
58a7b38
Merge pull request #625 from OneCommunityGlobal/development
one-community Nov 29, 2023
2a2c39d
Merge pull request #626 from OneCommunityGlobal/development
one-community Nov 29, 2023
27877a4
Merge pull request #632 from OneCommunityGlobal/development
one-community Dec 1, 2023
8ca4484
Revert "Backend Release to Main [1.23]"
xaanders Dec 2, 2023
20d087f
Rhea adding newLesson schema and set up db
RheaWu1212 Dec 2, 2023
f0fded3
Merge pull request #636 from OneCommunityGlobal/revert-632-development
one-community Dec 2, 2023
f28f4e6
Merge pull request #637 from OneCommunityGlobal/development
one-community Dec 2, 2023
282b72b
updating controller
RheaWu1212 Dec 9, 2023
da3a2ce
Merge pull request #652 from OneCommunityGlobal/development
one-community Dec 13, 2023
92a1d71
new lesson controller part 1
RheaWu1212 Dec 16, 2023
4f6e7a6
Merge pull request #658 from OneCommunityGlobal/development
one-community Dec 16, 2023
8bf159d
get function using find() return empty array
RheaWu1212 Dec 18, 2023
8e575c6
Merge pull request #662 from OneCommunityGlobal/development
one-community Dec 20, 2023
5659686
Merge pull request #669 from OneCommunityGlobal/development
one-community Dec 24, 2023
e079093
fix conflicts
tdkent Dec 27, 2023
dbf8843
fix userHelper crash
tdkent Dec 27, 2023
7e054ed
update new lesson schema. update endpoint strings.
tdkent Dec 27, 2023
639204b
rhea edit newlesson controller, GET function working, POST function w…
RheaWu1212 Dec 30, 2023
0051d81
updated controller with 201 status code and tested tags array for POS…
RheaWu1212 Jan 4, 2024
8150d0d
fix conflicts in routes.js
tdkent Jan 9, 2024
4da0d46
update pr template to match dev branch
tdkent Jan 9, 2024
7be6b64
fix conflict in routes.js
tdkent Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ To test this backend PR you need to checkout the #XXX frontend PR.
## How to test:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • did you mean to revert this file to an older version? Make sure to change it back to its current version if not.
  • you can use Source Control in VS Code or git status to check which files have been updated before committing. Changes you're not expecting or that are not relevant to your branch can be discarded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm about to ask you about that, because when I use git status, it showed up that file which I don't even know what that, and I only added my controller file when I did git add <controller name>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see files that you did not update after using git status I would just discard those changes. Source Control in VSC makes that really easy if you have it set up.

For now, I would just copy/paste the code for this file from the dev branch and make another commit.

1. check into current branch
2. do `npm install` and `...` to run this PR locally
3. Clear site data/cache
4. log as admin user
5. go to dashboard→ Tasks→ task→…
6. verify function “A” (feel free to include screenshot here)
3. log as admin user
4. go to dashboard→ Tasks→ task→…
5. verify function “A” (feel free to include screenshot here)

## Screenshots or videos of changes:

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/controllers/bmdashboard/bmNewLessonController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 { id, title, content, author, tag, relatedProject} = req.body;
Copy link
Contributor

@tdkent tdkent Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You don't need to deconstruct req.body if you are not using the variables. Line 17 can either be omitted or used to define a new variable such as const newDoc = req.body; const newLesson = BuildingNewLesson.create(newDoc);
  • tags is not updating because Mongo ignores fields that don't exactly match the model. Make sure to rename tag to tags.

const newLesson = BuildingNewLesson.create(req.body);
newLesson.save().then(result => res.status(200).send(result))
Copy link
Contributor

@tdkent tdkent Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.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;
4 changes: 4 additions & 0 deletions src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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 buildingInventoryType = require('../models/bmdashboard/buildingInventoryType');
const buildingMaterial = require('../models/bmdashboard/buildingMaterial');

Expand Down Expand Up @@ -64,6 +66,7 @@ const mapLocationRouter = require('../routes/mapLocationsRouter')(mapLocations);
const bmLoginRouter = require('../routes/bmdashboard/bmLoginRouter')();
const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(inventoryItemMaterial, buildingMaterial);
const bmProjectRouter = require('../routes/bmdashboard/bmProjectRouter')(buildingProject);
const bmNewLessonRouter = require('../routes/bmdashboard/bmNewLessonRouter')(buildingNewLesson);
const bmInventoryTypeRouter = require('../routes/bmdashboard/bmInventoryTypeRouter')(buildingInventoryType);

module.exports = function (app) {
Expand Down Expand Up @@ -100,5 +103,6 @@ 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);
};
Loading