From f6b29bb80e16c890ab9e54baa1555fe750d8eecd Mon Sep 17 00:00:00 2001 From: Muhammad Afif Date: Thu, 23 Oct 2025 12:37:14 +0700 Subject: [PATCH 1/3] repair: query user_schedule db --- db/user_schedule.db.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/user_schedule.db.js b/db/user_schedule.db.js index 525fd61..8275fb3 100644 --- a/db/user_schedule.db.js +++ b/db/user_schedule.db.js @@ -66,9 +66,9 @@ const getUserScheduleByIdDb = async (id) => { c.end_time, d.user_fullname FROM user_schedule a - LEFT JOIN schedule b ON a.user_schedule_id = b.schedule_id - LEFT JOIN m_shift c ON a.user_schedule_id = c.shift_id - LEFT JOIN m_users d ON a.user_schedule_id = d.user_id + LEFT JOIN schedule b ON a.schedule_id = b.schedule_id + LEFT JOIN m_shift c ON a.shift_id = c.shift_id + LEFT JOIN m_users d ON a.user_id = d.user_id WHERE a.user_schedule_id = $1 AND a.deleted_at IS NULL `; const result = await pool.query(queryText, [id]); From cec23e47777e18b1d679e3c116c893bc360c5396 Mon Sep 17 00:00:00 2001 From: Muhammad Afif Date: Thu, 23 Oct 2025 12:39:29 +0700 Subject: [PATCH 2/3] repair: query user_schedule db --- db/user_schedule.db.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/user_schedule.db.js b/db/user_schedule.db.js index 8275fb3..3305ff7 100644 --- a/db/user_schedule.db.js +++ b/db/user_schedule.db.js @@ -37,9 +37,9 @@ const getAllUserScheduleDb = async (searchParams = {}) => { c.end_time, d.user_fullname FROM user_schedule a - LEFT JOIN schedule b ON a.user_schedule_id = b.schedule_id - LEFT JOIN m_shift c ON a.user_schedule_id = c.shift_id - LEFT JOIN m_users d ON a.user_schedule_id = d.user_id + LEFT JOIN schedule b ON a.schedule_id = b.schedule_id + LEFT JOIN m_shift c ON a.shift_id = c.shift_id + LEFT JOIN m_users d ON a.user_id = d.user_id WHERE a.deleted_at IS NULL ${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""} ${whereOrConditions ? ` ${whereOrConditions}` : ""} From 23f447188f7d3caf94c388a32e427c4028b62c3f Mon Sep 17 00:00:00 2001 From: Muhammad Afif Date: Fri, 24 Oct 2025 10:31:27 +0700 Subject: [PATCH 3/3] replace sub_section to plant_sub_section --- ...ller.js => plant_sub_section.controller.js} | 2 +- ...b_section.db.js => plant_sub_section.db.js} | 18 +++++++++--------- db/tags.db.js | 12 ++++++------ routes/index.js | 2 +- ...ion.route.js => plant_sub_section.route.js} | 2 +- ...service.js => plant_sub_section.service.js} | 2 +- validate/sub_section.schema.js | 4 ++-- validate/tags.schema.js | 4 ++-- 8 files changed, 23 insertions(+), 23 deletions(-) rename controllers/{sub_section.controller.js => plant_sub_section.controller.js} (96%) rename db/{sub_section.db.js => plant_sub_section.db.js} (83%) rename routes/{sub_section.route.js => plant_sub_section.route.js} (88%) rename services/{sub_section.service.js => plant_sub_section.service.js} (97%) diff --git a/controllers/sub_section.controller.js b/controllers/plant_sub_section.controller.js similarity index 96% rename from controllers/sub_section.controller.js rename to controllers/plant_sub_section.controller.js index f2a9655..e175307 100644 --- a/controllers/sub_section.controller.js +++ b/controllers/plant_sub_section.controller.js @@ -1,4 +1,4 @@ -const SubSectionService = require('../services/sub_section.service'); +const SubSectionService = require('../services/plant_sub_section.service'); const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils'); const { insertSubSectionSchema, updateSubSectionSchema } = require('../validate/sub_section.schema'); diff --git a/db/sub_section.db.js b/db/plant_sub_section.db.js similarity index 83% rename from db/sub_section.db.js rename to db/plant_sub_section.db.js index 8d40e90..98980b4 100644 --- a/db/sub_section.db.js +++ b/db/plant_sub_section.db.js @@ -11,7 +11,7 @@ const getAllSubSectionsDb = async (searchParams = {}) => { // OR condition (pencarian bebas) const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike( - ["a.sub_section_code", "a.sub_section_name"], + ["a.plant_sub_section_code", "a.plant_sub_section_name"], searchParams.criteria, queryParams ); @@ -21,8 +21,8 @@ const getAllSubSectionsDb = async (searchParams = {}) => { // AND condition (filter spesifik) const { whereConditions, whereParamAnd } = pool.buildFilterQuery( [ - { column: "a.sub_section_code", param: searchParams.code, type: "string" }, - { column: "a.sub_section_name", param: searchParams.name, type: "string" }, + { column: "a.plant_sub_section_code", param: searchParams.code, type: "string" }, + { column: "a.plant_sub_section_name", param: searchParams.name, type: "string" }, ], queryParams ); @@ -36,7 +36,7 @@ const getAllSubSectionsDb = async (searchParams = {}) => { WHERE a.deleted_at IS NULL ${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""} ${whereOrConditions ? whereOrConditions : ""} - ORDER BY a.sub_section_id ASC + ORDER BY a.plant_sub_section_id ASC ${searchParams.limit ? `OFFSET $2 * $1 ROWS FETCH NEXT $1 ROWS ONLY` : ''} `; @@ -54,7 +54,7 @@ const getSubSectionByIdDb = async (id) => { const queryText = ` SELECT a.* FROM m_plant_sub_section a - WHERE a.sub_section_id = $1 AND a.deleted_at IS NULL + WHERE a.plant_sub_section_id = $1 AND a.deleted_at IS NULL `; const result = await pool.query(queryText, [id]); return result.recordset; @@ -63,11 +63,11 @@ const getSubSectionByIdDb = async (id) => { // Create new sub section const createSubSectionDb = async (data) => { // Generate kode otomatis - const newCode = await pool.generateKode("SUB", "m_plant_sub_section", "sub_section_code"); + const newCode = await pool.generateKode("SUB", "m_plant_sub_section", "plant_sub_section_code"); const store = { ...data, - sub_section_code: newCode + plant_sub_section_code: newCode }; const { query: queryText, values } = pool.buildDynamicInsert("m_plant_sub_section", store); @@ -80,7 +80,7 @@ const createSubSectionDb = async (data) => { // Update sub section const updateSubSectionDb = async (id, data) => { const store = { ...data }; - const whereData = { sub_section_id: id }; + const whereData = { plant_sub_section_id: id }; const { query: queryText, values } = pool.buildDynamicUpdate("m_plant_sub_section", store, whereData); await pool.query(`${queryText} AND deleted_at IS NULL`, values); @@ -93,7 +93,7 @@ const deleteSubSectionDb = async (id, deletedBy) => { const queryText = ` UPDATE m_plant_sub_section SET deleted_at = CURRENT_TIMESTAMP, deleted_by = $1 - WHERE sub_section_id = $2 AND deleted_at IS NULL + WHERE plant_sub_section_id = $2 AND deleted_at IS NULL `; await pool.query(queryText, [deletedBy, id]); return true; diff --git a/db/tags.db.js b/db/tags.db.js index 9f47031..8518c2f 100644 --- a/db/tags.db.js +++ b/db/tags.db.js @@ -17,7 +17,7 @@ const getAllTagsDb = async (searchParams = {}) => { "a.data_type", "a.unit", "b.device_name", - "c.sub_section_name", + "c.plant_sub_section_name", ], searchParams.criteria, queryParams @@ -38,7 +38,7 @@ const getAllTagsDb = async (searchParams = {}) => { type: "string", }, { - column: "c.sub_section_name", + column: "c.plant_sub_section_name", param: searchParams.subsection, type: "string", }, @@ -54,10 +54,10 @@ const getAllTagsDb = async (searchParams = {}) => { a.*, b.device_name, b.device_code, - c.sub_section_name + c.plant_sub_section_name FROM m_tags a LEFT JOIN m_device b ON a.device_id = b.device_id - LEFT JOIN m_plant_sub_section c ON a.sub_section_id = c.sub_section_id + LEFT JOIN m_plant_sub_section c ON a.plant_sub_section_id = c.plant_sub_section_id WHERE a.deleted_at IS NULL ${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""} ${whereOrConditions ? ` ${whereOrConditions}` : ""} @@ -81,10 +81,10 @@ const getTagsByIdDb = async (id) => { a.*, b.device_name, b.device_code, - c.sub_section_name + c.plant_sub_section_name FROM m_tags a LEFT JOIN m_device b ON a.device_id = b.device_id - LEFT JOIN m_plant_sub_section c ON a.sub_section_id = c.sub_section_id + LEFT JOIN m_plant_sub_section c ON a.plant_sub_section_id = c.plant_sub_section_id WHERE a.tag_id = $1 AND a.deleted_at IS NULL `; const result = await pool.query(queryText, [id]); diff --git a/routes/index.js b/routes/index.js index 25881e1..a5360a3 100644 --- a/routes/index.js +++ b/routes/index.js @@ -4,7 +4,7 @@ const users = require("./users.route"); const device = require('./device.route'); const roles = require('./roles.route'); const tags = require("./tags.route"); -const subSection = require("./sub_section.route"); +const subSection = require("./plant_sub_section.route"); const shift = require("./shift.route"); const schedule = require("./schedule.route"); const status = require("./status.route"); diff --git a/routes/sub_section.route.js b/routes/plant_sub_section.route.js similarity index 88% rename from routes/sub_section.route.js rename to routes/plant_sub_section.route.js index 58adde9..1caa49e 100644 --- a/routes/sub_section.route.js +++ b/routes/plant_sub_section.route.js @@ -1,5 +1,5 @@ const express = require('express'); -const PlantSubSectionController = require('../controllers/sub_section.controller'); +const PlantSubSectionController = require('../controllers/plant_sub_section.controller'); const verifyToken = require('../middleware/verifyToken'); const verifyAccess = require('../middleware/verifyAccess'); diff --git a/services/sub_section.service.js b/services/plant_sub_section.service.js similarity index 97% rename from services/sub_section.service.js rename to services/plant_sub_section.service.js index 8860bfd..a0e2302 100644 --- a/services/sub_section.service.js +++ b/services/plant_sub_section.service.js @@ -4,7 +4,7 @@ const { createSubSectionDb, updateSubSectionDb, deleteSubSectionDb -} = require('../db/sub_section.db'); +} = require('../db/plant_sub_section.db'); const { ErrorHandler } = require('../helpers/error'); class SubSectionService { diff --git a/validate/sub_section.schema.js b/validate/sub_section.schema.js index 991f993..1eac3ea 100644 --- a/validate/sub_section.schema.js +++ b/validate/sub_section.schema.js @@ -4,7 +4,7 @@ const Joi = require("joi"); // Plant Sub Section Validation // ======================== const insertSubSectionSchema = Joi.object({ - sub_section_name: Joi.string() + plant_sub_section_name: Joi.string() .max(200) .required() .messages({ @@ -17,7 +17,7 @@ const insertSubSectionSchema = Joi.object({ }); const updateSubSectionSchema = Joi.object({ - sub_section_name: Joi.string() + plant_sub_section_namesub_section_name: Joi.string() .max(200) .messages({ "string.base": "Sub section name must be a string", diff --git a/validate/tags.schema.js b/validate/tags.schema.js index 81ef917..e3ccf50 100644 --- a/validate/tags.schema.js +++ b/validate/tags.schema.js @@ -11,7 +11,7 @@ const insertTagsSchema = Joi.object({ is_active: Joi.boolean().optional(), data_type: Joi.string().max(50).optional(), unit: Joi.string().max(50).optional(), - sub_section_id: Joi.number().optional(), + plant_sub_section_id: Joi.number().optional(), is_alarm: Joi.boolean().optional(), is_report: Joi.boolean().optional(), is_history: Joi.boolean().optional(), @@ -29,7 +29,7 @@ const updateTagsSchema = Joi.object({ data_type: Joi.string().max(50), unit: Joi.string().max(50), is_alarm: Joi.boolean().optional(), - sub_section_id: Joi.number().optional(), + plant_sub_section_id: Joi.number().optional(), is_report: Joi.boolean().optional(), is_history: Joi.boolean().optional(), lim_low_crash: Joi.number().optional(),