diff --git a/backend/docs/StudyPlan.md b/backend/docs/StudyPlan.md index fdb7f12adc75af67cfd86c5f89dcf1d32c64011e..e64c6ad4d9236dc846e19b877612448c844f7d47 100644 --- a/backend/docs/StudyPlan.md +++ b/backend/docs/StudyPlan.md @@ -13,6 +13,7 @@ "creditsTotal": 2, "semester": "2", "status": "DRAFT", + "notes": "LGTM", "createdAt": "2021-03-14T10:59:28.652Z", "updatedAt": "2021-03-14T10:59:28.652Z", "studentId": "32657182-8849-4783-a141-51f29c008fc5", @@ -36,6 +37,7 @@ "creditsTotal": 0, "semester": "1", "status": "DRAFT", + "notes": "LGTM", "createdAt": "2021-03-13T13:24:37.317Z", "updatedAt": "2021-03-13T13:24:37.317Z", "studentId": "7d9d0f64-ee6a-44d6-b56c-e9d9fd75de0d" @@ -66,6 +68,7 @@ "startYear": 2021, "semester": 1, "status": "DRAFT", // Optional + "notes": "LGTM", // Optional "studyPlanCourses" : [ //Optional { "courseClassId": "c2353c52-9543-4135-9d1d-b9a0f96e64e2", @@ -88,6 +91,7 @@ "creditsTotal": 8, "semester": "1", "status": "DRAFT", + "notes": "LGTM", "studyPlanCourses": [ { "id": "d74d549b-250d-49ba-a90f-42fb16de2ae1", @@ -160,6 +164,7 @@ ```json { "status": "FINAL", + "notes": "LGTM", "studyPlanCourses": [ { "courseClassId": "fe9d83cb-26c3-42a9-838a-20d66266e073" }, { "courseClassId": "9c643f0b-7cdd-4d02-aacd-d33347fdfc0b" }, @@ -177,6 +182,7 @@ "creditsTotal": 11, "semester": "1", "status": "FINAL", + "notes": "LGTM", "createdAt": "2021-03-15T08:28:35.937Z", "updatedAt": "2021-03-15T08:28:54.642Z", "studentId": "694588c4-237b-491e-baa6-0058660381a1", diff --git a/backend/src/controllers/study-plan.js b/backend/src/controllers/study-plan.js index ec34cce800b53f79c9f68b12611acf06f284616f..3df226e6d22bec08085947f4942dd39ca2d84495 100644 --- a/backend/src/controllers/study-plan.js +++ b/backend/src/controllers/study-plan.js @@ -27,9 +27,9 @@ exports.getStudyPlan = async (req, res) => { try { const studyPlan = await getStudyPlan(opts); - res.json(studyPlan); + res.json(studyPlan); } catch (error) { - if (error instanceof NotExistError) { + if (error instanceof NotExistError) { handleRequestWithResourceItemNotFound(res, error); } else { handleRequestWithInternalServerError(res, error); @@ -46,6 +46,7 @@ exports.createStudyPlanData = async(req, res) => { startYear, semester, status, + notes, studyPlanCourses } = req.body; @@ -56,6 +57,7 @@ exports.createStudyPlanData = async(req, res) => { startYear, semester, status, + notes }; let creditsTotal = 0; @@ -86,7 +88,7 @@ exports.createStudyPlanData = async(req, res) => { exports.updateStudyPlan = async (req, res) => { try { - const { + const { studyPlan, changeset } = req.body; diff --git a/backend/src/middleware/study-plan.js b/backend/src/middleware/study-plan.js index 80290f070143d03237d691b6eadd45464c4a0437..0c0fd71d0025839229cd99b6f413018466aae2c9 100644 --- a/backend/src/middleware/study-plan.js +++ b/backend/src/middleware/study-plan.js @@ -1,21 +1,21 @@ 'use strict'; -const { - handleRequestWithInvalidRequestBody, - checkRequiredParameter, +const { + handleRequestWithInvalidRequestBody, + checkRequiredParameter, handleRequestWithInternalServerError, handleRequestWithResourceItemNotFound } = require("../util/common"); const { getStudyPlan } = require("../util/db/study-plan"); const { - RequiredParameterUndefinedError, - NotExistError + RequiredParameterUndefinedError, + NotExistError } = require("../util/error"); const getStudyPlanMiddleware = async(req, res, next) => { const { studyPlanId, - studentId, - semester, + studentId, + semester, startYear, shouldIncludeCourses = "true", } = req.query; @@ -51,7 +51,7 @@ const getStudyPlanMiddleware = async(req, res, next) => { if (shouldIncludeCourses.toLowerCase() === "true") { opts.include = "studyPlanCourses" } - + req.body.opts = opts; next(); @@ -67,12 +67,14 @@ const updateStudyPlanMiddleware = async (req, res, next) => { try { const { status, + notes, studyPlanCourses } = req.body; checkRequiredParameter({ oneOf: { status, + notes, studyPlanCourses } }); @@ -90,6 +92,10 @@ const updateStudyPlanMiddleware = async (req, res, next) => { changeset.status = status; } + if (notes) { + changeset.notes = notes; + } + if (studyPlanCourses) { changeset.studyPlanCourses = studyPlanCourses; } diff --git a/backend/src/test/studyplan.controller.test.js b/backend/src/test/studyplan.controller.test.js index 2a45de725aceb2820a666d5a26314a6fa5f6566d..9d0851097de6cb09ad1912ff9bbf6813f0a5e007 100644 --- a/backend/src/test/studyplan.controller.test.js +++ b/backend/src/test/studyplan.controller.test.js @@ -33,6 +33,7 @@ const COURSE_NAME = "Rekayasa Perangkat Lunak"; const COURSE_CREDIT = 3; const INVALID_ID = '57e19842-d712-45fd-9068-04cde6bf41f'; const SCORE = 'T'; +const NOTES = 'LGTM'; const SUCCESS_CODE = 200; const REQUEST_ERROR = 400; @@ -95,6 +96,7 @@ describe('Study Plan Test', () => { studentId: student.id, startYear: START_YEAR, semester: SemesterEnum.EVEN, + notes: NOTES }); }); @@ -109,6 +111,7 @@ describe('Study Plan Test', () => { startYear: START_YEAR, semester: SEMESTER, status: STUDY_PLAN_STATUS, + notes: NOTES, studyPlanCourses : [ { courseClassId: availableCourseClass.id, @@ -129,6 +132,7 @@ describe('Study Plan Test', () => { res.body.should.have.property('semester').deep.equal(requestBody.semester); res.body.should.have.property('status').deep.equal(requestBody.status); res.body.should.have.property('startYear').deep.equal(requestBody.startYear); + res.body.should.have.property('notes').deep.equal(NOTES); res.body.should.have.property('studyPlanCourses').to.not.equal(null); res.body.should.have.property('updatedAt').to.not.equal(null); res.body.should.have.property('createdAt').to.not.equal(null); @@ -235,6 +239,7 @@ describe('Study Plan Test', () => { res.body.should.have.property('creditsTotal').deep.equal(0); res.body.should.have.property('semester').deep.equal(SemesterEnum.EVEN); res.body.should.have.property('status').deep.equal(STUDY_PLAN_STATUS); + res.body.should.have.property('notes').deep.equal(NOTES); res.body.should.have.property('updatedAt').to.not.equal(null); res.body.should.have.property('createdAt').to.not.equal(null); res.body.should.have.property('studentId').deep.equal(studyPlan.studentId); @@ -252,6 +257,7 @@ describe('Study Plan Test', () => { res.body.should.have.property('creditsTotal').deep.equal(0); res.body.should.have.property('semester').deep.equal(SemesterEnum.EVEN); res.body.should.have.property('status').deep.equal(STUDY_PLAN_STATUS); + res.body.should.have.property('notes').deep.equal(NOTES); res.body.should.have.property('updatedAt').to.not.equal(null); res.body.should.have.property('createdAt').to.not.equal(null); res.body.should.have.property('studentId').to.not.equal(null);