Skip to content

Commit 96f9e47

Browse files
committed
created logic for erpId of student and faculty
1 parent 16aa476 commit 96f9e47

File tree

6 files changed

+158
-148
lines changed

6 files changed

+158
-148
lines changed

controller/faculty.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { logger } from "#util";
88

99
async function addFaculty(req, res) {
1010
const {
11-
ERPID,
1211
dateOfJoining,
1312
dateOfLeaving,
1413
profileLink,
@@ -25,6 +24,15 @@ async function addFaculty(req, res) {
2524
additionalResponsibilities,
2625
} = req.body;
2726
try {
27+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
28+
const randomIndex = Math.floor(Math.random() * alphabet.length);
29+
const randomLetter = alphabet[randomIndex];
30+
let randomNumber = Math.floor(Math.random() * 1000).toString();
31+
if (randomNumber.length === 2) {
32+
randomNumber = `0${ randomNumber}`;
33+
}
34+
const ERPID = `F${ randomLetter }${randomNumber}`;
35+
2836
const newFaculty = await createFaculty(
2937
ERPID,
3038
dateOfJoining,

controller/student.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ import { logger } from "#util";
88
import { isEntityIdValid } from "#middleware/entityIdValidation";
99
import Department from "#models/department";
1010
import Course from "#models/course";
11+
import { departmentAbbrev, departmentNames } from "#constant";
1112

1213
async function addStudent(req, res) {
13-
const { ERPID, name, joiningYear, branch, division, rollNo, coursesOpted } =
14+
const { name, joiningYear, branch, division, rollNo, coursesOpted } =
1415
req.body;
1516
try {
1617
const isBranchValid = await isEntityIdValid(branch, Department);
1718
const isCourseValid = await isEntityIdValid(coursesOpted, Course);
1819
if (isBranchValid && isCourseValid) {
20+
const departmentData = await Department.read({ _id: branch });
21+
const departmentName = departmentData.data[0].name;
22+
const abbrev = departmentAbbrev[departmentNames.indexOf(departmentName)];
23+
const year = joiningYear.toString().slice(-2);
24+
let randomNumber = Math.floor(Math.random() * 1000).toString();
25+
if (randomNumber.length === 2) {
26+
randomNumber = `0${ randomNumber}`;
27+
}
28+
const ERPID = `S${ abbrev }${year }${randomNumber}`;
29+
1930
const newStudent = await createStudent(
2031
ERPID,
2132
name,

misc/constant.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,38 @@ export const logLevel = {
33
dev: "debug",
44
prod: "info",
55
};
6+
7+
export const departmentNames = [
8+
"Mechanical Engineering",
9+
"Civil Engineering",
10+
"Computer Engineering",
11+
"Information Technology",
12+
"Electronics and Telecommunication Engineering",
13+
"Electronics and Computer Science",
14+
"Artificial Intelligence and Data Science",
15+
"Internet of Things",
16+
"Artificial Intelligence and Machine Learning",
17+
"Computer Science and Engineering (Cyber Security)",
18+
"Mechanical and Mechatronics Engineering (Additive Manufacturing)",
19+
"Artificial Intelligence and Data Science",
20+
"Software Development",
21+
"Animation & Graphic Designing",
22+
"Data Analytics",
23+
];
24+
export const departmentAbbrev = [
25+
"ME",
26+
"CE",
27+
"CS",
28+
"IT",
29+
"ETE",
30+
"ECS",
31+
"AIDS",
32+
"IOT",
33+
"AIML",
34+
"CSS",
35+
"MEMM",
36+
"AIDS",
37+
"SD",
38+
"AGD",
39+
"DA",
40+
];

misc/mockDB/deptMock.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,5 @@
11
import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies
2-
3-
/* eslint-disable no-underscore-dangle */
4-
const departmentNames = [
5-
"Mechanical Engineering",
6-
"Civil Engineering",
7-
"Computer Engineering",
8-
"Information Technology",
9-
"Electronics and Telecommunication Engineering",
10-
"Electronics and Computer Science",
11-
"Artificial Intelligence and Data Science",
12-
"Internet of Things",
13-
"Artificial Intelligence and Machine Learning",
14-
"Computer Science and Engineering (Cyber Security)",
15-
"Mechanical and Mechatronics Engineering (Additive Manufacturing)",
16-
"Artificial Intelligence and Data Science",
17-
"Software Development",
18-
"Animation & Graphic Designing",
19-
"Data Analytics",
20-
];
21-
const departmentAbbrev = [
22-
"ME",
23-
"CE",
24-
"CS",
25-
"IT",
26-
"ETE",
27-
"ECS",
28-
"AIDS",
29-
"IOT",
30-
"AIML",
31-
"CSS",
32-
"MEMM",
33-
"AIDS",
34-
"SD",
35-
"AGD",
36-
"DA",
37-
];
2+
import { departmentNames, departmentAbbrev } from "#constant";
383

394
const createRandomDepartment = (
405
i,

test/routes/faculty.test.js

Lines changed: 100 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3,126 +3,120 @@ import connector from "#models/databaseUtil";
33
import facultyModel from "#models/faculty";
44

55
jest.mock("#util");
6-
const {agent} = global;
6+
const { agent } = global;
77

88
// test case for deletion
99
function cleanUp(callback) {
10-
facultyModel.remove(
11-
{
12-
ERPID: "test123",
13-
dateOfJoining: "2023-06-18T14:11:30Z",
14-
dateOfLeaving: "2023-07-18T14:11:30Z",
15-
profileLink: "Sanika",
16-
qualifications: ["Ph.D.", "M.Sc."],
17-
totalExperience: 5,
18-
achievements: ["Award 1", "Award 2"],
19-
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
20-
papersPublishedPG: 10,
21-
papersPublishedUG: 5,
22-
department: ["5f7b75a5c69e2d4f0c285e52"],
23-
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
24-
designation: "Assistant Professor",
25-
natureOfAssociation: "Regular",
26-
additionalResponsibilities: "Teaching and Research",
27-
},
28-
)
29-
.then(() => {
30-
connector.disconnect((DBerr) => {
31-
if (DBerr) console.log("Database disconnect error: ", DBerr);
32-
callback();
33-
});
34-
});
10+
facultyModel
11+
.remove({
12+
ERPID: "test123",
13+
dateOfJoining: "2023-06-18T14:11:30Z",
14+
dateOfLeaving: "2023-07-18T14:11:30Z",
15+
profileLink: "Sanika",
16+
qualifications: ["Ph.D.", "M.Sc."],
17+
totalExperience: 5,
18+
achievements: ["Award 1", "Award 2"],
19+
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
20+
papersPublishedPG: 10,
21+
papersPublishedUG: 5,
22+
department: ["5f7b75a5c69e2d4f0c285e52"],
23+
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
24+
designation: "Assistant Professor",
25+
natureOfAssociation: "Regular",
26+
additionalResponsibilities: "Teaching and Research",
27+
})
28+
.then(() => {
29+
connector.disconnect((DBerr) => {
30+
if (DBerr) console.log("Database disconnect error: ", DBerr);
31+
callback();
32+
});
33+
});
3534
}
3635

3736
afterAll((done) => {
38-
cleanUp(done);
37+
cleanUp(done);
3938
});
4039

4140
describe("Faculty API", () => {
42-
it("should create faculty", async () => {
43-
const response = await agent.post("/faculty/create").send({
44-
ERPID: "test123",
45-
dateOfJoining: "2023-06-18T14:11:30Z",
46-
dateOfLeaving: "2023-07-18T14:11:30Z",
47-
profileLink: "xyz",
48-
qualifications: ["Ph.D.", "M.Sc."],
49-
totalExperience: 5,
50-
achievements: ["Award 1", "Award 2"],
51-
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
52-
papersPublishedPG: 10,
53-
papersPublishedUG: 5,
54-
department: ["5f7b75a5c69e2d4f0c285e52"],
55-
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
56-
designation: "Assistant Professor",
57-
natureOfAssociation: "Regular",
58-
additionalResponsibilities: "Teaching and Research",
59-
});
60-
61-
expect(response.status).toBe(200);
62-
expect(response.body.res).toMatch(/added faculty/);
41+
it("should create faculty", async () => {
42+
const response = await agent.post("/faculty/create").send({
43+
dateOfJoining: "2023-06-18T14:11:30Z",
44+
dateOfLeaving: "2023-07-18T14:11:30Z",
45+
profileLink: "xyz",
46+
qualifications: ["Ph.D.", "M.Sc."],
47+
totalExperience: 5,
48+
achievements: ["Award 1", "Award 2"],
49+
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
50+
papersPublishedPG: 10,
51+
papersPublishedUG: 5,
52+
department: ["5f7b75a5c69e2d4f0c285e52"],
53+
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
54+
designation: "Assistant Professor",
55+
natureOfAssociation: "Regular",
56+
additionalResponsibilities: "Teaching and Research",
6357
});
6458

65-
describe("after adding faculty", () => {
66-
let id;
67-
beforeEach(async () => {
68-
id = await agent.post("/faculty/create").send(
69-
{
70-
ERPID: "test123",
71-
dateOfJoining: "2023-06-18T14:11:30Z",
72-
dateOfLeaving: "2023-07-18T14:11:30Z",
73-
profileLink: "xyz",
74-
qualifications: ["Ph.D.", "M.Sc."],
75-
totalExperience: 5,
76-
achievements: ["Award 1", "Award 2"],
77-
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
78-
papersPublishedPG: 10,
79-
papersPublishedUG: 5,
80-
department: ["5f7b75a5c69e2d4f0c285e52"],
81-
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
82-
designation: "Assistant Professor",
83-
natureOfAssociation: "Regular",
84-
additionalResponsibilities: "Teaching and Research",
85-
});
59+
expect(response.status).toBe(200);
60+
expect(response.body.res).toMatch(/added faculty/);
61+
});
8662

87-
id = JSON.parse(id.res.text).id;
88-
});
63+
describe("after adding faculty", () => {
64+
let id;
65+
beforeEach(async () => {
66+
id = await agent.post("/faculty/create").send({
67+
dateOfJoining: "2023-06-18T14:11:30Z",
68+
dateOfLeaving: "2023-07-18T14:11:30Z",
69+
profileLink: "xyz",
70+
qualifications: ["Ph.D.", "M.Sc."],
71+
totalExperience: 5,
72+
achievements: ["Award 1", "Award 2"],
73+
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
74+
papersPublishedPG: 10,
75+
papersPublishedUG: 5,
76+
department: ["5f7b75a5c69e2d4f0c285e52"],
77+
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
78+
designation: "Assistant Professor",
79+
natureOfAssociation: "Regular",
80+
additionalResponsibilities: "Teaching and Research",
81+
});
8982

90-
afterEach(async () => {
91-
await facultyModel.remove(
92-
{
93-
ERPID: "test123",
94-
dateOfJoining: "2023-06-18T14:11:30Z",
95-
dateOfLeaving: "2023-07-18T14:11:30Z",
96-
profileLink: "xyz",
97-
qualifications: ["Ph.D.", "M.Sc."],
98-
totalExperience: 5,
99-
achievements: ["Award 1", "Award 2"],
100-
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
101-
papersPublishedPG: 10,
102-
papersPublishedUG: 5,
103-
department: ["5f7b75a5c69e2d4f0c285e52"],
104-
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
105-
designation: "Assistant Professor",
106-
natureOfAssociation: "Regular",
107-
additionalResponsibilities: "Teaching and Research",
108-
});
109-
});
83+
id = JSON.parse(id.res.text).id;
84+
});
11085

111-
it("should read faculty", async () => {
112-
const response = await agent
113-
.get("/faculty/list")
114-
.send({ERPID: "test123"});
86+
afterEach(async () => {
87+
await facultyModel.remove({
88+
dateOfJoining: "2023-06-18T14:11:30Z",
89+
dateOfLeaving: "2023-07-18T14:11:30Z",
90+
profileLink: "xyz",
91+
qualifications: ["Ph.D.", "M.Sc."],
92+
totalExperience: 5,
93+
achievements: ["Award 1", "Award 2"],
94+
areaOfSpecialization: ["Specialization 1", "Specialization 2"],
95+
papersPublishedPG: 10,
96+
papersPublishedUG: 5,
97+
department: ["5f7b75a5c69e2d4f0c285e52"],
98+
preferredSubjects: ["5f7b75a5c69e2d4f0c285e53"],
99+
designation: "Assistant Professor",
100+
natureOfAssociation: "Regular",
101+
additionalResponsibilities: "Teaching and Research",
102+
});
103+
});
115104

116-
expect(response.status).toBe(200);
117-
expect(response.body.res).toBeDefined();
118-
});
105+
it("should read faculty", async () => {
106+
const response = await agent
107+
.get("/faculty/list")
108+
.send({ profileLink: "xyz" });
119109

120-
it("should update faculty", async () => {
121-
const response = await agent
122-
.post(`/faculty/update/${id}`)
123-
.send({ ERPID: "test123" }, { totalExperience: 10 });
124-
expect(response.status).toBe(200);
125-
expect(response.body.res).toMatch(/updated faculty/);
126-
});
110+
expect(response.status).toBe(200);
111+
expect(response.body.res).toBeDefined();
127112
});
128-
});
113+
114+
it("should update faculty", async () => {
115+
const response = await agent
116+
.post(`/faculty/update/${id}`)
117+
.send({ profileLink: "xyz" }, { totalExperience: 10 });
118+
expect(response.status).toBe(200);
119+
expect(response.body.res).toMatch(/updated faculty/);
120+
});
121+
});
122+
});

test/routes/student.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ afterAll((done) => {
4242
describe("Student API", () => {
4343
it("should create student", async () => {
4444
const response = await agent.post("/student/create").send({
45-
ERPID: "S1032220999",
4645
name: "Arya",
4746
joiningYear: 2020,
4847
branch: branchId,
@@ -59,7 +58,6 @@ describe("Student API", () => {
5958
let id;
6059
beforeEach(async () => {
6160
id = await agent.post("/student/create").send({
62-
ERPID: "S1032220999",
6361
name: "Arya",
6462
joiningYear: 2020,
6563
branch: branchId,
@@ -72,7 +70,6 @@ describe("Student API", () => {
7270

7371
afterEach(async () => {
7472
await studentModel.remove({
75-
ERPID: "S1032220999",
7673
name: "Arya",
7774
joiningYear: 2020,
7875
branch: branchId,
@@ -91,7 +88,7 @@ describe("Student API", () => {
9188
it("should update student", async () => {
9289
const response = await agent
9390
.post(`/student/update/${id}`)
94-
.send({ ERPID: "S1032220999" }, { joiningYear: 2021 });
91+
.send({ name: "Arya" }, { joiningYear: 2021 });
9592

9693
expect(response.status).toBe(200);
9794
expect(response.body.res).toMatch(`updated Student with id ${id}`);

0 commit comments

Comments
 (0)