repair: notification error
This commit is contained in:
@@ -57,12 +57,20 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
||||
|
||||
await InsertNotificationErrorDb();
|
||||
|
||||
const boolFields = ["is_send", "is_delivered", "is_read", "is_active"];
|
||||
|
||||
boolFields.forEach((f) => {
|
||||
if (searchParams[f] !== undefined && searchParams[f] !== null && searchParams[f] !== "") {
|
||||
const v = searchParams[f];
|
||||
searchParams[f] = v == "1" ? 1 : v == "0" ? 0 : null;
|
||||
}
|
||||
});
|
||||
|
||||
if (searchParams.limit) {
|
||||
const page = Number(searchParams.page ?? 1) - 1;
|
||||
queryParams = [Number(searchParams.limit ?? 10), page];
|
||||
}
|
||||
|
||||
// Build dynamic WHERE OR
|
||||
const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike(
|
||||
[
|
||||
"b.error_code",
|
||||
@@ -71,26 +79,24 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
||||
"COALESCE(a.is_send, 0)",
|
||||
"COALESCE(a.is_delivered, 0)",
|
||||
"COALESCE(a.is_read, 0)",
|
||||
"COALESCE(a.is_active, 0)"
|
||||
"COALESCE(a.is_active, 0)",
|
||||
],
|
||||
searchParams.criteria,
|
||||
queryParams
|
||||
);
|
||||
if (whereParamOr) queryParams = whereParamOr;
|
||||
|
||||
// Build dynamic WHERE AND
|
||||
const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
|
||||
[
|
||||
{ column: "COALESCE(a.is_send, 0)", param: searchParams.is_send, 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" },
|
||||
{ column: "COALESCE(a.is_send, 0)", param: searchParams.is_send, type: "number" },
|
||||
{ column: "COALESCE(a.is_delivered, 0)", param: searchParams.is_delivered, type: "number" },
|
||||
{ column: "COALESCE(a.is_read, 0)", param: searchParams.is_read, type: "number" },
|
||||
{ column: "COALESCE(a.is_active, 0)", param: searchParams.is_active, type: "number" },
|
||||
],
|
||||
queryParams
|
||||
);
|
||||
if (whereParamAnd) queryParams = whereParamAnd;
|
||||
|
||||
|
||||
const queryText = `
|
||||
SELECT
|
||||
COUNT(*) OVER() AS total_data,
|
||||
@@ -117,25 +123,15 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
||||
COALESCE(d.device_name, '') + ' - ' + COALESCE(b.error_code_name, '') AS device_name_error
|
||||
|
||||
FROM notification_error a
|
||||
|
||||
LEFT JOIN brand_code b
|
||||
ON a.error_code_id = b.error_code_id
|
||||
AND b.deleted_at IS NULL
|
||||
|
||||
ON a.error_code_id = b.error_code_id AND b.deleted_at IS NULL
|
||||
LEFT JOIN brand_code_solution c
|
||||
ON b.error_code_id = c.error_code_id
|
||||
AND c.deleted_at IS NULL
|
||||
|
||||
ON b.error_code_id = c.error_code_id AND c.deleted_at IS NULL
|
||||
LEFT JOIN m_device d
|
||||
ON b.brand_id = d.brand_id
|
||||
AND d.deleted_at IS NULL
|
||||
ON b.brand_id = d.brand_id AND d.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}` : ""}
|
||||
|
||||
ORDER BY a.notification_error_id DESC
|
||||
@@ -153,6 +149,7 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
||||
return { data: result.recordset, total };
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
getNotificationByIdDb,
|
||||
getAllNotificationDb,
|
||||
Reference in New Issue
Block a user