From 5e4a9928349c6a7907b2b70eeea3f0d6dea20bc0 Mon Sep 17 00:00:00 2001 From: mhmmdafif Date: Tue, 18 Nov 2025 13:50:23 +0700 Subject: [PATCH] repair: crud notification error sparepart --- .../notification_error_sparepart.controller.js | 3 ++- services/notification_error_sparepart.service.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/controllers/notification_error_sparepart.controller.js b/controllers/notification_error_sparepart.controller.js index 31e9eef..373d72f 100644 --- a/controllers/notification_error_sparepart.controller.js +++ b/controllers/notification_error_sparepart.controller.js @@ -5,8 +5,9 @@ const { updateNotificationErrorSparepartSchema, insertNotificationErrorSparepart class NotificationErrorSparepartController { static async getAll(req, res) { + const { contact_id } = req.body; const queryParams = req.query; - const results = await NotificationErrorSparepart.getAll(queryParams); + const results = await NotificationErrorSparepart.getAll(queryParams, contact_id); const response = await setResponsePaging(queryParams, results, 'Notification Error Sparepart found'); res.status(response.statusCode).json(response); diff --git a/services/notification_error_sparepart.service.js b/services/notification_error_sparepart.service.js index 31f38fb..a5208c4 100644 --- a/services/notification_error_sparepart.service.js +++ b/services/notification_error_sparepart.service.js @@ -14,12 +14,20 @@ class NotificationErrorSparepartService { if (contactType !== "gudang") { throw new ErrorHandler( 403, - "Akses ditolak. Hanya contact_type 'gudang' yang dapat create/update/delete." + "Akses ditolak. Hanya contact_type 'gudang' yang dapat getAll/create/update/delete." ); } } - static async getAll(param) { + static async getAll(param, contact_id) { + const contactResult = await getContactByIdDb(contact_id); + + if (!contactResult || contactResult.length < 1) + throw new ErrorHandler(404, "Contact tidak ditemukan"); + + const contact = contactResult[0]; + + this._checkAccess(contact.contact_type); return await getAllNotificationErrorSparepartDb(param); }