Skip to content

Commit 7537299

Browse files
committed
added mock data for accred, org, infra, department, topics, modules, major fixes
1 parent 5af7523 commit 7537299

34 files changed

+882
-222
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

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.
File renamed without changes.

misc/initDB.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies
2+
import Infrastructure from "#models/infrastructure";
3+
import Accreditation from "#models/accreditation";
4+
import Organization from "#models/organization";
5+
import Department from "#models/department";
6+
import Topics from "#models/topic";
7+
import Module from "#models/module";
8+
import generateOrganizations from "#mockDB/orgMock";
9+
import ACCREDS from "#mockDB/accredMock";
10+
import TOPICS from "#mockDB/topicMock";
11+
import generateDepartments from "#mockDB/deptMock";
12+
import generateModules from "#mockDB/moduleMock";
13+
import generateInfrastructures from "#mockDB/infraMock";
14+
/* eslint-disable no-underscore-dangle */
15+
const createdAccreds = await Accreditation.createMultiple(ACCREDS);
16+
17+
const parentOrg = await Organization.create({
18+
startDate: faker.date.past({ years: 10 }),
19+
name: "Thakur Education",
20+
accreditations: [
21+
createdAccreds[faker.number.int({ min: 0, max: createdAccreds.length - 1 })]
22+
._id,
23+
createdAccreds[faker.number.int({ min: 0, max: createdAccreds.length - 1 })]
24+
._id,
25+
],
26+
});
27+
28+
const ORGS = generateOrganizations(parentOrg._id, createdAccreds);
29+
30+
const createdOrgs = await Organization.createMultiple(ORGS);
31+
32+
const tcetObject = createdOrgs.filter(
33+
(obj) => obj.name === "Thakur College of Engineering & Technology",
34+
)[0];
35+
36+
const INFRA = generateInfrastructures(tcetObject._id);
37+
38+
const createdInfras = await Infrastructure.createMultiple(INFRA);
39+
40+
const filteredInfrastructures = createdInfras.filter((infrastructure) => {
41+
const allowedTypes = ["LAB", "CLASSROOM", "COMPUTER LAB"];
42+
return allowedTypes.includes(infrastructure.type);
43+
});
44+
45+
const DEPTS = generateDepartments(
46+
tcetObject._id,
47+
createdAccreds.map((createdAccred) => createdAccred._id),
48+
filteredInfrastructures.map((createdInfra) => createdInfra._id),
49+
);
50+
51+
const createdDepts = await Department.createMultiple(DEPTS); // eslint-disable-line no-unused-vars
52+
53+
const createdTopics = await Topics.createMultiple(TOPICS);
54+
55+
const MODULES = await generateModules(
56+
createdTopics.map((createdTopic) => createdTopic._id),
57+
);
58+
59+
const createdModules = await Module.createMultiple(MODULES); // eslint-disable-line no-unused-vars
60+
61+
process.exit(0);

0 commit comments

Comments
 (0)