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

[ADDED] Added validation for module. #443

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
coverage
logs
.env
.env
8 changes: 5 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ module.exports = {
"alias": {
"map": [
["#app", "./app.js"],
["#util", "./util.js"],
["#constant", "./constant.js"],
["#util", "./misc/util.js"],
["#constant", "./misc/constant.js"],
["#routes", "./routes"],
["#models", "./models"],
["#middleware", "./middleware"],
["#controller", "./controller"],
["#services", "./services"],
["#error", "./error"]
["#error", "./error"],
["#misc", "./misc"],
["#mockDB", "./misc/mockDB"]
],
"extensions": [".js"]
}
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN npm ci

COPY . .

EXPOSE 3500
CMD ["npm", "run", "start"]
EXPOSE 4000
CMD ["npm", "run", "serverstart"]


4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TCET ERP System

TCET ERP System is a project that aims to simplify and automate daily operation in TCET.
TCET ERP System is a project that aims to simplify and automate daily operations in TCET.

This ERP system will be used to manage various aspects of the operations of colleges, including admissions, registration, student records, financial aid, course scheduling, and fees. The ERP system would typically consist of multiple integrated modules that support these functions.

Expand Down Expand Up @@ -32,7 +32,7 @@ node -e "console.log(require('crypto').randomBytes(256).toString('base64'));
Set this on 'local'

`DB_URL`
For this parameter you will need to open your account on MongoDB Atlas, don't forget to note down you account password, then create new cluster and through that you will get your connection string which will be your DB_URL in .env, make sure instead of "password" in connection string, you enter your own account password.
For this parameter, you will need to open your account on MongoDB Atlas, don't forget to note down your account password, then create new cluster and through that you will get your connection string which will be your DB_URL in .env, make sure instead of "password" in connection string, you enter your own account password.

`EMAIL_HOST`,
`EMAIL_PORT`,
Expand Down
16 changes: 12 additions & 4 deletions _apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
* @apiBody {String} wing The wing where the infrastructure is located.
* @apiBody {Number} floor The floor where the infrastructure is located.
* @apiBody {Number} capacity The capacity of the infrastructure.
* @apiBody {connector.Schema.Types.ObjectId} organization The organization which is associated.
*
* @apiSuccess {String} res Success message with the ID of the added infrastructure.
*
Expand All @@ -198,6 +199,7 @@
* @apiSuccess {String} infrastructure.wing Wing of Infrastructure. One of possible A,B,C.
* @apiSuccess {Number} infrastructure.floor Floor of Infrastructure.
* @apiSuccess {Number} infrastructure.capacity Capacity of Infrastructure.
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
*/

/**
Expand Down Expand Up @@ -226,6 +228,7 @@
* @apiBody {String} [wing] The wing where the infrastructure is located.
* @apiBody {Number} [floor] The floor where the infrastructure is located.
* @apiBody {Number} [capacity] The capacity of the infrastructure.
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
*
* @apiSuccess {String} res infrastructure updated.
* @apiError (Error 500) err Error in updating database
Expand Down Expand Up @@ -432,6 +435,7 @@
* @apiBody {Date} yearOfStarting The year of establishment of the Department.
* @apiBody {connector.Schema.Types.ObjectId} accreditations The accreditation which is associated.
* @apiBody {connector.Schema.Types.ObjectId} infrastructure The infrastructure which is associated.
* @apiBody {connector.Schema.Types.ObjectId} organization The organization which is associated.
*
* @apiSuccess {String} res added Department successfully.
*
Expand All @@ -450,6 +454,7 @@
* @apiBody {Date} [yearOfStarting] The year of establishment of the Department.
* @apiBody {connector.Schema.Types.ObjectId} [accreditations] Accreditation which is associated.
* @apiBody {connector.Schema.Types.ObjectId} [infrastructure] Infrastructure which is associated.
* @apiBody {connector.Schema.Types.ObjectId} organization The organization which is associated.
*
* @apiSuccess {Department[]} res Array of Filtered Department Doc .
* @apiSuccess {String} department._id ID of document given by database.
Expand All @@ -458,6 +463,7 @@
* @apiSuccess {Date} department.yearOfStarting The year of establishment of the Department.
* @apiSuccess {connector.Schema.Types.ObjectId} department.accreditations associated Accreditation.
* @apiSuccess {connector.Schema.Types.ObjectId} department.infrastructure associatedInfrastructure.
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
* @apiError (Error 500) err Error while fetching the data.
*/

Expand Down Expand Up @@ -488,6 +494,7 @@
* @apiSuccess {Date} department.yearOfStarting The year of establishment of the Department.
* @apiSuccess {connector.Schema.Types.ObjectId} department.accreditations associated Accreditation.
* @apiSuccess {connector.Schema.Types.ObjectId} department.infrastructure associatedInfrastructure.
* @apiSuccess {connector.Schema.Types.ObjectId} department.organization associated Organization.
*
* @apiSuccess {String} res updated infrastructure with id.
* @apiError (Error 500) err Error while inserting in DB
Expand Down Expand Up @@ -655,8 +662,8 @@
*
* @apiQuery {Number} [no] Module number.
* @apiQuery {String} [name] Name of the module.
* @apiQuery {String} [outcome] Module outcome.
* @apiQuery {String[]} [contents] Array of contents of the module.
* @apiQuery {ObjectId} content ID of the Topics (ObjectId).
* @apiQuery {Number} [hrsPerModule] Number of hours required per module.
* @apiQuery {String[]} [cognitiveLevels] Array of cognitive levels
* of attainment as per Bloom's Taxanomy (L1-L6).
Expand All @@ -665,7 +672,6 @@
* @apiSuccess {String} module._id ID of document given by database.
* @apiSuccess {String} module.no Module number.
* @apiSuccess {String} module.name Name of the module.
* @apiSuccess {String} module.outcome Module outcome.
* @apiSuccess {String[]} module.contents Array of contents of the module.
* @apiSuccess {Number} module.hrsPerModule Number of hours required per module.
* @apiSuccess {String[]} module.cognitiveLevels Array of cognitive levels of
Expand Down Expand Up @@ -741,8 +747,8 @@
*
* @apiBody {Number} [no] Module number.
* @apiBody {String} [name] Name of the module.
* @apiBody {String} [outcome] Module outcome.
* @apiBody {String[]} [contents] Array of contents of the module.
* @apiBody {ObjectId} content ID of the Topics (ObjectId).
* @apiBody {Number} [hrsPerModule] Number of hours required per module.
* @apiBody {String[]} [cognitiveLevels] Array of cognitive levels
* of attainment as per Bloom's Taxanomy (L1-L6).
Expand Down Expand Up @@ -772,8 +778,8 @@
* @apiParam {String} moduleId The ID of the Module document to update.
* @apiBody {Number} [no] Module number.
* @apiBody {String} [name] Name of the module.
* @apiBody {String} [outcome] Module outcome.
* @apiBody {String[]} [contents] Array of contents of the module.
* @apiBody {ObjectId} content ID of the Topics (ObjectId).
* @apiBody {Number} [hrsPerModule] Number of hours required per module.
* @apiBody {String[]} [cognitiveLevels] Array of cognitive levels
* of attainment as per Bloom's Taxanomy (L1-L6).
Expand Down Expand Up @@ -1875,3 +1881,5 @@
* @apiError (Error 500) err Error in updating database
*
*/

// TODO ADD COURSE ENDPOINT APIDOCS
14 changes: 9 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import groupRouter from "#routes/group";
import performarouter from "#routes/performance";
import notificationRouter from "#routes/notification";
import topicRouter from "#routes/topic";
import courseRouter from "#routes/course";

const app = express();
const currDirName = dirname(fileURLToPath(import.meta.url));
Expand All @@ -40,10 +41,12 @@ app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(morgan(
":remote-addr - :remote-user \":method :url HTTP/:http-version\" :status \":referrer\" \":user-agent\"",
{ stream: logger.stream },
));
app.use(
morgan(
":remote-addr - :remote-user \":method :url HTTP/:http-version\" :status \":referrer\" \":user-agent\"",
{ stream: logger.stream },
),
);

app.use(express.static(path.join(currDirName, "public")));

Expand Down Expand Up @@ -71,6 +74,7 @@ app.use("/semester", semesterRouter);
app.use("/faculty", facultyRouter);
app.use("/performance", performarouter);
app.use("/notification", notificationRouter);
app.use("/topic",topicRouter);
app.use("/topic", topicRouter);
app.use("/course", courseRouter);

export default app;
107 changes: 107 additions & 0 deletions controller/course.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {
createCourse,
courseList,
deleteCourseById,
updateCourseById,
} from "#services/course";
import { logger } from "#util";

async function addCourse(req, res) {
const {
name,
code,
theoryHours,
department,
tutorialHours,
practicalHours,
ISAMarks,
ESEMarks,
tutorialMarks,
practicalMarks,
semester,
subType,
prerequisites,
objective,
outcomes,
modules,
practicals,
tutorials,
assignments,
reccTextbooks,
refBooks,
} = req.body;
try {
const newCourse = await createCourse(
name,
code,
theoryHours,
department,
tutorialHours,
practicalHours,
ISAMarks,
ESEMarks,
tutorialMarks,
practicalMarks,
semester,
subType,
prerequisites,
objective,
outcomes,
modules,
practicals,
tutorials,
assignments,
reccTextbooks,
refBooks,
);
res.json({ res: `added course ${newCourse.ERPID}` });
} catch (error) {
logger.error("Error while inserting", error);
res.status(500);
res.json({ err: "Error while inserting in DB" });
}
}

async function getCourse(req, res) {
try {
const filter = req.body;
const { limit, page } = req.query;
const courselist = await courseList(filter, limit, page);
res.json({ res: courselist });
} catch (error) {
logger.error("Error while fetching", error);
res.status(500);
res.json({ err: "Error while fetching the data" });
}
}

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

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

export default {
addCourse,
getCourse,
deleteCourse,
updateCourse,
};
11 changes: 9 additions & 2 deletions controller/department.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import {
import { logger } from "#util";

async function addDepartment(req, res) {
const { name, acronym, yearOfStarting, accreditations, infrastructures } =
req.body;
const {
name,
acronym,
yearOfStarting,
accreditations,
infrastructures,
organization,
} = req.body;
try {
const department = await createnewdepartment(
name,
acronym,
yearOfStarting,
accreditations,
infrastructures,
organization,
);
res.json({
res: `added Department successfully ${department.name}`,
Expand Down
40 changes: 29 additions & 11 deletions controller/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,42 @@ import {
updateExamById,
} from "#services/exam";
import { logger } from "#util";
import { isEntityIdValid } from "#middleware/entityIdValidation";
import Infrastructure from "#models/infrastructure";
import Course from "#models/course";
import Faculty from "#models/faculty";

async function addExam(req, res) {
const { date, startTime, duration, infrastructure, supervisor, course } =
req.body;

// Checking if the provided IDs exist in the database
const isInfrastructureValid = await isEntityIdValid(
infrastructure,
Infrastructure,
);
const isSupervisorValid = await isEntityIdValid(supervisor, Faculty);
const isCourseValid = await isEntityIdValid(course, Course);

try {
const exam = await createExam(
date,
startTime,
duration,
supervisor,
infrastructure,
course,
);
res.json({ res: `added exam ${exam.id}`, id: exam.id });
if (!isInfrastructureValid || !isSupervisorValid || !isCourseValid) {
res.status(400).json({
error: `Invalid ID(s): Infra:${isInfrastructureValid} Supervisor:${isSupervisorValid} Course:${isCourseValid} `,
});
} else {
const exam = await createExam(
date,
startTime,
duration,
supervisor,
infrastructure,
course,
);
res.json({ res: `added exam ${exam.id}`, id: exam.id });
}
} catch (error) {
logger.error("Error while inserting", error);
res.status(500);
res.json({ err: "Error while inserting in DB" });
res.status(500).json({ err: "Error while inserting in DB" });
}
}

Expand Down
3 changes: 2 additions & 1 deletion controller/infrastructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
import { logger } from "#util";

async function addInfrastructure(req, res) {
const { name, type, wing, floor, capacity } = req.body;
const { name, type, wing, floor, capacity, organization } = req.body;
try {
const newInfrastructure = await createInfrastructure(
name,
type,
wing,
floor,
capacity,
organization,
);
res.json({
res: `added infrastructure ${newInfrastructure.id}`,
Expand Down
Loading
Loading