diff --git a/src/Database/Migrations/20260203134809-add-timestamps-in-program.js b/src/Database/Migrations/20260203134809-add-timestamps-in-program.js new file mode 100644 index 0000000..323adf9 --- /dev/null +++ b/src/Database/Migrations/20260203134809-add-timestamps-in-program.js @@ -0,0 +1,38 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +export default{ + async up (queryInterface, Sequelize) { + /** + * Add altering commands here. + * + * Example: + * await queryInterface.createTable('users', { id: Sequelize.INTEGER }); + */ + + await queryInterface.addColumn('ProgramCourses', 'createdAt', { + allowNull: false, + type: Sequelize.DATE, + defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') + }); + + await queryInterface.addColumn('ProgramCourses', 'updatedAt', { + allowNull: false, + type: Sequelize.DATE, + defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), + }); + + }, + + async down (queryInterface, Sequelize) { + /** + * Add reverting commands here. + * + * Example: + * await queryInterface.dropTable('users'); + */ + + await queryInterface.removeColumn('ProgramCourses','createdAt'); + await queryInterface.removeColumn('ProgramCourses', 'updatedAt') + } +}; diff --git a/src/api/Models/programcourse.js b/src/api/Models/programcourse.js index d269b95..9e09bbc 100644 --- a/src/api/Models/programcourse.js +++ b/src/api/Models/programcourse.js @@ -49,7 +49,7 @@ export default (sequelize) => { { sequelize, modelName: 'ProgramCourse', - timestamps: false, + timestamps: true, } ); diff --git a/src/api/Services/ProgramCourseServices.js b/src/api/Services/ProgramCourseServices.js index c067073..7ce43ea 100644 --- a/src/api/Services/ProgramCourseServices.js +++ b/src/api/Services/ProgramCourseServices.js @@ -86,20 +86,15 @@ const updateProgram = async (programData) => { const SearchProgram = async (top,page,limit,search) => { try { - const queryOptions = { - where: { type: "PROGRAM" }, - // order: [["createdAt", "DESC"]], - }; - - // Pagination - if (top) { - queryOptions.limit = parseInt(top, 10); - } else if (page && limit) { - page = parseInt(page, 10); - limit = parseInt(limit, 10); - queryOptions.limit = limit; - queryOptions.offset = (page - 1) * limit; // ✅ fixed parseDecimal - } + page = parseInt(page, 10) || 1; + limit = parseInt(limit, 10) || 10; + + const queryOptions = { + where: { type: "PROGRAM" }, + limit, + offset: (page - 1) * limit, // pagination + order: [["createdAt", "DESC"]], // optional ordering + }; // Wildcard search if (search) { @@ -120,7 +115,6 @@ const SearchProgram = async (top,page,limit,search) => { pagination: { page: page || null, limit: queryOptions.limit || null, - total: programs.length } }; } catch (error) {