repair: get all notification
This commit is contained in:
@@ -4,15 +4,12 @@ const { insertNotificationSchema, updateNotificationSchema } = require('../valid
|
|||||||
|
|
||||||
class NotificationController {
|
class NotificationController {
|
||||||
static async getAll(req, res) {
|
static async getAll(req, res) {
|
||||||
try {
|
const queryParams = req.query;
|
||||||
const queryParams = req.query;
|
|
||||||
const results = await NotificationService.getAllNotification(queryParams);
|
const results = await NotificationService.getAllNotification(queryParams);
|
||||||
const response = await setResponsePaging(queryParams, results, 'Notification list retrieved successfully');
|
const response = await setResponsePaging(queryParams, results, 'Notification found')
|
||||||
return res.status(response.statusCode).json(response);
|
|
||||||
} catch (err) {
|
res.status(response.statusCode).json(response);
|
||||||
console.error("Notification Error:", err.message);
|
|
||||||
return res.status(500).json(setResponse(err, 'Failed to fetch notifications', 500));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,23 +16,26 @@ 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,
|
||||||
|
|
||||||
CONCAT(
|
CONCAT(
|
||||||
COALESCE(b.error_code_description, '-'),
|
COALESCE(b.error_code_description, '-'),
|
||||||
' pada ',
|
' pada ',
|
||||||
COALESCE(d.plant_sub_section_name, '-'),
|
COALESCE(d.device_name, '-'),
|
||||||
'. Pengecekan potensi kerusakan dibutuhkan'
|
'. Pengecekan potensi kerusakan dibutuhkan'
|
||||||
) AS message_error_issue
|
) AS message_error_issue
|
||||||
|
|
||||||
FROM brand_code b
|
FROM brand_code b
|
||||||
|
|
||||||
CROSS JOIN m_plant_sub_section d
|
LEFT JOIN notification_error a
|
||||||
|
ON a.error_code_id = b.error_code_id
|
||||||
|
AND a.deleted_at IS NULL
|
||||||
|
|
||||||
LEFT JOIN notification_error ne
|
LEFT JOIN m_device d
|
||||||
ON ne.error_code_id = b.error_code_id
|
ON b.brand_id = d.brand_id
|
||||||
AND ne.deleted_at IS NULL
|
AND d.deleted_at IS NULL
|
||||||
|
|
||||||
WHERE b.deleted_at IS NULL
|
WHERE b.deleted_at IS NULL
|
||||||
AND d.deleted_at IS NULL
|
AND a.notification_error_id IS NULL;
|
||||||
AND ne.notification_error_id IS NULL
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
await pool.query(insertQuery);
|
await pool.query(insertQuery);
|
||||||
@@ -43,7 +46,6 @@ const InsertNotificationErrorDb = async () => {
|
|||||||
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) {
|
||||||
@@ -84,18 +86,29 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
|||||||
SELECT
|
SELECT
|
||||||
COUNT(*) OVER() AS total_data,
|
COUNT(*) OVER() AS total_data,
|
||||||
|
|
||||||
a.*,
|
a.notification_error_id,
|
||||||
|
a.error_code_id,
|
||||||
|
a.message_error_issue,
|
||||||
|
a.is_send,
|
||||||
|
a.is_delivered,
|
||||||
|
a.is_read,
|
||||||
|
a.is_active,
|
||||||
|
|
||||||
b.error_code,
|
b.error_code,
|
||||||
b.error_code_name,
|
b.error_code_name,
|
||||||
|
b.created_at,
|
||||||
|
|
||||||
c.solution_name,
|
c.solution_name,
|
||||||
c.type_solution,
|
c.type_solution,
|
||||||
c.path_solution,
|
c.path_solution,
|
||||||
|
|
||||||
d.plant_sub_section_name,
|
d.device_name,
|
||||||
e.device_location
|
d.device_location,
|
||||||
|
|
||||||
|
COALESCE(d.device_name, '') + ' - ' + COALESCE(b.error_code_name, '') AS device_name_error
|
||||||
|
|
||||||
FROM notification_error a
|
FROM notification_error a
|
||||||
|
|
||||||
LEFT JOIN brand_code b
|
LEFT JOIN brand_code b
|
||||||
ON a.error_code_id = b.error_code_id
|
ON a.error_code_id = b.error_code_id
|
||||||
AND b.deleted_at IS NULL
|
AND b.deleted_at IS NULL
|
||||||
@@ -104,9 +117,9 @@ const getAllNotificationDb = async (searchParams = {}) => {
|
|||||||
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
|
||||||
|
|
||||||
CROSS JOIN m_plant_sub_section d
|
LEFT JOIN m_device d
|
||||||
|
ON b.brand_id = d.brand_id
|
||||||
CROSS JOIN m_device e
|
AND d.deleted_at IS NULL
|
||||||
|
|
||||||
WHERE a.deleted_at IS NULL
|
WHERE a.deleted_at IS NULL
|
||||||
${
|
${
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const {
|
|||||||
insertNotificationDb,
|
insertNotificationDb,
|
||||||
updateNotificationDb,
|
updateNotificationDb,
|
||||||
deleteNotificationDb,
|
deleteNotificationDb,
|
||||||
handleBrandCodeError // 🧩 tambahkan ini
|
|
||||||
} = require('../db/notification.db');
|
} = require('../db/notification.db');
|
||||||
|
|
||||||
const { ErrorHandler } = require('../helpers/error');
|
const { ErrorHandler } = require('../helpers/error');
|
||||||
|
|||||||
Reference in New Issue
Block a user