From 00706ca3ceca472f54769e45a7eb638529bfcebf Mon Sep 17 00:00:00 2001 From: agaes Date: Tue, 3 Feb 2026 11:59:28 +0800 Subject: [PATCH] refactor(program-api): clean up response and fix search filtering - Removed unnecessary `code` field from API response - Imported Sequelize `Op` to resolve search parameter filtering issues - Disabled model timestamps (timestamps: false) since migrations are not handled --- .gitignore | 1 + .../Controllers/ProgramCourseController.js | 4 ---- src/api/Models/programcourse.js | 2 +- src/api/Services/ProgramCourseServices.js | 22 +++++++++---------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 47a6c40..2a10195 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ package-lock.json node_modules/.package-lock.json node_modules/accepts/HISTORY.md .env +/.vs diff --git a/src/api/Controllers/ProgramCourseController.js b/src/api/Controllers/ProgramCourseController.js index 8e3e98f..e2ee35a 100644 --- a/src/api/Controllers/ProgramCourseController.js +++ b/src/api/Controllers/ProgramCourseController.js @@ -30,7 +30,6 @@ const getAllPrograms = async (req, res) => { let response = await ProgramService.SearchProgram(top, page,limit, search) return res.status(200).json({ - code:res.statusCode, response }) @@ -45,8 +44,6 @@ const updateProgram = async (req, res) => { const { message } = await ProgramService.updateProgram(req.body); res.status(200).json({ - code:200, - data: data, message }); } catch (err) { @@ -60,7 +57,6 @@ const deleteProgram = async (req, res) => { const { message } = await ProgramService.deleteProgram(req.params.id); return res.status(200).json({ - code: 200, message }); } catch (error) { diff --git a/src/api/Models/programcourse.js b/src/api/Models/programcourse.js index 9e09bbc..d269b95 100644 --- a/src/api/Models/programcourse.js +++ b/src/api/Models/programcourse.js @@ -49,7 +49,7 @@ export default (sequelize) => { { sequelize, modelName: 'ProgramCourse', - timestamps: true, + timestamps: false, } ); diff --git a/src/api/Services/ProgramCourseServices.js b/src/api/Services/ProgramCourseServices.js index 5b432d5..c067073 100644 --- a/src/api/Services/ProgramCourseServices.js +++ b/src/api/Services/ProgramCourseServices.js @@ -1,6 +1,6 @@ import path from 'path'; import { fileURLToPath } from 'url'; -import { DataTypes } from 'sequelize'; +import { DataTypes, Op } from 'sequelize'; import sequelize from '../../Config/db.js'; import ProgramCourseModelFactory from '../Models/programcourse.js'; @@ -98,8 +98,8 @@ const SearchProgram = async (top,page,limit,search) => { page = parseInt(page, 10); limit = parseInt(limit, 10); queryOptions.limit = limit; - queryOptions.offset = (page - 1) * limit; // ✅ fixed parseDecimal - } + queryOptions.offset = (page - 1) * limit; // ✅ fixed parseDecimal + } // Wildcard search if (search) { @@ -113,15 +113,15 @@ const SearchProgram = async (top,page,limit,search) => { }; } - const programs = await ProgramCourse.findAll(queryOptions); + const programs = await ProgramCourse.findAll(queryOptions); - return { - programs, - pagination: { - page: page || null, - limit: queryOptions.limit || null, - total: programs.length - } + return { + programs, + pagination: { + page: page || null, + limit: queryOptions.limit || null, + total: programs.length + } }; } catch (error) { throw error;