repair: update is read in notification error
This commit is contained in:
@@ -10,10 +10,7 @@ const getAllNotificationErrorUserDb = async (searchParams = {}) => {
|
||||
}
|
||||
|
||||
const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike(
|
||||
[
|
||||
"a.notification_error_id",
|
||||
"a.contact_id",
|
||||
],
|
||||
["a.notification_error_id", "a.contact_id"],
|
||||
searchParams.criteria,
|
||||
queryParams
|
||||
);
|
||||
@@ -22,7 +19,11 @@ const getAllNotificationErrorUserDb = async (searchParams = {}) => {
|
||||
|
||||
const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
|
||||
[
|
||||
{ column: "a.notification_error_id", param: searchParams.name, type: "int" },
|
||||
{
|
||||
column: "a.notification_error_id",
|
||||
param: searchParams.name,
|
||||
type: "int",
|
||||
},
|
||||
{ column: "a.contact_id", param: searchParams.code, type: "int" },
|
||||
],
|
||||
queryParams
|
||||
@@ -36,10 +37,14 @@ const getAllNotificationErrorUserDb = async (searchParams = {}) => {
|
||||
a.*
|
||||
FROM notification_error_user a
|
||||
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_user_id ASC
|
||||
${searchParams.limit ? `OFFSET $2 * $1 ROWS FETCH NEXT $1 ROWS ONLY` : ''}
|
||||
${searchParams.limit ? `OFFSET $2 * $1 ROWS FETCH NEXT $1 ROWS ONLY` : ""}
|
||||
`;
|
||||
|
||||
const result = await pool.query(queryText, queryParams);
|
||||
@@ -66,8 +71,27 @@ const getNotificationErrorUserByIdDb = async (id) => {
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
const getNotificationErrorByIdDb = async (notification_error_id) => {
|
||||
const queryText = `
|
||||
SELECT
|
||||
a.*,
|
||||
b. is_active as contact_is_active,
|
||||
c.is_read
|
||||
|
||||
FROM notification_error_user a
|
||||
LEFT JOIN contact b ON a.contact_phone = b.contact_phone
|
||||
LEFT JOIN notification_error c ON a.notification_error_id = c.notification_error_id
|
||||
WHERE a.notification_error_id = $1 AND a.deleted_at IS NULL
|
||||
`;
|
||||
const result = await pool.query(queryText, [notification_error_id]);
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
const createNotificationErrorUserDb = async (store) => {
|
||||
const { query: queryText, values } = pool.buildDynamicInsert("notification_error_user", store);
|
||||
const { query: queryText, values } = pool.buildDynamicInsert(
|
||||
"notification_error_user",
|
||||
store
|
||||
);
|
||||
const result = await pool.query(queryText, values);
|
||||
const insertedId = result.recordset?.[0]?.inserted_id;
|
||||
|
||||
@@ -85,7 +109,7 @@ const updateNotificationErrorUserDb = async (id, data) => {
|
||||
);
|
||||
|
||||
await pool.query(`${queryText} AND deleted_at IS NULL`, values);
|
||||
return getNotificationErrorUserByIdDb(id);
|
||||
return getNotificationErrorUserByIdDb(id);
|
||||
};
|
||||
|
||||
// Soft delete tag
|
||||
@@ -102,6 +126,7 @@ const deleteNotificationErrorUserDb = async (id, deletedBy) => {
|
||||
module.exports = {
|
||||
getAllNotificationErrorUserDb,
|
||||
getNotificationErrorUserByIdDb,
|
||||
getNotificationErrorByIdDb,
|
||||
createNotificationErrorUserDb,
|
||||
updateNotificationErrorUserDb,
|
||||
deleteNotificationErrorUserDb,
|
||||
|
||||
Reference in New Issue
Block a user