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); }