Skip to content

Commit cad89da

Browse files
Merge pull request #323 from tcet-opensource/292-Create-all-endpoints-for-student
292 Created all endpoints for student
2 parents 9d9c399 + 5e08ef2 commit cad89da

File tree

5 files changed

+486
-390
lines changed

5 files changed

+486
-390
lines changed

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import usersRouter from "#routes/users";
1010
import authRouter from "#routes/auth";
1111
import accreditationRouter from "#routes/accreditation";
1212
import infrastructureRouter from "#routes/infrastructure";
13+
import studentRouter from "#routes/student";
1314
import tutorialRouter from "#routes/tutorial";
1415
import assignmentRouter from "#routes/assignment";
1516
import timetableRouter from "#routes/timetable";
@@ -39,6 +40,7 @@ app.use("/users", usersRouter);
3940
app.use("/auth", authRouter);
4041
app.use("/accreditation", accreditationRouter);
4142
app.use("/infrastructure", infrastructureRouter);
43+
app.use("/student", studentRouter);
4244
app.use("/tutorial", tutorialRouter);
4345
app.use("/assignment", assignmentRouter);
4446
app.use("/timetable", timetableRouter);

controller/student.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
createStudent, deleteStudentById, studentList, updateStudentById,
3+
} from "#services/student";
4+
import { logger } from "#util";
5+
6+
async function addStudent(req, res) {
7+
const {
8+
ERPID, name, joiningYear, branch, division, rollNo, coursesOpted
9+
} = req.body;
10+
try {
11+
const newStudent = await createStudent(ERPID, name, joiningYear, branch, division, rollNo, coursesOpted);
12+
res.json({ res: `added user ${newStudent.id}` });
13+
} catch (error) {
14+
logger.error("Error while inserting", error);
15+
res.status(500);
16+
res.json({ err: "Error while inserting in DB" });
17+
}
18+
}
19+
20+
async function updateStudent(req, res) {
21+
const {
22+
id, ...data
23+
} = req.body;
24+
try {
25+
await updateStudentById(id, data);
26+
res.json({ res: `updated Student with id ${id}` });
27+
} catch (error) {
28+
logger.error("Error while updating", error);
29+
res.status(500);
30+
res.json({ err: "Error while updaing in DB" });
31+
}
32+
}
33+
34+
async function getStudent(req, res) {
35+
const filter = req.query;
36+
const StudList = await StudentList(filter);
37+
res.json({ res: StudList });
38+
}
39+
40+
async function deleteStudent(req, res) {
41+
const { StudentId } = req.params;
42+
try {
43+
await deleteStudentById(StudentId);
44+
45+
res.json({ res: `Deleted Student with ID ${StudentId}` });
46+
} catch (error) {
47+
logger.error("Error while deleting", error);
48+
res.status(500).json({ error: "Error while deleting from DB" });
49+
}
50+
}
51+
export default {
52+
addStudent, deleteStudent, getStudent, updateStudent,
53+
};
54+

0 commit comments

Comments
 (0)