Skip to content

Commit

Permalink
Merge pull request #366 from tcet-opensource/development
Browse files Browse the repository at this point in the history
Biweekly Merge
  • Loading branch information
TejasNair9977 authored Oct 1, 2023
2 parents 6bbdbc0 + 14042f9 commit 9afc3d3
Show file tree
Hide file tree
Showing 85 changed files with 4,979 additions and 494 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
es2021: true,
jest: true
},
extends: "airbnb-base",
extends: ["airbnb-base", "prettier"],
overrides: [],
parserOptions: {
ecmaVersion: "latest",
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/node_modules
**/apidoc
**/.git
**/_apidoc.js
**/*.json
**/*.css
Dockerfile
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"tabWidth": 2
"singleQuote": false,
"tabWidth": 2,
"semi": true
}
File renamed without changes.
1,041 changes: 1,041 additions & 0 deletions _apidoc.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@ import { logger } from "#util";
import indexRouter from "#routes/index";
import usersRouter from "#routes/users";
import authRouter from "#routes/auth";
import semesterRouter from "#routes/semester";
import accreditationRouter from "#routes/accreditation";
import infrastructureRouter from "#routes/infrastructure";
import practicalRouter from "#routes/practical";
import organizationRouter from "#routes/organization";
import studentRouter from "#routes/student";
import tutorialRouter from "#routes/tutorial";
import assignmentRouter from "#routes/assignment";
import timetableRouter from "#routes/timetable";
import courseworkRouter from "#routes/coursework";
import activityRouter from "#routes/activity";
import moduleRouter from "#routes/module";
import facultyRouter from "#routes/faculty";
import { identifyUser } from "#middleware/identifyUser";
import departmentRouter from "#routes/department";
import paperRouter from "#routes/paper";
import groupRouter from "#routes/group";

const app = express();
const currDirName = dirname(fileURLToPath(import.meta.url));
Expand All @@ -33,5 +47,20 @@ app.use("/users", usersRouter);
app.use("/auth", authRouter);
app.use("/accreditation", accreditationRouter);
app.use("/infrastructure", infrastructureRouter);
app.use("/department", departmentRouter);
app.use("/practical", practicalRouter);
app.use("/organization", organizationRouter);
app.use("/student", studentRouter);
app.use("/activity", activityRouter);
app.use("/tutorial", tutorialRouter);
app.use("/assignment", assignmentRouter);
app.use("/timetable", timetableRouter);
app.use("/department", departmentRouter);
app.use("/coursework", courseworkRouter);
app.use("/module", moduleRouter);
app.use("/paper", paperRouter);
app.use("/group", groupRouter);
app.use("/semester", semesterRouter);
app.use("/faculty", facultyRouter);

export default app;
11 changes: 6 additions & 5 deletions controller/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ async function addAccreditation(req, res) {
try {
// eslint-disable-next-line max-len
const accreditation = await addNewAccreditation(name, agencyName, dateofAccreditation, dateofExpiry);
res.json({ res: `added accreditation ${accreditation.name}` });
res.json({ res: `added accreditation ${accreditation.name}`, id: accreditation.id });
} catch (error) {
logger.error("Error while inserting", error);
res.status(500);
res.json({ err: "Error while inserting in DB" });
}
}
async function deleteAccreditation(req, res) {
const { accredationId } = req.params;
const { id } = req.params;
try {
await deleteAccreditationById(accredationId);
await deleteAccreditationById(id);
res.json({ res: "Accreditation deleted successfully" });
} catch (error) {
logger.error("Error while deleting", error);
Expand All @@ -30,13 +30,14 @@ async function deleteAccreditation(req, res) {
}

async function updateAccreditation(req, res) {
const { id } = req.params;
const {
id, ...data
...data
} = req.body;

try {
await updateAccreditationById(id, data);
res.json({ res: "accreditation updated" });
res.json({ res: `${id} accreditation updated` });
} catch (error) {
logger.error("Error while inserting", error);
res.status(500);
Expand Down
64 changes: 64 additions & 0 deletions controller/activity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
createActivity,deleteActivityById, activityList ,updateActivityById,
}from "#services/activity";
import {logger} from "#util" ;

async function addActivity(req,res) {
const{
activityBlueprint,
startTime,
duration,
course,
faculty,
type,
task,
group,
students,
}=req.body;
try{
const newActivity = await createActivity(activityBlueprint,startTime,duration,course,faculty,type,task,group,students);
res.json ({res: `added activity ${newActivity.id}`, id: newActivity.id});
} catch (error){
logger.error ("Error while inserting",error);
res.status(500);
res.json({err:"Error while inserting in DB"});
}
}

async function updateActivity(req,res){
const { id }=req.params;
const {
...data
}=req.body;
try {
await updateActivityById(id,data);
res.json({res:`updated activity with id ${id}`});
}catch (error){
logger.error("Error while updating",error);
res.status(500);
res.json({err:"Error while updating in DB"});
}
}

async function getActivity(req,res){
const filter = req.query;
const activitylist =await activityList(filter);
res.json({res:activitylist});
}


async function deleteActivity(res,req){
const { id }=req.params;
try{
await deleteActivityById(id);

res.json({res:`Deleted activity with ID ${id}`});
}catch(error){
logger.error ("Error while deleting",error);
res.status(500).json({error:"Error while deleting from DB"});
}
}

export default {
addActivity, deleteActivity ,getActivity ,updateActivity,
};
54 changes: 54 additions & 0 deletions controller/assignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
createAssignment, deleteAssignmentById, assignmentList, updateAssignmentById,
} from "#services/assignment";
import { logger } from "#util";

async function addAssignment(req, res) {
const {
no, title, type, marks,
} = req.body;
try {
const newAssignment = await createAssignment(no, title, type, marks);
res.json({ res: `added assignment ${newAssignment.id}`, id: newAssignment.id });
} catch (error) {
logger.error("Error while inserting", error);
res.status(500);
res.json({ err: "Error while inserting in DB" });
}
}

async function updateAssignment(req, res) {
const { id } = req.params;
const {
...data
} = req.body;
try {
await updateAssignmentById(id, data);
res.json({ res: `updated assignment ${id}` });
} catch (error) {
logger.error("Error while updating", error);
res.status(500);
res.json({ err: "Error while updaing in DB" });
}
}

async function getAssignment(req, res) {
const filter = req.query;
const assingmentlist = await assignmentList(filter);
res.json({ res: assingmentlist });
}

async function deleteAssignment(req, res) {
const { id } = req.params;
try {
await deleteAssignmentById(id);

res.json({ res: `Deleted assignment with ID ${id}` });
} catch (error) {
logger.error("Error while deleting", error);
res.status(500).json({ error: "Error while deleting from DB" });
}
}
export default {
addAssignment, deleteAssignment, getAssignment, updateAssignment,
};
6 changes: 5 additions & 1 deletion controller/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ async function login(req, res) {
}

function validateUser(req, res) {
res.json({ res: req.user, msg: "user validated", err: null });
if (req.user) {
res.json({ res: req.user, msg: "user validated", err: null });
} else {
res.status(401).json({ res: null, msg: "unauthorised", err: "User not authorised" });
}
}

async function sendOTP(req, res) {
Expand Down
68 changes: 68 additions & 0 deletions controller/coursework.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Import Coursework-related services and utilities
import {
createCoursework,
deleteCourseworkById,
listCoursework,
updateCourseworkById,
} from "#services/coursework";

import { logger } from "#util"; // Import the logger utility

// Controller function to add a new Coursework entity
async function addCoursework(req, res) {
const {
student, type, course, task, objectID, activity, marks,
} = req.body;
try {
const newCoursework = await createCoursework({
student, type, course, task, objectID, activity, marks,
});
res.json({ res: `Added Coursework with ID ${newCoursework.id}`, id: newCoursework.id });
} catch (error) {
logger.error("Error while inserting Coursework", error);
res.status(500);
res.json({ err: "Error while inserting Coursework in DB" });
}
}

// Controller function to update a Coursework entity
async function updateCoursework(req, res) {
const { id } = req.params;
const {
...data
} = req.body;
try {
await updateCourseworkById(id, data);
res.json({ res: "/Updated Coursework/" });
} catch (error) {
logger.error("Error while updating Coursework", error);
res.status(500);
res.json({ err: "Error while updating Coursework in DB" });
}
}

// Controller function to get a list of Coursework entities
async function getCoursework(req, res) {
const filter = req.query;
const courseworkList = await listCoursework(filter);
res.json({ res: courseworkList });
}

// Controller function to delete a Coursework entity
async function deleteCoursework(req, res) {
const { id } = req.params;
try {
await deleteCourseworkById(id);
res.json({ res: `Deleted Coursework with ID ${id}` });
} catch (error) {
logger.error("Error while deleting Coursework", error);
res.status(500).json({ error: "Error while deleting Coursework from DB" });
}
}

export default {
addCoursework,
deleteCoursework,
getCoursework,
updateCoursework,
};
80 changes: 80 additions & 0 deletions controller/department.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
updateDepartmentbyid, createnewdepartment, listdepartment, deletedepartment,
} from "#services/department";

import { logger } from "#util";

async function addDepartment(req, res) {
const {
name,
acronym,
yearOfStarting,
accreditations,
infrastructures,
} = req.body;
try {
const department = await createnewdepartment(
name,
acronym,
yearOfStarting,
accreditations,
infrastructures,
);
res.json({
res: `added Department successfully ${department.name}`,
id: department.id,
});
} catch (error) {
logger.error("Error while inserting", error);
res.status(500);
res.json({ err: "Error while inserting in DB" });
}
}

async function removedepartmentbyid(req, res) {
const { departmentId } = req.params;
try {
await deletedepartment(departmentId);
res.json({
res: "Department deleted successfully",
});
} catch (error) {
logger.error("Error while deleting", error);
res.status(500);
res.json({ err: "Error while deleting from DB" });
}
}

async function showdepartments(req, res) {
try {
const departments = await listdepartment(req.query);
return res.json({
res: departments,
});
} catch (error) {
logger.error("Error while fetching", error);
res.status(500);
return res.json({ err: "Error while fetching the data" });
}
}

async function updatedDepartment(req, res) {
const { id } = req.params;
const {
...data
} = req.body;
try {
await updateDepartmentbyid(id, data);
res.json({
res: "department updated successfully",
});
} catch (error) {
logger.error("Error while inserting", error);
res.status(500);
res.json({ err: "Error while inserting in DB" });
}
}

export default {
updatedDepartment, showdepartments, removedepartmentbyid, addDepartment,
};
Loading

0 comments on commit 9afc3d3

Please sign in to comment.