repair: get all notification

This commit is contained in:
2025-11-17 11:14:36 +07:00
parent ac68a380dd
commit ff4176f8f9
3 changed files with 33 additions and 24 deletions

View File

@@ -4,15 +4,12 @@ const { insertNotificationSchema, updateNotificationSchema } = require('../valid
class NotificationController {
static async getAll(req, res) {
try {
const queryParams = req.query;
const results = await NotificationService.getAllNotification(queryParams);
const response = await setResponsePaging(queryParams, results, 'Notification list retrieved successfully');
return res.status(response.statusCode).json(response);
} catch (err) {
console.error("Notification Error:", err.message);
return res.status(500).json(setResponse(err, 'Failed to fetch notifications', 500));
}
const queryParams = req.query;
const results = await NotificationService.getAllNotification(queryParams);
const response = await setResponsePaging(queryParams, results, 'Notification found')
res.status(response.statusCode).json(response);
}

View File

@@ -16,23 +16,26 @@ const InsertNotificationErrorDb = async () => {
1 AS is_delivered,
0 AS is_read,
1 AS is_send,
CONCAT(
COALESCE(b.error_code_description, '-'),
' pada ',
COALESCE(d.plant_sub_section_name, '-'),
COALESCE(d.device_name, '-'),
'. Pengecekan potensi kerusakan dibutuhkan'
) AS message_error_issue
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
ON ne.error_code_id = b.error_code_id
AND ne.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 d.deleted_at IS NULL
AND ne.notification_error_id IS NULL
AND a.notification_error_id IS NULL;
`;
await pool.query(insertQuery);
@@ -43,7 +46,6 @@ const InsertNotificationErrorDb = async () => {
const getAllNotificationDb = async (searchParams = {}) => {
let queryParams = [];
// Tambahkan data baru jika belum ada
await InsertNotificationErrorDb();
if (searchParams.limit) {
@@ -84,18 +86,29 @@ const getAllNotificationDb = async (searchParams = {}) => {
SELECT
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_name,
b.created_at,
c.solution_name,
c.type_solution,
c.path_solution,
d.plant_sub_section_name,
e.device_location
d.device_name,
d.device_location,
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
@@ -104,9 +117,9 @@ const getAllNotificationDb = async (searchParams = {}) => {
ON b.error_code_id = c.error_code_id
AND c.deleted_at IS NULL
CROSS JOIN m_plant_sub_section d
CROSS JOIN m_device e
LEFT JOIN m_device d
ON b.brand_id = d.brand_id
AND d.deleted_at IS NULL
WHERE a.deleted_at IS NULL
${

View File

@@ -4,7 +4,6 @@ const {
insertNotificationDb,
updateNotificationDb,
deleteNotificationDb,
handleBrandCodeError // 🧩 tambahkan ini
} = require('../db/notification.db');
const { ErrorHandler } = require('../helpers/error');