Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1f37c70
refactor: migrate Department model to ES module syntax
agaesh Oct 11, 2025
4f483b6
refactor: migrate index.js to ES module syntax and improve model loading
agaesh Oct 11, 2025
169929a
refactor: migrate Instructor model to ES module syntax
agaesh Oct 11, 2025
0cf5423
refactor: migrate ProgramCourse model to ES module syntax
agaesh Oct 11, 2025
c759254
refactor: migrate Student model to ES module syntax
agaesh Oct 11, 2025
f439f61
refactor: migrate User model to ES module syntax
agaesh Oct 11, 2025
a6677ec
Merge pull request #62 from agaesh/fix/es6-migrations-models
agaesh Oct 11, 2025
28badbc
refactor: migrate DepartmentController to ES module syntax and improv…
agaesh Oct 9, 2025
eb6a06d
refactor: update createDepartment function to use ES module syntax an…
agaesh Oct 9, 2025
786f913
refactor: update updateDepartment function to use ES module syntax
agaesh Oct 9, 2025
9800a2e
refactor: add getDepartmentByID and deleteDepartment functions with p…
agaesh Oct 9, 2025
14de928
refactor: migrate InstructorController to ES module syntax and improv…
agaesh Oct 9, 2025
5aa7217
refactor: update UpdateInstructor and DeleteInstructor functions to u…
agaesh Oct 9, 2025
3feca0b
refactor: clean up CreateInstructor and UpdateInstructor functions fo…
agaesh Oct 9, 2025
f8909c5
refactor: migrate ProgramCourseController to ES module syntax and imp…
agaesh Oct 9, 2025
f06d06e
refactor: migrate getAllPrograms and UpdateProgram to ES module syntax
agaesh Oct 9, 2025
fdaa8ae
refactor: migrate DeleteProgram to ES module syntax
agaesh Oct 9, 2025
b67abd4
refactor: migrate userController to ES module syntax and improve func…
agaesh Oct 9, 2025
1ed4f27
refactor: streamline LoginUser function by reorganizing cookie settin…
agaesh Oct 9, 2025
c08a07b
Merge pull request #63 from agaesh/fix/es6-controllers
agaesh Oct 11, 2025
57d3238
refactor(routes): convert DepartmentRoutes to ES6 module syntax and f…
agaesh Oct 11, 2025
0d9aa4f
refactor(routes): convert InstructorRoutes to ES6 module syntax and i…
agaesh Oct 11, 2025
0aba74f
refactor(routes): convert ProgramRoutes to ES6 module syntax and impr…
agaesh Oct 11, 2025
b53d847
refactor(routes): convert userRoute to ES6 module syntax and improve …
agaesh Oct 11, 2025
f575997
Merge pull request #64 from agaesh/fix/es6-routes
agaesh Oct 11, 2025
c5e52d4
refactor(DepartmentServices): migrate to ES modules and improve error…
agaesh Oct 11, 2025
a980a5a
refactor(InstructorServices): migrate to ES modules and improve code …
agaesh Oct 11, 2025
f45768f
refactor(ProgramCourseServices): migrate to ES modules and improve co…
agaesh Oct 11, 2025
1f5fd8e
refactor(StudentService): migrate to ES modules and improve code stru…
agaesh Oct 11, 2025
4ba7bb3
refactor(UserService): migrate to ES modules and improve code structure
agaesh Oct 11, 2025
93f8491
Merge pull request #65 from agaesh/fix/es6-services
agaesh Oct 11, 2025
e7dfeab
refactor: convert RequiredBody.js to use ES6 import/export syntax
agaesh Oct 11, 2025
2049f21
refactor: convert RequiredID.js to use ES6 import/export syntax
agaesh Oct 11, 2025
d288a6e
Merge pull request #68 from agaesh/fix/es6-validators
agaesh Oct 11, 2025
9c83530
refactor(config): update to ES6 module syntax and enhance comments fo…
agaesh Oct 11, 2025
fe5a4ca
refactor(db): migrate to ES6 module syntax and update configuration i…
agaesh Oct 11, 2025
ed0cd94
refactor(config): migrate to ES module syntax and reorganize imports …
agaesh Oct 12, 2025
034a727
Merge pull request #69 from agaesh/fix/es6-config
agaesh Oct 12, 2025
a5ac686
fix(package): add "type": "module" to enable ES module support
agaesh Oct 12, 2025
1340ad9
Merge pull request #71 from agaesh/fix/add-es6-module-support
agaesh Oct 12, 2025
f34d5a7
fix(auth): correct token retrieval from cookies and update export syntax
agaesh Oct 12, 2025
bdb4514
Merge pull request #74 from agaesh/fix/es6-VerifyWebToken-Middleware
agaesh Oct 12, 2025
2c17edc
refactor(tests): update department tests to use ES module syntax and …
agaesh Oct 12, 2025
7a3bf4e
refactor(tests): update Instructor tests to use ES module syntax and …
agaesh Oct 12, 2025
c463583
added department_test.test.js. and old department_test.js have been d…
agaesh Oct 12, 2025
8abcf99
Merge pull request #76 from agaesh/fix/es6-tests
agaesh Oct 12, 2025
2d4c88e
refactor - importing config should be same as importing in another. i…
agaesh Oct 12, 2025
2837ad0
refactor - fixed sequelize variable path casing problem for confiq. f…
agaesh Oct 12, 2025
8086c3e
Casing changed to Config From Config
agaesh Oct 12, 2025
ac7a5e4
refactored all the path that import db.js and config
agaesh Oct 12, 2025
4d29dd0
Refactor: all the controllers method export together in the export de…
agaesh Oct 12, 2025
b79407f
all the Service methods are exported using default and verified and t…
agaesh Oct 12, 2025
8673ff9
added department_integration.test.test
agaesh Oct 12, 2025
301421a
Refactor: migrate from CommonJS to ES6 module syntax in migration files
agaesh Dec 28, 2025
1510175
Refactor: migrate migration and seeder files from CommonJS to ES6 mod…
agaesh Dec 28, 2025
4272308
Fix: enable timestamps for Department model
agaesh Dec 28, 2025
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "enroll",
"version": "1.0.0",
"description": "Student Management System",
"type": "module",
"main": "index.js",
"scripts": {
"start": "node ./src/config/index.js",
Expand Down
16 changes: 15 additions & 1 deletion src/Config/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
module.exports = {
/**
* Sequelize database configuration for the 'development' environment.
* This file uses ES6 module syntax (`export default`).
*/

export default {
development: {
// Uses environment variable DB_USER, falling back to 'root'
username: process.env.DB_USER || 'root',

// Uses environment variable DB_PASS, falling back to null (no password)
password: process.env.DB_PASS || null,

// Uses environment variable DB_NAME, falling back to 'EnrolNow'
database: process.env.DB_NAME || 'EnrolNow',

// Uses environment variable DB_HOST, falling back to '127.0.0.1' (localhost)
host: process.env.DB_HOST || '127.0.0.1',

// Specifies the database dialect
dialect: 'mysql'
}
};
20 changes: 15 additions & 5 deletions src/Config/db.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// db.js
const { Sequelize } = require('sequelize');
const config = require('./config').development;
/**
* Sequelize database connection setup using ES6 modules.
* It imports the database configuration from './database.config.js'.
*/
import { Sequelize } from 'sequelize';

// Import the default export (the configuration object) from the config file.
// Note: The original CJS referred to './config', but we use the actual file name.
import configModule from '../Config/config.js';

// Destructure the specific 'development' environment configuration.
const config = configModule.development;

// Initialize Sequelize instance
const sequelize = new Sequelize(
config.database,
config.username,
Expand All @@ -11,5 +21,5 @@ const sequelize = new Sequelize(
dialect: config.dialect,
}
);

module.exports = sequelize;
// Export the initialized Sequelize instance
export default sequelize;
58 changes: 40 additions & 18 deletions src/Config/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,52 @@
global.__basedir = __dirname;
const express = require('express');
// --- ES Module Setup for __dirname and __filename ---
// Import necessary modules for path resolution in ES modules
import path from 'path';
import { fileURLToPath } from 'url';

// Derive ES module equivalents for CJS context
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
global.__basedir = __dirname; // Set the global basedir

// --- Imports ---
import express from 'express';
import cookieParser from 'cookie-parser';
import { config } from 'dotenv';

// Initialize dotenv configuration immediately
config();

// Service Imports (Note: Must include .js extension for local modules)
import UserRegister from "../api/Services/UserService.js";
import ProgramService from '../api/Services/ProgramCourseServices.js';

// Route Imports (Note: Must include .js extension for local modules)
import userRoutes from '../api/Routes/userRoute.js';
import ProgramRoutes from '../api/Routes/ProgramRoutes.js';
import departmentRoutes from '../api/Routes/DepartmentRoutes.js';
import InstructorRoutes from "../api/Routes/InstructorRoutes.js";

// --- Application Setup ---
const app = express();
const port = 3000;
const cookieparser = require('cookie-parser');
app.use(express.json());
app.use(cookieparser());
require('dotenv').config();

const UserRegister = require("../api/Services/UserService");
const ProgramService = require('../api/Services/ProgramCourseServices')
// Require the router
const userRoutes = require('../api/Routes/userRoute');
const ProgramRoutes = require('../api/Routes/ProgramRoutes');
const departmentRoutes = require('../api/Routes/DepartmentRoutes')
const InstructorRoutes = require("../api/Routes/InstructorRoutes")
// Middleware
app.use(express.json());
app.use(cookieParser());
app.use(express.urlencoded({ extended: true }));

// Example route
app.get('/', (req, res) => {
res.send('Hello from Express API!');
});
app.use(express.urlencoded({ extended: true }));
// Use the router at a mount path

// Use the routers at their mount paths
app.use('/users', userRoutes);
app.use('/program', ProgramRoutes)
app.use('/department', departmentRoutes)
app.use("/instructor", InstructorRoutes)
app.use('/program', ProgramRoutes);
app.use('/department', departmentRoutes);
app.use("/instructor", InstructorRoutes);

// --- Start Server ---
app.listen(port, () => {
console.log(`Express API listening at http://localhost:${port}`);
});
3 changes: 2 additions & 1 deletion src/Database/Migrations/20250712044830-create-user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.createTable('Users', {
id: {
Expand Down Expand Up @@ -41,6 +41,7 @@ module.exports = {
}
});
},

async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Users');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Migrations/20250713051943-create-student.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.createTable('Students', {
id: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up (queryInterface, Sequelize) {

await queryInterface.addConstraint('students', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.createTable('Departments', {
department_id: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.createTable('Instructors', {
id: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.createTable('ProgramCourses', {
id: {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.addConstraint('programcourses', {
fields: ['parent_id'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up (queryInterface, Sequelize) {
/**
* Add altering commands here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up (queryInterface, Sequelize) {
/**
* Add altering commands here.
Expand Down Expand Up @@ -29,6 +29,6 @@ module.exports = {
* Example:
* await queryInterface.dropTable('users');
*/
await queryInterface.removeConstraint('Instructors', 'fk_head_department_id');
await queryInterface.removeConstraint('Departments', 'fk_head_department_id');
}
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up (queryInterface, Sequelize) {
await queryInterface.createTable('DepartmentInstructors', {
id: {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.addConstraint('ProgramCourses', {
fields: ['department_id'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up (queryInterface, Sequelize) {
/**
* Add altering commands here.
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Migrations/20250909013953-Semesters.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up (queryInterface, Sequelize) {
/**
* Add altering commands here.
Expand Down Expand Up @@ -77,7 +77,7 @@ module.exports = {
* await queryInterface.dropTable('users');
*/

await queryInterface.removeConstraint('Semester', 'uq_program_semester');
// await queryInterface.removeConstraint('Semester', 'uq_program_semester');
await queryInterface.dropTable('Semester')
}
};
5 changes: 2 additions & 3 deletions src/Database/seeders/20250805140906-demo-departments.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const department = require("../../api/Models/department");

module.exports = {
/** @type {import('sequelize-cli').Migration} */
export default{
async up(queryInterface, Sequelize) {
await queryInterface.bulkInsert('Departments', [
{
Expand Down
2 changes: 1 addition & 1 deletion src/Database/seeders/20250806125124-demo-instructors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
export default{
async up(queryInterface, Sequelize) {
await queryInterface.bulkInsert('Instructors', [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = {
/** @type {import('sequelize-cli').Migration} */
export default {
async up(queryInterface, Sequelize) {
// Fetch all instructors
const [instructors] = await queryInterface.sequelize.query(
Expand Down
4 changes: 2 additions & 2 deletions src/Database/seeders/20250809012319-demo-ProgramCourse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = {
/** @type {import('sequelize-cli').Migration} */
export default{
async up(queryInterface, Sequelize) {
// 1. Find the Computer Science department
const [csDept] = await queryInterface.sequelize.query(
Expand Down
Loading