diff --git a/db/notification_error_sparepart.db.js b/db/notification_error_sparepart.db.js index a20c13a..a2e519f 100644 --- a/db/notification_error_sparepart.db.js +++ b/db/notification_error_sparepart.db.js @@ -1,6 +1,34 @@ const pool = require("../config"); +const insertNotificationErrorSparepartDb = async () => { + const insertQuery = ` + INSERT INTO notification_error_sparepart ( + notification_error_id, + brand_sparepart_id + ) + SELECT + ne.notification_error_id, + bs.brand_sparepart_id + + FROM notification_error ne + + INNER JOIN brand_sparepart bs + ON ne.error_code_id = bs.error_code_id + + LEFT JOIN notification_error_sparepart nes + ON nes.notification_error_id = ne.notification_error_id + AND nes.brand_sparepart_id = bs.brand_sparepart_id + AND nes.deleted_at IS NULL + + WHERE ne.deleted_at IS NULL + AND nes.notification_error_sparepart_id IS NULL; + `; + + await pool.query(insertQuery); +}; + const getAllNotificationErrorSparepartDb = async (searchParams = {}) => { + await insertNotificationErrorSparepartDb(); let queryParams = []; if (searchParams.limit) {