Skip to content

Commit 186eb66

Browse files
authored
Merge pull request #418 from tcet-opensource/414-filldbwithplaceholderdata
Filled DB with placeholder data
2 parents 5118489 + 9fb5d9e commit 186eb66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1520
-254
lines changed

.eslintrc.cjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ module.exports = {
2222
"alias": {
2323
"map": [
2424
["#app", "./app.js"],
25-
["#util", "./util.js"],
26-
["#constant", "./constant.js"],
25+
["#util", "./misc/util.js"],
26+
["#constant", "./misc/constant.js"],
2727
["#routes", "./routes"],
2828
["#models", "./models"],
2929
["#middleware", "./middleware"],
3030
["#controller", "./controller"],
3131
["#services", "./services"],
32-
["#error", "./error"]
32+
["#error", "./error"],
33+
["#misc", "./misc"],
34+
["#mockDB", "./misc/mockDB"]
3335
],
3436
"extensions": [".js"]
3537
}

_apidoc.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
* @apiBody {String} wing The wing where the infrastructure is located.
173173
* @apiBody {Number} floor The floor where the infrastructure is located.
174174
* @apiBody {Number} capacity The capacity of the infrastructure.
175+
* @apiBody {connector.Schema.Types.ObjectId} organization The organization which is associated.
175176
*
176177
* @apiSuccess {String} res Success message with the ID of the added infrastructure.
177178
*
@@ -198,6 +199,7 @@
198199
* @apiSuccess {String} infrastructure.wing Wing of Infrastructure. One of possible A,B,C.
199200
* @apiSuccess {Number} infrastructure.floor Floor of Infrastructure.
200201
* @apiSuccess {Number} infrastructure.capacity Capacity of Infrastructure.
202+
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
201203
*/
202204

203205
/**
@@ -226,6 +228,7 @@
226228
* @apiBody {String} [wing] The wing where the infrastructure is located.
227229
* @apiBody {Number} [floor] The floor where the infrastructure is located.
228230
* @apiBody {Number} [capacity] The capacity of the infrastructure.
231+
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
229232
*
230233
* @apiSuccess {String} res infrastructure updated.
231234
* @apiError (Error 500) err Error in updating database
@@ -432,6 +435,7 @@
432435
* @apiBody {Date} yearOfStarting The year of establishment of the Department.
433436
* @apiBody {connector.Schema.Types.ObjectId} accreditations The accreditation which is associated.
434437
* @apiBody {connector.Schema.Types.ObjectId} infrastructure The infrastructure which is associated.
438+
* @apiBody {connector.Schema.Types.ObjectId} organization The organization which is associated.
435439
*
436440
* @apiSuccess {String} res added Department successfully.
437441
*
@@ -450,6 +454,7 @@
450454
* @apiBody {Date} [yearOfStarting] The year of establishment of the Department.
451455
* @apiBody {connector.Schema.Types.ObjectId} [accreditations] Accreditation which is associated.
452456
* @apiBody {connector.Schema.Types.ObjectId} [infrastructure] Infrastructure which is associated.
457+
* @apiBody {connector.Schema.Types.ObjectId} organization The organization which is associated.
453458
*
454459
* @apiSuccess {Department[]} res Array of Filtered Department Doc .
455460
* @apiSuccess {String} department._id ID of document given by database.
@@ -458,6 +463,7 @@
458463
* @apiSuccess {Date} department.yearOfStarting The year of establishment of the Department.
459464
* @apiSuccess {connector.Schema.Types.ObjectId} department.accreditations associated Accreditation.
460465
* @apiSuccess {connector.Schema.Types.ObjectId} department.infrastructure associatedInfrastructure.
466+
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
461467
* @apiError (Error 500) err Error while fetching the data.
462468
*/
463469

@@ -488,6 +494,7 @@
488494
* @apiSuccess {Date} department.yearOfStarting The year of establishment of the Department.
489495
* @apiSuccess {connector.Schema.Types.ObjectId} department.accreditations associated Accreditation.
490496
* @apiSuccess {connector.Schema.Types.ObjectId} department.infrastructure associatedInfrastructure.
497+
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
491498
*
492499
* @apiSuccess {String} res updated infrastructure with id.
493500
* @apiError (Error 500) err Error while inserting in DB
@@ -655,8 +662,8 @@
655662
*
656663
* @apiQuery {Number} [no] Module number.
657664
* @apiQuery {String} [name] Name of the module.
658-
* @apiQuery {String} [outcome] Module outcome.
659665
* @apiQuery {String[]} [contents] Array of contents of the module.
666+
* @apiQuery {ObjectId} content ID of the Topics (ObjectId).
660667
* @apiQuery {Number} [hrsPerModule] Number of hours required per module.
661668
* @apiQuery {String[]} [cognitiveLevels] Array of cognitive levels
662669
* of attainment as per Bloom's Taxanomy (L1-L6).
@@ -665,7 +672,6 @@
665672
* @apiSuccess {String} module._id ID of document given by database.
666673
* @apiSuccess {String} module.no Module number.
667674
* @apiSuccess {String} module.name Name of the module.
668-
* @apiSuccess {String} module.outcome Module outcome.
669675
* @apiSuccess {String[]} module.contents Array of contents of the module.
670676
* @apiSuccess {Number} module.hrsPerModule Number of hours required per module.
671677
* @apiSuccess {String[]} module.cognitiveLevels Array of cognitive levels of
@@ -741,8 +747,8 @@
741747
*
742748
* @apiBody {Number} [no] Module number.
743749
* @apiBody {String} [name] Name of the module.
744-
* @apiBody {String} [outcome] Module outcome.
745750
* @apiBody {String[]} [contents] Array of contents of the module.
751+
* @apiBody {ObjectId} content ID of the Topics (ObjectId).
746752
* @apiBody {Number} [hrsPerModule] Number of hours required per module.
747753
* @apiBody {String[]} [cognitiveLevels] Array of cognitive levels
748754
* of attainment as per Bloom's Taxanomy (L1-L6).
@@ -772,8 +778,8 @@
772778
* @apiParam {String} moduleId The ID of the Module document to update.
773779
* @apiBody {Number} [no] Module number.
774780
* @apiBody {String} [name] Name of the module.
775-
* @apiBody {String} [outcome] Module outcome.
776781
* @apiBody {String[]} [contents] Array of contents of the module.
782+
* @apiBody {ObjectId} content ID of the Topics (ObjectId).
777783
* @apiBody {Number} [hrsPerModule] Number of hours required per module.
778784
* @apiBody {String[]} [cognitiveLevels] Array of cognitive levels
779785
* of attainment as per Bloom's Taxanomy (L1-L6).
@@ -1875,3 +1881,5 @@
18751881
* @apiError (Error 500) err Error in updating database
18761882
*
18771883
*/
1884+
1885+
// TODO ADD COURSE ENDPOINT APIDOCS

app.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import groupRouter from "#routes/group";
3030
import performarouter from "#routes/performance";
3131
import notificationRouter from "#routes/notification";
3232
import topicRouter from "#routes/topic";
33+
import courseRouter from "#routes/course";
3334

3435
const app = express();
3536
const currDirName = dirname(fileURLToPath(import.meta.url));
@@ -40,10 +41,12 @@ app.use(cors());
4041
app.use(express.json());
4142
app.use(express.urlencoded({ extended: false }));
4243
app.use(cookieParser());
43-
app.use(morgan(
44-
":remote-addr - :remote-user \":method :url HTTP/:http-version\" :status \":referrer\" \":user-agent\"",
45-
{ stream: logger.stream },
46-
));
44+
app.use(
45+
morgan(
46+
":remote-addr - :remote-user \":method :url HTTP/:http-version\" :status \":referrer\" \":user-agent\"",
47+
{ stream: logger.stream },
48+
),
49+
);
4750

4851
app.use(express.static(path.join(currDirName, "public")));
4952

@@ -71,6 +74,7 @@ app.use("/semester", semesterRouter);
7174
app.use("/faculty", facultyRouter);
7275
app.use("/performance", performarouter);
7376
app.use("/notification", notificationRouter);
74-
app.use("/topic",topicRouter);
77+
app.use("/topic", topicRouter);
78+
app.use("/course", courseRouter);
7579

7680
export default app;

controller/course.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import {
2+
createCourse,
3+
courseList,
4+
deleteCourseById,
5+
updateCourseById,
6+
} from "#services/course";
7+
import { logger } from "#util";
8+
9+
async function addCourse(req, res) {
10+
const {
11+
name,
12+
code,
13+
theoryHours,
14+
department,
15+
tutorialHours,
16+
practicalHours,
17+
ISAMarks,
18+
ESEMarks,
19+
tutorialMarks,
20+
practicalMarks,
21+
semester,
22+
subType,
23+
prerequisites,
24+
objective,
25+
outcomes,
26+
modules,
27+
practicals,
28+
tutorials,
29+
assignments,
30+
reccTextbooks,
31+
refBooks,
32+
} = req.body;
33+
try {
34+
const newCourse = await createCourse(
35+
name,
36+
code,
37+
theoryHours,
38+
department,
39+
tutorialHours,
40+
practicalHours,
41+
ISAMarks,
42+
ESEMarks,
43+
tutorialMarks,
44+
practicalMarks,
45+
semester,
46+
subType,
47+
prerequisites,
48+
objective,
49+
outcomes,
50+
modules,
51+
practicals,
52+
tutorials,
53+
assignments,
54+
reccTextbooks,
55+
refBooks,
56+
);
57+
res.json({ res: `added course ${newCourse.ERPID}` });
58+
} catch (error) {
59+
logger.error("Error while inserting", error);
60+
res.status(500);
61+
res.json({ err: "Error while inserting in DB" });
62+
}
63+
}
64+
65+
async function getCourse(req, res) {
66+
try {
67+
const filter = req.body;
68+
const { limit, page } = req.query;
69+
const courselist = await courseList(filter, limit, page);
70+
res.json({ res: courselist });
71+
} catch (error) {
72+
logger.error("Error while fetching", error);
73+
res.status(500);
74+
res.json({ err: "Error while fetching the data" });
75+
}
76+
}
77+
78+
async function deleteCourse(req, res) {
79+
const { courseId } = req.params;
80+
try {
81+
await deleteCourseById(courseId);
82+
res.json({ res: "Course deleted successfully" });
83+
} catch (error) {
84+
logger.error("Error while deleting", error);
85+
res.status(500);
86+
res.json({ err: "Error while deleting from DB" });
87+
}
88+
}
89+
90+
async function updateCourse(req, res) {
91+
const { id, ...data } = req.body;
92+
try {
93+
await updateCourseById(id, data);
94+
res.json({ res: `updated course with id ${id}` });
95+
} catch (error) {
96+
logger.error("Error while updating", error);
97+
res.status(500);
98+
res.json({ err: "Error while updating in DB" });
99+
}
100+
}
101+
102+
export default {
103+
addCourse,
104+
getCourse,
105+
deleteCourse,
106+
updateCourse,
107+
};

controller/department.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ import {
88
import { logger } from "#util";
99

1010
async function addDepartment(req, res) {
11-
const { name, acronym, yearOfStarting, accreditations, infrastructures } =
12-
req.body;
11+
const {
12+
name,
13+
acronym,
14+
yearOfStarting,
15+
accreditations,
16+
infrastructures,
17+
organization,
18+
} = req.body;
1319
try {
1420
const department = await createnewdepartment(
1521
name,
1622
acronym,
1723
yearOfStarting,
1824
accreditations,
1925
infrastructures,
26+
organization,
2027
);
2128
res.json({
2229
res: `added Department successfully ${department.name}`,

controller/infrastructure.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import {
77
import { logger } from "#util";
88

99
async function addInfrastructure(req, res) {
10-
const { name, type, wing, floor, capacity } = req.body;
10+
const { name, type, wing, floor, capacity, organization } = req.body;
1111
try {
1212
const newInfrastructure = await createInfrastructure(
1313
name,
1414
type,
1515
wing,
1616
floor,
1717
capacity,
18+
organization,
1819
);
1920
res.json({
2021
res: `added infrastructure ${newInfrastructure.id}`,

controller/module.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ async function showModule(req, res) {
2020
}
2121

2222
async function addModule(req, res) {
23-
const { no, name, outcome, contents, hrsPerModule, cognitiveLevels } =
24-
req.body;
23+
const { no, name, contents, hrsPerModule, cognitiveLevels } = req.body;
2524
try {
2625
const newModule = await addNewModule(
2726
no,
2827
name,
29-
outcome,
3028
contents,
3129
hrsPerModule,
3230
cognitiveLevels,

jsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
"baseUrl": "./",
55
"paths": {
66
"#app": ["./app.js"],
7-
"#util": ["./util.js"],
8-
"#constant": ["./constant.js"],
7+
"#util": ["./misc/util.js"],
8+
"#constant": ["./misc/constant.js"],
99
"#routes/*": ["./routes/*.js"],
1010
"#models/*": ["./models/*.js"],
1111
"#middleware/*": ["./middleware/*.js"],
1212
"#controller/*": ["./controller/*.js"],
1313
"#services/*": ["./services/*.js"],
14-
"#error/*": ["./error/*.js"]
14+
"#error/*": ["./error/*.js"],
15+
"#misc/*": ["./misc/*.js"],
16+
"#mockDB/*": ["./misc/mockDB/*.js"]
1517
}
1618
}
1719
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)