Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #242

Closed
Closed
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
118 changes: 103 additions & 15 deletions _apidoc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,107 @@
// ------------------------------------------------------------------------------------------
// General apiDoc documentation blocks and old history blocks.
// ------------------------------------------------------------------------------------------
/**
* @api {post} /auth Login User
* @apiName LoginUser
* @apiGroup Authentication
*
* @apiParam {String} id User ID.
* @apiParam {String} password User password.
*
* @apiSuccess {String} res Response message.
* @apiSuccess {Object} user User details.
* @apiSuccess {String} user.uid User ID.
* @apiSuccess {String} user.name User name.
* @apiSuccess {String} user.emailId User email ID.
* @apiSuccess {String} user.type User type.
* @apiSuccess {String} user.token User token.
*
* @apiSuccessExample Success Response:
* HTTP/1.1 200 OK
* {
* "res": "welcome",
* "user": {
* "uid": "123",
* "name": "Some User",
* "emailId": "[email protected]",
* "type": "user",
* "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
* }
* }
*
* @apiError (Error 403) UserDoesNotExist Incorrect ID or password.
* @apiError (Error 500) ServerError Something is wrong on our side. Try again.
*/

// ------------------------------------------------------------------------------------------
// Current Success.
// ------------------------------------------------------------------------------------------
/**
* @api {post} /auth/validateUser Validate User
* @apiName ValidateUser
* @apiGroup Authentication
* @apiDescription Validates the user's authentication token.
*
* @apiHeader {String} Authorization User's authentication token.
*
* @apiSuccess {Object} res User object.
* @apiSuccess {Object} res.user User details.
* @apiSuccess {String} res.user.uid User ID.
* @apiSuccess {String} res.user.name User name.
* @apiSuccess {String} res.user.emailId User email ID.
* @apiSuccess {String} res.user.type User type.
*
* @apiSuccessExample Success Response:
* HTTP/1.1 200 OK
* {
* "res": {
* "user": {
* "uid": "123",
* "name": "Some User",
* "emailId": "[email protected]",
* "type": "user"
* },
* "msg": "user validated",
* "err": null
* }
* }
*/

// ------------------------------------------------------------------------------------------
// Current Errors.
// ------------------------------------------------------------------------------------------
/**
* @api {post} /auth/sendOTP Send OTP
* @apiName SendOTP
* @apiGroup Authentication
* @apiDescription Sends an OTP (One-Time Password) to the user's email ID.
*
* @apiParam {String} uid User ID.
* @apiParam {String} emailId User email ID.
*
* @apiSuccess {String} res Response message.
*
* @apiSuccessExample Success Response:
* HTTP/1.1 200 OK
* {
* "res": "otp sent to emailID"
* }
*
* @apiError (Error) IncorrectUidOrEmail Incorrect UID or emailId.
*/

// ------------------------------------------------------------------------------------------
// Current Permissions.
// ------------------------------------------------------------------------------------------
/**
* @api {post} /auth/resetPassword Reset Password
* @apiName ResetPassword
* @apiGroup Authentication
* @apiDescription Resets the user's password using the provided OTP (One-Time Password).
*
* @apiParam {String} uid User ID.
* @apiParam {String} otp One-Time Password received by the user.
* @apiParam {String} password New password.
*
* @apiSuccess {String} res Response message.
*
* @apiSuccessExample Success Response:
* HTTP/1.1 200 OK
* {
* "res": "successfully updated password"
* }
*
* @apiError (Error) IncorrectOtp Incorrect OTP.
* @apiError (Error 500) UpdateError Something went wrong while updating password.
* @apiError (Error 500) ServerError Something went wrong.
*/

// ------------------------------------------------------------------------------------------
// History.
// ------------------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion controller/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function resetPassword(req, res) {
await updatePassword(uid, password);
res.json({ res: "successfully updated password" });
} catch (error) {
logger.log("Error while updating", error);
logger.error("Error while updating", error);
res.status(500);
if (error.name === "UpdateError") res.json({ err: "Something went wrong while updating password" });
else res.json({ err: "something went wrong" });
Expand Down
4 changes: 2 additions & 2 deletions controller/infrastructure.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createinfrastructure } from "#services/infrastructure";
import { createInfrastructure } from "#services/infrastructure";
import { logger } from "#util";

async function addinfrastructure(req, res) {
const {
name, type, wing, floor, capacity,
} = req.body;
try {
const newinfrastructure = await createinfrastructure(name, type, wing, floor, capacity);
const newinfrastructure = await createInfrastructure(name, type, wing, floor, capacity);
res.json({ res: `added user ${newinfrastructure.id}` });
} catch (error) {
logger.error("Error while inserting", error);
Expand Down
19 changes: 11 additions & 8 deletions models/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ const accreditationSchema = {
const Accreditation = connector.model("Accreditation", accreditationSchema);

async function remove(filter) {
const res = await Accreditation.findOneAndDelete(filter);
return res;
const deleteResult = await Accreditation.deleteMany(filter);
return deleteResult.acknowledged;
}

async function create(name, agencyName, dateofAccreditation, dateofExpiry) {
async function create(accreditationData) {
const {
name, agencyName, dateofAccreditation, dateofExpiry,
} = accreditationData;
const accreditation = new Accreditation({
name,
agencyName,
Expand All @@ -26,13 +29,13 @@ async function create(name, agencyName, dateofAccreditation, dateofExpiry) {
}

async function read(filter, limit = 1) {
const accreditationData = await Accreditation.find(filter).limit(limit);
return accreditationData;
const accreditationDoc = await Accreditation.find(filter).limit(limit);
return accreditationDoc;
}

async function update(filter, updateObject) {
const accreditation = await Accreditation.findOneAndUpdate(filter, updateObject, { new: true });
return accreditation;
async function update(filter, updateObject, options = { multi: true }) {
const deleteResult = await Accreditation.updateMany(filter, { $set: updateObject }, options);
return deleteResult.acknowledged;
}

export default {
Expand Down
7 changes: 4 additions & 3 deletions models/assignment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import connector from '#models/databaseUtil';
import connector from "#models/databaseUtil";

const assignmentSchema = {
no: { type: Number, required: true },
title: { type: String, required: true },
type: { type: String, required: true, enum: ['FA', 'RA'] },
type: { type: String, required: true, enum: ["FA", "RA"] },
marks: { type: Number, required: true },
};

const Assignment = connector.model('Assignment', assignmentSchema);
// eslint-disable-next-line no-unused-vars
const Assignment = connector.model("Assignment", assignmentSchema);
65 changes: 24 additions & 41 deletions models/attendance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import connector from "./databaseUtil";
import connector from "#models/databaseUtil";

connector.set("debug", true);

Expand All @@ -13,52 +13,35 @@ const attendanceSchema = {

const Attendance = connector.model("Attendance", attendanceSchema);

async function create(studentId, courseId) {
try {
const attendance = new Attendance({
student: studentId,
course: courseId,
});
const createAttendance = await attendance.save();
return createAttendance;
} catch (error) {
console.error("Error creating attendance:", error);
return null;
}
async function create(attendanceData) {
const {
student, course, monthlyAttended, monthlyOccured, cumulativeAttended, cumulativeOccured,
} = attendanceData;
const attendance = new Attendance({
student,
course,
monthlyAttended,
monthlyOccured,
cumulativeAttended,
cumulativeOccured,
});
const attendanceDoc = await attendance.save();
return attendanceDoc;
}

async function read(attendanceId) {
try {
const attendance = await Attendance.findById(attendanceId);
return attendance;
} catch (error) {
console.error("error reading attendance", error);
return null;
}
async function read(filter, limit = 1) {
const attendanceDoc = await Attendance.find(filter).limit(limit);
return attendanceDoc;
}

async function update(attendanceId, updateData) {
try {
const updatedAttendance = await Attendance.findByIdAndUpdate(
attendanceId,
updateData,
{ new: true },
);
return updatedAttendance;
} catch (error) {
console.error("error updating attendance:", error);
return null;
}
async function update(filter, updateObject, options = { multi: true }) {
const updateResult = await Attendance.updateMany(filter, { $set: updateObject }, options);
return updateResult.acknowledged;
}

async function remove(attendanceId) {
try {
const deletedAttendance = await Attendance.findByIdAndDelete(attendanceId);
return deletedAttendance;
} catch (error) {
console.error("error removing attendance", error);
return null;
}
async function remove(filter) {
const deleteResult = await Attendance.deleteMany(filter);
return deleteResult.acknowledged;
}
export default {
create, remove, update, read,
Expand Down
54 changes: 23 additions & 31 deletions models/course.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { connector } = require('#models/databaseUtil')
const { connector } = require("#models/databaseUtil");

const courseSchema = {
name: { type: String, required: true },
Expand All @@ -13,12 +13,12 @@ const courseSchema = {
practicalMarks: { type: Number, required: true },
semester: {
type: connector.Schema.Types.ObjectId,
ref: 'Semester',
ref: "Semester",
required: true,
},
subType: {
type: String,
enum: ['open', 'professional', 'core'],
enum: ["open", "professional", "core"],
required: true,
}, // can be open, professional, or core
prerequisites: { type: [String], required: true }, // array of strings
Expand All @@ -29,60 +29,52 @@ const courseSchema = {
RBTLevel: { type: [String] },
},
], // this is the modules from syllabus
modules: [{ type: connector.Schema.Types.ObjectId, ref: 'Module' }],
practicals: [{ type: connector.Schema.Types.ObjectId, ref: 'Practical' }],
tutorials: [{ type: connector.Schema.Types.ObjectId, ref: 'Tutorial' }],
assignments: [{ type: connector.Schema.Types.ObjectId, ref: 'Assignment' }],
modules: [{ type: connector.Schema.Types.ObjectId, ref: "Module" }],
practicals: [{ type: connector.Schema.Types.ObjectId, ref: "Practical" }],
tutorials: [{ type: connector.Schema.Types.ObjectId, ref: "Tutorial" }],
assignments: [{ type: connector.Schema.Types.ObjectId, ref: "Assignment" }],
reccTextbooks: { type: [String], required: true },
refBooks: { type: [String], required: true },
evalScheme: { type: [Number], required: true },
}
};

// virtual for total hours
courseSchema.virtual('totalHours').get(function() {
return this.theoryHours + this.tutorialHours + this.practicalHours
})
courseSchema.virtual("totalHours").get(() => this.theoryHours + this.tutorialHours + this.practicalHours);

// virtual for theory marks
courseSchema.virtual('theoryMarks').get(function() {
return this.ISAMarks + this.ESEMarks
})
courseSchema.virtual("theoryMarks").get(() => this.ISAMarks + this.ESEMarks);

// virtual for total marks
courseSchema.virtual('totalMarks').get(function() {
return this.theoryMarks + this.tutorialMarks + this.practicalMarks
})
courseSchema.virtual("totalMarks").get(() => this.theoryMarks + this.tutorialMarks + this.practicalMarks);

const Course = connector.model('Course', courseSchema)
const Course = connector.model("Course", courseSchema);

/// CRUD operations ///

async function create(courseData) {
const course = new Course(courseData)
const createdCourse = await course.save()
return createdCourse
const course = new Course(courseData);
const courseDoc = await course.save();
return courseDoc;
}

async function read(filter, limit = 1) {
const courseData = await Course.find(filter).limit(limit)
return courseData
const courseDoc = await Course.find(filter).limit(limit);
return courseDoc;
}

async function update(filter, updateObject) {
const updatedCourse = await Course.findOneAndUpdate(filter, updateObject, {
new: true,
}).exec()
return updatedCourse
async function update(filter, updateObject, options = { multi: true }) {
const updateResult = await Course.updateMany(filter, { $set: updateObject }, options);
return updateResult.acknowledged;
}

async function remove(filter) {
const deletedCourse = await Course.findOneAndDelete(filter).exec()
return deletedCourse
const deleteResult = await Course.deleteMany(filter).exec();
return deleteResult.acknowledged;
}

export default {
create,
read,
update,
remove,
}
};
Loading
Loading