repair: message_error_issue
This commit is contained in:
@@ -10,7 +10,7 @@ class NotificationController {
|
|||||||
const response = await setResponsePaging(queryParams, results, 'Notification list retrieved successfully');
|
const response = await setResponsePaging(queryParams, results, 'Notification list retrieved successfully');
|
||||||
return res.status(response.statusCode).json(response);
|
return res.status(response.statusCode).json(response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ [getAll] Notification Error:", err.message);
|
console.error("Notification Error:", err.message);
|
||||||
return res.status(500).json(setResponse(err, 'Failed to fetch notifications', 500));
|
return res.status(500).json(setResponse(err, 'Failed to fetch notifications', 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ class NotificationController {
|
|||||||
const response = await setResponse(results, 'Notification retrieved successfully');
|
const response = await setResponse(results, 'Notification retrieved successfully');
|
||||||
return res.status(response.statusCode).json(response);
|
return res.status(response.statusCode).json(response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ [getById] Notification Error:", err.message);
|
console.error(" Notification Error:", err.message);
|
||||||
return res.status(500).json(setResponse(err, 'Failed to fetch notification', 500));
|
return res.status(500).json(setResponse(err, 'Failed to fetch notification', 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ class NotificationController {
|
|||||||
const response = await setResponse(results, 'Notification created successfully');
|
const response = await setResponse(results, 'Notification created successfully');
|
||||||
return res.status(response.statusCode).json(response);
|
return res.status(response.statusCode).json(response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ [create] Notification Error:", err.message);
|
console.error("Notification Error:", err.message);
|
||||||
return res.status(500).json(setResponse(err, 'Failed to create notification', 500));
|
return res.status(500).json(setResponse(err, 'Failed to create notification', 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ class NotificationController {
|
|||||||
const response = await setResponse(results, 'Notification updated successfully');
|
const response = await setResponse(results, 'Notification updated successfully');
|
||||||
return res.status(response.statusCode).json(response);
|
return res.status(response.statusCode).json(response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ [update] Notification Error:", err.message);
|
console.error("Notification Error:", err.message);
|
||||||
return res.status(500).json(setResponse(err, 'Failed to update notification', 500));
|
return res.status(500).json(setResponse(err, 'Failed to update notification', 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ class NotificationController {
|
|||||||
const response = await setResponse(results, 'Notification deleted successfully');
|
const response = await setResponse(results, 'Notification deleted successfully');
|
||||||
return res.status(response.statusCode).json(response);
|
return res.status(response.statusCode).json(response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ [delete] Notification Error:", err.message);
|
console.error("Notification Error:", err.message);
|
||||||
return res.status(500).json(setResponse(err, 'Failed to delete notification', 500));
|
return res.status(500).json(setResponse(err, 'Failed to delete notification', 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,24 +16,34 @@ const InsertNotificationErrorDb = async () => {
|
|||||||
1 AS is_delivered,
|
1 AS is_delivered,
|
||||||
0 AS is_read,
|
0 AS is_read,
|
||||||
1 AS is_send,
|
1 AS is_send,
|
||||||
COALESCE(b.error_code_description, '') AS message_error_issue
|
CONCAT(
|
||||||
|
COALESCE(b.error_code_description, '-'),
|
||||||
|
' pada ',
|
||||||
|
COALESCE(d.plant_sub_section_name, '-'),
|
||||||
|
'. Pengecekan potensi kerusakan dibutuhkan'
|
||||||
|
) AS message_error_issue
|
||||||
FROM brand_code b
|
FROM brand_code b
|
||||||
|
|
||||||
|
CROSS JOIN m_plant_sub_section d
|
||||||
|
|
||||||
LEFT JOIN notification_error ne
|
LEFT JOIN notification_error ne
|
||||||
ON ne.error_code_id = b.error_code_id
|
ON ne.error_code_id = b.error_code_id
|
||||||
AND ne.deleted_at IS NULL
|
AND ne.deleted_at IS NULL
|
||||||
LEFT JOIN brand_code_solution c
|
|
||||||
ON c.error_code_id = b.error_code_id
|
|
||||||
AND c.deleted_at IS NULL
|
|
||||||
WHERE b.deleted_at IS NULL
|
WHERE b.deleted_at IS NULL
|
||||||
|
AND d.deleted_at IS NULL
|
||||||
AND ne.notification_error_id IS NULL
|
AND ne.notification_error_id IS NULL
|
||||||
`;
|
`;
|
||||||
|
|
||||||
await pool.query(insertQuery);
|
await pool.query(insertQuery);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const getAllNotificationDb = async (searchParams = {}) => {
|
const getAllNotificationDb = async (searchParams = {}) => {
|
||||||
let queryParams = [];
|
let queryParams = [];
|
||||||
|
|
||||||
|
// Tambahkan data baru jika belum ada
|
||||||
await InsertNotificationErrorDb();
|
await InsertNotificationErrorDb();
|
||||||
|
|
||||||
if (searchParams.limit) {
|
if (searchParams.limit) {
|
||||||
@@ -41,6 +51,7 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
|||||||
queryParams = [Number(searchParams.limit ?? 10), page];
|
queryParams = [Number(searchParams.limit ?? 10), page];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build dynamic WHERE OR
|
||||||
const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike(
|
const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike(
|
||||||
[
|
[
|
||||||
"b.error_code",
|
"b.error_code",
|
||||||
@@ -49,69 +60,55 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
|||||||
"COALESCE(a.is_send, 0)",
|
"COALESCE(a.is_send, 0)",
|
||||||
"COALESCE(a.is_delivered, 0)",
|
"COALESCE(a.is_delivered, 0)",
|
||||||
"COALESCE(a.is_read, 0)",
|
"COALESCE(a.is_read, 0)",
|
||||||
"COALESCE(a.is_active, 0)",
|
"COALESCE(a.is_active, 0)"
|
||||||
],
|
],
|
||||||
searchParams.criteria,
|
searchParams.criteria,
|
||||||
queryParams
|
queryParams
|
||||||
);
|
);
|
||||||
if (whereParamOr) queryParams = whereParamOr;
|
if (whereParamOr) queryParams = whereParamOr;
|
||||||
|
|
||||||
|
// Build dynamic WHERE AND
|
||||||
const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
|
const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
|
||||||
[
|
[
|
||||||
{
|
{ column: "COALESCE(a.is_send, 0)", param: searchParams.is_send, type: "int" },
|
||||||
column: "COALESCE(a.is_send, 0)",
|
{ column: "COALESCE(a.is_delivered, 0)", param: searchParams.is_delivered, type: "int" },
|
||||||
param: searchParams.is_send,
|
{ column: "COALESCE(a.is_read, 0)", param: searchParams.is_read, type: "int" },
|
||||||
type: "int",
|
{ column: "COALESCE(a.is_active, 0)", param: searchParams.is_active, type: "int" },
|
||||||
},
|
|
||||||
{
|
|
||||||
column: "COALESCE(a.is_delivered, 0)",
|
|
||||||
param: searchParams.is_delivered,
|
|
||||||
type: "int",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
column: "COALESCE(a.is_read, 0)",
|
|
||||||
param: searchParams.is_read,
|
|
||||||
type: "int",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
column: "COALESCE(a.is_active, 0)",
|
|
||||||
param: searchParams.is_active,
|
|
||||||
type: "int",
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
queryParams
|
queryParams
|
||||||
);
|
);
|
||||||
if (whereParamAnd) queryParams = whereParamAnd;
|
if (whereParamAnd) queryParams = whereParamAnd;
|
||||||
|
|
||||||
|
|
||||||
const queryText = `
|
const queryText = `
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) OVER() AS total_data,
|
COUNT(*) OVER() AS total_data,
|
||||||
|
|
||||||
a.notification_error_id,
|
a.*,
|
||||||
COALESCE(a.is_send, 0) AS is_send,
|
|
||||||
COALESCE(a.is_delivered, 0) AS is_delivered,
|
|
||||||
COALESCE(a.is_read, 0) AS is_read,
|
|
||||||
COALESCE(a.is_active, 0) AS is_active,
|
|
||||||
a.message_error_issue,
|
|
||||||
|
|
||||||
b.error_code_id,
|
|
||||||
b.error_code,
|
b.error_code,
|
||||||
b.error_code_name,
|
b.error_code_name,
|
||||||
|
|
||||||
c.solution_name,
|
c.solution_name,
|
||||||
c.type_solution,
|
c.type_solution,
|
||||||
c.path_solution
|
c.path_solution,
|
||||||
|
|
||||||
FROM brand_code b
|
d.plant_sub_section_name,
|
||||||
LEFT JOIN notification_error a
|
e.device_location
|
||||||
|
|
||||||
|
FROM notification_error a
|
||||||
|
LEFT JOIN brand_code b
|
||||||
ON a.error_code_id = b.error_code_id
|
ON a.error_code_id = b.error_code_id
|
||||||
AND a.deleted_at IS NULL
|
AND b.deleted_at IS NULL
|
||||||
|
|
||||||
LEFT JOIN brand_code_solution c
|
LEFT JOIN brand_code_solution c
|
||||||
ON b.error_code_id = c.error_code_id
|
ON b.error_code_id = c.error_code_id
|
||||||
AND c.deleted_at IS NULL
|
AND c.deleted_at IS NULL
|
||||||
|
|
||||||
WHERE b.deleted_at IS NULL
|
CROSS JOIN m_plant_sub_section d
|
||||||
|
|
||||||
|
CROSS JOIN m_device e
|
||||||
|
|
||||||
|
WHERE a.deleted_at IS NULL
|
||||||
${
|
${
|
||||||
whereConditions.length > 0
|
whereConditions.length > 0
|
||||||
? ` AND ${whereConditions.join(" AND ")}`
|
? ` AND ${whereConditions.join(" AND ")}`
|
||||||
@@ -119,7 +116,7 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
|||||||
}
|
}
|
||||||
${whereOrConditions ? ` ${whereOrConditions}` : ""}
|
${whereOrConditions ? ` ${whereOrConditions}` : ""}
|
||||||
|
|
||||||
ORDER BY b.error_code_id ASC
|
ORDER BY a.notification_error_id DESC
|
||||||
|
|
||||||
${searchParams.limit ? `OFFSET $2 * $1 ROWS FETCH NEXT $1 ROWS ONLY` : ""}
|
${searchParams.limit ? `OFFSET $2 * $1 ROWS FETCH NEXT $1 ROWS ONLY` : ""}
|
||||||
`;
|
`;
|
||||||
@@ -127,7 +124,9 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
|||||||
const result = await pool.query(queryText, queryParams);
|
const result = await pool.query(queryText, queryParams);
|
||||||
|
|
||||||
const total =
|
const total =
|
||||||
result.recordset?.length > 0 ? Number(result.recordset[0].total_data) : 0;
|
result?.recordset?.length > 0
|
||||||
|
? parseInt(result.recordset[0].total_data, 10)
|
||||||
|
: 0;
|
||||||
|
|
||||||
return { data: result.recordset, total };
|
return { data: result.recordset, total };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user