replace sub_section to plant_sub_section
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
@@ -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]);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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 {
|
||||
@@ -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",
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user