replace sub_section to plant_sub_section

This commit is contained in:
Muhammad Afif
2025-10-24 10:31:27 +07:00
parent cec23e4777
commit 23f447188f
8 changed files with 23 additions and 23 deletions

View File

@@ -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;

View File

@@ -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]);