add: add notification
This commit is contained in:
@@ -1,44 +1,14 @@
|
||||
const pool = require("../config");
|
||||
|
||||
const InsertNotificationErrorDb = async () => {
|
||||
const insertQuery = `
|
||||
INSERT INTO notification_error (
|
||||
error_code_id,
|
||||
is_active,
|
||||
is_delivered,
|
||||
is_read,
|
||||
is_send,
|
||||
message_error_issue
|
||||
)
|
||||
SELECT
|
||||
b.error_code_id,
|
||||
1 AS is_active,
|
||||
1 AS is_delivered,
|
||||
0 AS is_read,
|
||||
1 AS is_send,
|
||||
const InsertNotificationErrorDb = async (store) => {
|
||||
const { query: queryText, values } = pool.buildDynamicInsert(
|
||||
"notification_error",
|
||||
store
|
||||
);
|
||||
const result = await pool.query(queryText, values);
|
||||
const insertedId = result.recordset?.[0]?.inserted_id;
|
||||
|
||||
CONCAT(
|
||||
COALESCE(b.error_code_name, '-'),
|
||||
' pada ',
|
||||
COALESCE(d.device_name, '-'),
|
||||
'. Pengecekan potensi kerusakan dibutuhkan'
|
||||
) AS message_error_issue
|
||||
|
||||
FROM brand_code b
|
||||
|
||||
LEFT JOIN notification_error a
|
||||
ON a.error_code_id = b.error_code_id
|
||||
AND a.deleted_at IS NULL
|
||||
|
||||
LEFT JOIN m_device d
|
||||
ON b.brand_id = d.brand_id
|
||||
AND d.deleted_at IS NULL
|
||||
|
||||
WHERE b.deleted_at IS NULL
|
||||
AND a.notification_error_id IS NULL;
|
||||
`;
|
||||
|
||||
await pool.query(insertQuery);
|
||||
return insertedId ? await getNotificationByIdDb(insertedId) : null;
|
||||
};
|
||||
|
||||
const getNotificationByIdDb = async (id) => {
|
||||
@@ -55,8 +25,6 @@ const getNotificationByIdDb = async (id) => {
|
||||
const getAllNotificationDb = async (searchParams = {}) => {
|
||||
let queryParams = [];
|
||||
|
||||
await InsertNotificationErrorDb();
|
||||
|
||||
const boolFields = ["is_send", "is_delivered", "is_read", "is_active"];
|
||||
|
||||
boolFields.forEach((f) => {
|
||||
@@ -158,4 +126,5 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
||||
module.exports = {
|
||||
getNotificationByIdDb,
|
||||
getAllNotificationDb,
|
||||
InsertNotificationErrorDb
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user