Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion controller/faculty.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { logger } from "#util";

async function addFaculty(req, res) {
const {
ERPID,
dateOfJoining,
dateOfLeaving,
profileLink,
Expand All @@ -56,6 +55,15 @@ async function addFaculty(req, res) {
const session = await mongoose.startSession();
session.startTransaction();
try {
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const randomIndex = Math.floor(Math.random() * alphabet.length);
const randomLetter = alphabet[randomIndex];
let randomNumber = Math.floor(Math.random() * 1000).toString();
if (randomNumber.length === 2) {
randomNumber = `0${ randomNumber}`;
}
const ERPID = `F${ randomLetter }${randomNumber}`;

const newFaculty = await createFaculty(
ERPID,
dateOfJoining,
Expand Down
12 changes: 11 additions & 1 deletion controller/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { logger } from "#util";
import { isEntityIdValid } from "#middleware/entityIdValidation";
import Department from "#models/department";
import Course from "#models/course";
import { departmentAbbrev, departmentNames } from "#constant";

async function addStudent(req, res) {
const {
ERPID,
name,
joiningYear,
branch,
Expand Down Expand Up @@ -192,6 +192,16 @@ async function addStudent(req, res) {
const isBranchValid = await isEntityIdValid(branch, Department);
const isCourseValid = await isEntityIdValid(coursesOpted, Course);
if (isBranchValid && isCourseValid) {
const departmentData = await Department.read({ _id: branch });
const departmentName = departmentData.data[0].name;
const abbrev = departmentAbbrev[departmentNames.indexOf(departmentName)];
const year = joiningYear.toString().slice(-2);
let randomNumber = Math.floor(Math.random() * 1000).toString();
if (randomNumber.length === 2) {
randomNumber = `0${ randomNumber}`;
}
const ERPID = `S${ abbrev }${year }${randomNumber}`;

const session = await mongoose.startSession();
session.startTransaction();

Expand Down
35 changes: 35 additions & 0 deletions misc/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,38 @@ export const logLevel = {
dev: "debug",
prod: "info",
};

export const departmentNames = [
"Mechanical Engineering",
"Civil Engineering",
"Computer Engineering",
"Information Technology",
"Electronics and Telecommunication Engineering",
"Electronics and Computer Science",
"Artificial Intelligence and Data Science",
"Internet of Things",
"Artificial Intelligence and Machine Learning",
"Computer Science and Engineering (Cyber Security)",
"Mechanical and Mechatronics Engineering (Additive Manufacturing)",
"Artificial Intelligence and Data Science",
"Software Development",
"Animation & Graphic Designing",
"Data Analytics",
];
export const departmentAbbrev = [
"ME",
"CE",
"CS",
"IT",
"ETE",
"ECS",
"AIDS",
"IOT",
"AIML",
"CSS",
"MEMM",
"AIDS",
"SD",
"AGD",
"DA",
];
37 changes: 1 addition & 36 deletions misc/mockDB/deptMock.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
import { faker } from "@faker-js/faker"; // eslint-disable-line import/no-extraneous-dependencies

/* eslint-disable no-underscore-dangle */
const departmentNames = [
"Mechanical Engineering",
"Civil Engineering",
"Computer Engineering",
"Information Technology",
"Electronics and Telecommunication Engineering",
"Electronics and Computer Science",
"Artificial Intelligence and Data Science",
"Internet of Things",
"Artificial Intelligence and Machine Learning",
"Computer Science and Engineering (Cyber Security)",
"Mechanical and Mechatronics Engineering (Additive Manufacturing)",
"Artificial Intelligence and Data Science",
"Software Development",
"Animation & Graphic Designing",
"Data Analytics",
];
const departmentAbbrev = [
"ME",
"CE",
"CS",
"IT",
"ETE",
"ECS",
"AIDS",
"IOT",
"AIML",
"CSS",
"MEMM",
"AIDS",
"SD",
"AGD",
"DA",
];
import { departmentNames, departmentAbbrev } from "#constant";

const createRandomDepartment = (
i,
Expand Down
3 changes: 2 additions & 1 deletion test/routes/faculty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { agent } = global;

// test case for deletion
function cleanUp(callback) {

facultyBankModel.remove({ uid: "aaaaa" });
facultyCurrentModel.remove({ uid: "aaaaa" });
facultyEducationModel.remove({ uid: "aaaaa" });
Expand Down Expand Up @@ -48,7 +49,6 @@ afterAll((done) => {
describe("Faculty API", () => {
it("should create faculty", async () => {
const response = await agent.post("/faculty/create").send({
ERPID: "test123",
dateOfJoining: "2023-06-18T14:11:30Z",
dateOfLeaving: "2023-07-18T14:11:30Z",
profileLink: "xyz",
Expand Down Expand Up @@ -277,6 +277,7 @@ describe("Faculty API", () => {
]);
});


describe("after adding faculty", () => {
let id;
beforeEach(async () => {
Expand Down
21 changes: 9 additions & 12 deletions test/routes/student.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ afterAll((done) => {
describe("Student API", () => {
it("should create student", async () => {
const response = await agent.post("/student/create").send({
ERPID: "ST14556245",
name: "John",
joiningYear: 2022,
name: "Arya",
joiningYear: 2020,
branch: branchId,
division: "B",
rollNo: 101,
Expand Down Expand Up @@ -217,9 +216,8 @@ describe("Student API", () => {
let id;
beforeEach(async () => {
id = await agent.post("/student/create").send({
ERPID: "ST14556245",
name: "John",
joiningYear: 2022,
name: "Arya",
joiningYear: 2020,
branch: branchId,
division: "B",
rollNo: 101,
Expand Down Expand Up @@ -381,12 +379,11 @@ describe("Student API", () => {
stdMedHistory.remove({ uid: "USR25123456445" }),
stdPersonal.remove({ uid: "USR25123456445" }),
studentModel.remove({
ERPID: "ST14556245",
name: "John",
joiningYear: 2022,
name: "Arya",
joiningYear: 2020,
branch: branchId,
division: "B",
rollNo: 101,
division: "A",
rollNo: 12,
coursesOpted: courseIds,
}),
]);
Expand All @@ -401,7 +398,7 @@ describe("Student API", () => {
it("should update student", async () => {
const response = await agent
.post(`/student/update/${id}`)
.send({ ERPID: "S1032220999" }, { joiningYear: 2021 });
.send({ name: "Arya" }, { joiningYear: 2021 });

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