Skip to content

Commit ac21383

Browse files
Merge branch 'development' into 258-endpoints-from-pracs
2 parents 65c0d3b + 93be61a commit ac21383

File tree

13 files changed

+527
-8
lines changed

13 files changed

+527
-8
lines changed

_apidoc.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,117 @@
309309
* @apiSuccess {Date} accreditation.dateofAccreditation Date on which accreditation was issued.
310310
* @apiSuccess {Date} accreditation.dateofExpiry Date till which accreditation is valid.
311311
*/
312+
313+
// ------------------------------------------------------------------------------------------
314+
// Coursework.
315+
// ------------------------------------------------------------------------------------------
316+
317+
/**
318+
* @api {post} /coursework/add Add Coursework
319+
* @apiName AddCoursework
320+
* @apiGroup Coursework
321+
* @apiDescription Add a new coursework entry.
322+
*
323+
* @apiBody {ObjectId} student ID of the student (ObjectId).
324+
* @apiBody {String} Coursework type that is either onCampus or offCampus.
325+
* @apiBody {ObjectId} course ID of the Course in Coursework (ObjectId).
326+
* @apiBody {ObjectId} task ID of the task in Coursework (ObjectId).
327+
* @apiBody {String} objectID either its practicals or tutorial or assignment .
328+
* @apiBody {ObjectId} activity Id of the activity in Coursework.
329+
* @apiBody {Number} Marks in the Coursework.
330+
*
331+
* @apiSuccess {String} res Response message.
332+
* @apiError (Error 500) DatabaseError Err message if there is an error inserting into the database.
333+
*
334+
* @apiSuccessExample Success-Response:
335+
* HTTP/1.1 200 OK
336+
* {
337+
* "res": "Added coursework"
338+
* }
339+
*
340+
* @apiErrorExample Error-Response:
341+
* HTTP/1.1 500 Internal Server Error
342+
* {
343+
* "err": "Error while inserting in DB"
344+
* }
345+
*/
346+
347+
/**
348+
* @api {delete} /coursework/delete/:courseworkId Delete Coursework
349+
* @apiName DeleteCoursework
350+
* @apiGroup Coursework
351+
*
352+
* @apiParam {String} courseworkId The ID of the Coursework document to delete.
353+
*
354+
* @apiSuccess {String} res Success message indicating the deletion.
355+
*
356+
* @apiError (Error 500) DatabaseError Error message if there was an error during the deletion.
357+
*/
358+
359+
/**
360+
* @api {post} /coursework/update Update Coursework
361+
* @apiName UpdateCoursework
362+
* @apiGroup Coursework
363+
* @apiDescription Update existing coursework data.
364+
*
365+
* @apiBody {String} id ID of the Coursework to be updated.
366+
* @apiBody {ObjectId} student ID of the student (ObjectId).
367+
* @apiBody {String} Coursework type that is either onCampus or offCampus.
368+
* @apiBody {ObjectId} course ID of the Course in Coursework (ObjectId).
369+
* @apiBody {ObjectId} task ID of the task in Coursework (ObjectId).
370+
* @apiBody {String} objectID either its practicals or tutorial or assignment .
371+
* @apiBody {ObjectId} activity Id of the activity in Coursework.
372+
* @apiBody {Number} Marks in the Coursework.
373+
*
374+
* @apiSuccess {String} res Coursework updated.
375+
* @apiError (Error 500) DatabaseError Error in updating the database.
376+
*/
377+
378+
/**
379+
* @api {get} /coursework/list Get Coursework List
380+
* @apiName GetCourseworkList
381+
* @apiGroup Coursework
382+
*
383+
* @apiQuery {ObjectId} student ID of the student (ObjectId).
384+
* @apiQuery {String} Coursework type that is either onCampus or offCampus.
385+
* @apiQuery {ObjectId} course ID of the Course in Coursework (ObjectId).
386+
* @apiQuery {ObjectId} task ID of the task in Coursework (ObjectId).
387+
* @apiQuery {String} objectID either its practicals or tutorial or assignment .
388+
* @apiQuery {ObjectId} activity Id of the activity in Coursework.
389+
* @apiQuery {Number} Marks in the Coursework.
390+
*
391+
* @apiSuccess {Coursework[]} res Array of filtered coursework documents.
392+
* @apiSuccess {String} coursework._id ID of the coursework document given by the database.
393+
* @apiSuccess {ObjectId} coursework.student ID of the student (ObjectId).
394+
* @apiSuccess {String} coursework.type Coursework type that is either onCampus or offCampus.
395+
* @apiSuccess {ObjectId} coursework.course ID of the Course in Coursework (ObjectId).
396+
* @apiSuccess {ObjectId} coursework.task ID of the task in Coursework (ObjectId).
397+
* @apiSuccess {String} coursework.objectID objectID either Practicals or Tutorial or Assignment .
398+
* @apiSuccess {ObjectId} coursework.activity Id of the activity in Coursework.
399+
* @apiSuccess {Number} coursework.marks Marks in the Coursework.
400+
*/
401+
=======
402+
// Module.
403+
// ------------------------------------------------------------------------------------------
404+
405+
/**
406+
* @api {get} module/list Get Module List
407+
* @apiName GetModule
408+
* @apiGroup Module
409+
*
410+
* @apiQuery {Number} [no] Module number.
411+
* @apiQuery {String} [name] Name of the module.
412+
* @apiQuery {String} [outcome] Module outcome.
413+
* @apiQuery {String[]} [contents] Array of contents of the module.
414+
* @apiQuery {Number} [hrsPerModule] Number of hours required per module.
415+
* @apiQuery {String[]} [cognitiveLevels] Array of cognitive levels of attainment as per Bloom's Taxanomy (L1-L6).
416+
*
417+
* @apiSuccess {module[]} res Array of Filtered module Doc.
418+
* @apiSuccess {String} module._id ID of document given by database.
419+
* @apiSuccess {String} module.no Module number.
420+
* @apiSuccess {String} module.name Name of the module.
421+
* @apiSuccess {String} module.outcome Module outcome.
422+
* @apiSuccess {String[]} module.contents Array of contents of the module.
423+
* @apiSuccess {Number} module.hrsPerModule Number of hours required per module.
424+
* @apiSuccess {String[]} module.cognitiveLevels Array of cognitive levels of attainment as per Bloom's Taxanomy (L1-L6).
425+
*/

app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import authRouter from "#routes/auth";
1111
import accreditationRouter from "#routes/accreditation";
1212
import infrastructureRouter from "#routes/infrastructure";
1313
import practicalRouter from "#routes/practical";
14+
import courseworkRouter from "#routes/coursework";
15+
import moduleRouter from "#routes/module";
1416
import { identifyUser } from "#middleware/identifyUser";
1517

1618

@@ -36,4 +38,7 @@ app.use("/auth", authRouter);
3638
app.use("/accreditation", accreditationRouter);
3739
app.use("/infrastructure", infrastructureRouter);
3840
app.use("/practical", practicalRouter);
41+
app.use("/coursework", courseworkRouter);
42+
app.use("/module", moduleRouter);
43+
3944
export default app;

controller/coursework.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Import Coursework-related services and utilities
2+
import {
3+
createCoursework,
4+
deleteCourseworkById,
5+
listCoursework,
6+
updateCourseworkById,
7+
} from "#services/coursework";
8+
9+
import { logger } from "#util"; // Import the logger utility
10+
11+
// Controller function to add a new Coursework entity
12+
async function addCoursework(req, res) {
13+
const {
14+
student, type, course, task, objectID, activity, marks,
15+
} = req.body;
16+
try {
17+
const newCoursework = await createCoursework({
18+
student, type, course, task, objectID, activity, marks,
19+
});
20+
res.json({ res: `Added Coursework with ID ${newCoursework.id}` });
21+
} catch (error) {
22+
logger.error("Error while inserting Coursework", error);
23+
res.status(500);
24+
res.json({ err: "Error while inserting Coursework in DB" });
25+
}
26+
}
27+
28+
// Controller function to update a Coursework entity
29+
async function updateCoursework(req, res) {
30+
const {
31+
id, ...data
32+
} = req.body;
33+
try {
34+
await updateCourseworkById(id, data);
35+
res.json({ res: "/Updated Coursework/" });
36+
} catch (error) {
37+
logger.error("Error while updating Coursework", error);
38+
res.status(500);
39+
res.json({ err: "Error while updating Coursework in DB" });
40+
}
41+
}
42+
43+
// Controller function to get a list of Coursework entities
44+
async function getCoursework(req, res) {
45+
const filter = req.query;
46+
const courseworkList = await listCoursework(filter);
47+
res.json({ res: courseworkList });
48+
}
49+
50+
// Controller function to delete a Coursework entity
51+
async function deleteCoursework(req, res) {
52+
const { courseworkId } = req.params;
53+
try {
54+
await deleteCourseworkById(courseworkId);
55+
res.json({ res: `Deleted Coursework with ID ${courseworkId}` });
56+
} catch (error) {
57+
logger.error("Error while deleting Coursework", error);
58+
res.status(500).json({ error: "Error while deleting Coursework from DB" });
59+
}
60+
}
61+
62+
export default {
63+
addCoursework,
64+
deleteCoursework,
65+
getCoursework,
66+
updateCoursework,
67+
};

controller/module.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { getModule } from "#services/module";
2+
import { logger } from "#util";
3+
4+
async function showModule(req, res) {
5+
try {
6+
const modules = await getModule(req.query);
7+
return res.json({ res: modules });
8+
} catch (error) {
9+
logger.error("Error while fetching", error);
10+
res.status(500);
11+
return res.json({ err: "Error while fetching the data" });
12+
}
13+
}
14+
15+
export default {
16+
showModule,
17+
}

models/activityBlueprint.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const activityBluePrintSchema = {
66
type: String,
77
required: true,
88
validate: {
9-
validator: (value) => /^20\d{2}$/.test(value), //changed the valid year format starting from "20" !!
9+
validator: (value) => /^20\d{2}$/.test(value), // changed the valid year format starting from "20" !!
1010
message: (props) => `${props.value} is not a valid year format starting with "2"!`,
1111
},
1212
},
@@ -26,12 +26,12 @@ async function remove(filter) {
2626
async function create(activityBlueprintData) {
2727
const {
2828
number, academicYear, type, startDate, endDate,
29-
} = activityBlueprintDataData;
29+
} = activityBlueprintData;
3030
const activityblueprint = new ActivityBlueprint({
3131
number,
32-
academicYear,
33-
type,
34-
startDate,
32+
academicYear,
33+
type,
34+
startDate,
3535
endDate,
3636
});
3737
const activityblueprintDoc = await activityblueprint.save();
@@ -48,6 +48,6 @@ async function update(filter, updateObject, options = { multi: true }) {
4848
return deleteResult.acknowledged;
4949
}
5050

51-
export default{
51+
export default {
5252
create, read, update, remove,
53-
}
53+
};

models/coursework.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,43 @@ const courseworkSchema = {
1010
marks: { type: Number, required: true },
1111
};
1212

13-
// eslint-disable-next-line no-unused-vars
1413
const Coursework = connector.model("Coursework", courseworkSchema);
14+
15+
async function create(courseworkData) {
16+
const {
17+
student, type, course, task, objectID, activity, marks,
18+
} = courseworkData;
19+
const coursework = new Coursework({
20+
student,
21+
type,
22+
course,
23+
task,
24+
objectID,
25+
activity,
26+
marks,
27+
});
28+
const courseworkDoc = await coursework.save();
29+
return courseworkDoc;
30+
}
31+
32+
async function read(filter, limit = 1) {
33+
const courseworkDoc = await Coursework.find(filter).limit(limit);
34+
return courseworkDoc;
35+
}
36+
37+
async function update(filter, updateObject, options = { multi: true }) {
38+
const updateResult = await Coursework.updateMany(filter, { $set: updateObject }, options);
39+
return updateResult.acknowledged;
40+
}
41+
42+
async function remove(filter) {
43+
const deleteResult = await Coursework.deleteMany(filter).exec();
44+
return deleteResult.acknowledged;
45+
}
46+
47+
export default {
48+
create,
49+
read,
50+
update,
51+
remove,
52+
};

models/semester.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import connector from "#models/databaseUtil";
2+
const semesterSchema = {
3+
number:{ type: Number,enum: [1,2,3,4,5,6,7,8], required:true},
4+
academicYear: {
5+
type: String,
6+
required: true,
7+
validate: {
8+
validator: (value) => /^20\d{2}$/.test(value),
9+
message: (props) => `${props.value} is not a valid year format starting with "2"!`,
10+
},
11+
},
12+
type:{ enum: ["ODD", "EVEN"], required: true },
13+
14+
startDate: { type: Date, required: true },
15+
endDate: { type: Date, required: true },
16+
};
17+
18+
// eslint-disable-next-line no-unused-vars
19+
const Semester = connector.model("Semester", semesterSchema);
20+
21+
// CURD operations
22+
async function create(semesterData) {
23+
const {
24+
number,
25+
academicYear,
26+
type,
27+
startDate,
28+
endDate,
29+
} = semesterData;
30+
const semester = new Semester({
31+
number,
32+
academicYear,
33+
type,
34+
startDate,
35+
endDate,
36+
37+
});
38+
const semesterDoc = await semester.save();
39+
return semesterDoc;
40+
}
41+
42+
async function read(filter, limit = 1) {
43+
const semesterDoc = await Semester.find(filter).limit(limit);
44+
return semesterDoc;
45+
}
46+
47+
async function update(filter, updateObject, options = { multi: true }) {
48+
const updateResult = await Semester.updateMany(filter, { $set: updateObject }, options);
49+
return updateResult.acknowledged;
50+
}
51+
52+
async function remove(filter) {
53+
const deleteResult = await Semester.deleteMany(filter);
54+
return deleteResult.acknowledged;
55+
}
56+
export default {
57+
create, remove, update, read,
58+
};
59+

routes/coursework.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import express from "express";
2+
import courseworkController from "#controller/coursework";
3+
4+
const router = express.Router();
5+
router.post("/add", courseworkController.addCoursework);
6+
router.get("/list", courseworkController.getCoursework);
7+
router.post("/update", courseworkController.updateCoursework);
8+
router.post("/delete/:courseworkId", courseworkController.deleteCoursework);
9+
10+
export default router;

routes/module.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import express from "express";
2+
import moduleController from "#controller/module";
3+
4+
const router = express.Router();
5+
6+
router.get("/list", moduleController.showModule);
7+
8+
export default router;

0 commit comments

Comments
 (0)