Merge pull request 'wisdom' (#5) from wisdom into main

Reviewed-on: #5
This commit is contained in:
2025-10-24 03:35:12 +00:00
9 changed files with 29 additions and 29 deletions

View File

@@ -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 { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
const { insertSubSectionSchema, updateSubSectionSchema } = require('../validate/sub_section.schema'); const { insertSubSectionSchema, updateSubSectionSchema } = require('../validate/sub_section.schema');

View File

@@ -11,7 +11,7 @@ const getAllSubSectionsDb = async (searchParams = {}) => {
// OR condition (pencarian bebas) // OR condition (pencarian bebas)
const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike( 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, searchParams.criteria,
queryParams queryParams
); );
@@ -21,8 +21,8 @@ const getAllSubSectionsDb = async (searchParams = {}) => {
// AND condition (filter spesifik) // AND condition (filter spesifik)
const { whereConditions, whereParamAnd } = pool.buildFilterQuery( const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
[ [
{ column: "a.sub_section_code", param: searchParams.code, type: "string" }, { column: "a.plant_sub_section_code", param: searchParams.code, type: "string" },
{ column: "a.sub_section_name", param: searchParams.name, type: "string" }, { column: "a.plant_sub_section_name", param: searchParams.name, type: "string" },
], ],
queryParams queryParams
); );
@@ -36,7 +36,7 @@ const getAllSubSectionsDb = async (searchParams = {}) => {
WHERE a.deleted_at IS NULL WHERE a.deleted_at IS NULL
${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""} ${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""}
${whereOrConditions ? whereOrConditions : ""} ${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` : ''} ${searchParams.limit ? `OFFSET $2 * $1 ROWS FETCH NEXT $1 ROWS ONLY` : ''}
`; `;
@@ -54,7 +54,7 @@ const getSubSectionByIdDb = async (id) => {
const queryText = ` const queryText = `
SELECT a.* SELECT a.*
FROM m_plant_sub_section 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]); const result = await pool.query(queryText, [id]);
return result.recordset; return result.recordset;
@@ -63,11 +63,11 @@ const getSubSectionByIdDb = async (id) => {
// Create new sub section // Create new sub section
const createSubSectionDb = async (data) => { const createSubSectionDb = async (data) => {
// Generate kode otomatis // 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 = { const store = {
...data, ...data,
sub_section_code: newCode plant_sub_section_code: newCode
}; };
const { query: queryText, values } = pool.buildDynamicInsert("m_plant_sub_section", store); const { query: queryText, values } = pool.buildDynamicInsert("m_plant_sub_section", store);
@@ -80,7 +80,7 @@ const createSubSectionDb = async (data) => {
// Update sub section // Update sub section
const updateSubSectionDb = async (id, data) => { const updateSubSectionDb = async (id, data) => {
const store = { ...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); const { query: queryText, values } = pool.buildDynamicUpdate("m_plant_sub_section", store, whereData);
await pool.query(`${queryText} AND deleted_at IS NULL`, values); await pool.query(`${queryText} AND deleted_at IS NULL`, values);
@@ -93,7 +93,7 @@ const deleteSubSectionDb = async (id, deletedBy) => {
const queryText = ` const queryText = `
UPDATE m_plant_sub_section UPDATE m_plant_sub_section
SET deleted_at = CURRENT_TIMESTAMP, deleted_by = $1 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]); await pool.query(queryText, [deletedBy, id]);
return true; return true;

View File

@@ -17,7 +17,7 @@ const getAllTagsDb = async (searchParams = {}) => {
"a.data_type", "a.data_type",
"a.unit", "a.unit",
"b.device_name", "b.device_name",
"c.sub_section_name", "c.plant_sub_section_name",
], ],
searchParams.criteria, searchParams.criteria,
queryParams queryParams
@@ -38,7 +38,7 @@ const getAllTagsDb = async (searchParams = {}) => {
type: "string", type: "string",
}, },
{ {
column: "c.sub_section_name", column: "c.plant_sub_section_name",
param: searchParams.subsection, param: searchParams.subsection,
type: "string", type: "string",
}, },
@@ -54,10 +54,10 @@ const getAllTagsDb = async (searchParams = {}) => {
a.*, a.*,
b.device_name, b.device_name,
b.device_code, b.device_code,
c.sub_section_name c.plant_sub_section_name
FROM m_tags a FROM m_tags a
LEFT JOIN m_device b ON a.device_id = b.device_id 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 WHERE a.deleted_at IS NULL
${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""} ${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""}
${whereOrConditions ? ` ${whereOrConditions}` : ""} ${whereOrConditions ? ` ${whereOrConditions}` : ""}
@@ -81,10 +81,10 @@ const getTagsByIdDb = async (id) => {
a.*, a.*,
b.device_name, b.device_name,
b.device_code, b.device_code,
c.sub_section_name c.plant_sub_section_name
FROM m_tags a FROM m_tags a
LEFT JOIN m_device b ON a.device_id = b.device_id 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 WHERE a.tag_id = $1 AND a.deleted_at IS NULL
`; `;
const result = await pool.query(queryText, [id]); const result = await pool.query(queryText, [id]);

View File

@@ -37,9 +37,9 @@ const getAllUserScheduleDb = async (searchParams = {}) => {
c.end_time, c.end_time,
d.user_fullname d.user_fullname
FROM user_schedule a FROM user_schedule a
LEFT JOIN schedule b ON a.user_schedule_id = b.schedule_id LEFT JOIN schedule b ON a.schedule_id = b.schedule_id
LEFT JOIN m_shift c ON a.user_schedule_id = c.shift_id LEFT JOIN m_shift c ON a.shift_id = c.shift_id
LEFT JOIN m_users d ON a.user_schedule_id = d.user_id LEFT JOIN m_users d ON a.user_id = d.user_id
WHERE a.deleted_at IS NULL WHERE a.deleted_at IS NULL
${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""} ${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""}
${whereOrConditions ? ` ${whereOrConditions}` : ""} ${whereOrConditions ? ` ${whereOrConditions}` : ""}
@@ -66,9 +66,9 @@ const getUserScheduleByIdDb = async (id) => {
c.end_time, c.end_time,
d.user_fullname d.user_fullname
FROM user_schedule a FROM user_schedule a
LEFT JOIN schedule b ON a.user_schedule_id = b.schedule_id LEFT JOIN schedule b ON a.schedule_id = b.schedule_id
LEFT JOIN m_shift c ON a.user_schedule_id = c.shift_id LEFT JOIN m_shift c ON a.shift_id = c.shift_id
LEFT JOIN m_users d ON a.user_schedule_id = d.user_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 WHERE a.user_schedule_id = $1 AND a.deleted_at IS NULL
`; `;
const result = await pool.query(queryText, [id]); const result = await pool.query(queryText, [id]);

View File

@@ -4,7 +4,7 @@ const users = require("./users.route");
const device = require('./device.route'); const device = require('./device.route');
const roles = require('./roles.route'); const roles = require('./roles.route');
const tags = require("./tags.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 shift = require("./shift.route");
const schedule = require("./schedule.route"); const schedule = require("./schedule.route");
const status = require("./status.route"); const status = require("./status.route");

View File

@@ -1,5 +1,5 @@
const express = require('express'); 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 verifyToken = require('../middleware/verifyToken');
const verifyAccess = require('../middleware/verifyAccess'); const verifyAccess = require('../middleware/verifyAccess');

View File

@@ -4,7 +4,7 @@ const {
createSubSectionDb, createSubSectionDb,
updateSubSectionDb, updateSubSectionDb,
deleteSubSectionDb deleteSubSectionDb
} = require('../db/sub_section.db'); } = require('../db/plant_sub_section.db');
const { ErrorHandler } = require('../helpers/error'); const { ErrorHandler } = require('../helpers/error');
class SubSectionService { class SubSectionService {

View File

@@ -4,7 +4,7 @@ const Joi = require("joi");
// Plant Sub Section Validation // Plant Sub Section Validation
// ======================== // ========================
const insertSubSectionSchema = Joi.object({ const insertSubSectionSchema = Joi.object({
sub_section_name: Joi.string() plant_sub_section_name: Joi.string()
.max(200) .max(200)
.required() .required()
.messages({ .messages({
@@ -17,7 +17,7 @@ const insertSubSectionSchema = Joi.object({
}); });
const updateSubSectionSchema = Joi.object({ const updateSubSectionSchema = Joi.object({
sub_section_name: Joi.string() plant_sub_section_namesub_section_name: Joi.string()
.max(200) .max(200)
.messages({ .messages({
"string.base": "Sub section name must be a string", "string.base": "Sub section name must be a string",

View File

@@ -11,7 +11,7 @@ const insertTagsSchema = Joi.object({
is_active: Joi.boolean().optional(), is_active: Joi.boolean().optional(),
data_type: Joi.string().max(50).optional(), data_type: Joi.string().max(50).optional(),
unit: 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_alarm: Joi.boolean().optional(),
is_report: Joi.boolean().optional(), is_report: Joi.boolean().optional(),
is_history: Joi.boolean().optional(), is_history: Joi.boolean().optional(),
@@ -29,7 +29,7 @@ const updateTagsSchema = Joi.object({
data_type: Joi.string().max(50), data_type: Joi.string().max(50),
unit: Joi.string().max(50), unit: Joi.string().max(50),
is_alarm: Joi.boolean().optional(), is_alarm: Joi.boolean().optional(),
sub_section_id: Joi.number().optional(), plant_sub_section_id: Joi.number().optional(),
is_report: Joi.boolean().optional(), is_report: Joi.boolean().optional(),
is_history: Joi.boolean().optional(), is_history: Joi.boolean().optional(),
lim_low_crash: Joi.number().optional(), lim_low_crash: Joi.number().optional(),