repair: notification error sparepart
This commit is contained in:
@@ -6,31 +6,23 @@ const {
|
||||
deleteNotificationErrorSparepartDb,
|
||||
} = require("../db/notification_error_sparepart.db");
|
||||
|
||||
const { getContactByIdDb } = require("../db/contact.db");
|
||||
const { ErrorHandler } = require("../helpers/error");
|
||||
|
||||
class NotificationErrorSparepartService {
|
||||
static _checkAccess(contactType) {
|
||||
if (contactType !== "gudang") {
|
||||
throw new ErrorHandler(
|
||||
403,
|
||||
"Akses ditolak. Hanya contact_type 'gudang' yang dapat getAll/create/update/delete."
|
||||
);
|
||||
|
||||
static async getAll(param) {
|
||||
try {
|
||||
const results = await getAllNotificationErrorSparepartDb(param);
|
||||
|
||||
results.data.map(element => {
|
||||
});
|
||||
|
||||
return results
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static async getById(id) {
|
||||
const result = await getNotificationErrorSparepartByIdDb(id);
|
||||
|
||||
@@ -40,46 +32,37 @@ class NotificationErrorSparepartService {
|
||||
return result;
|
||||
}
|
||||
|
||||
static async create(data) {
|
||||
const contactResult = await getContactByIdDb(data.contact_id);
|
||||
static async create(data) {
|
||||
try {
|
||||
if (!data || typeof data !== 'object') data = {};
|
||||
|
||||
if (!contactResult || contactResult.length < 1)
|
||||
throw new ErrorHandler(404, "Contact tidak ditemukan");
|
||||
const result = await createNotificationErrorSparepartDb(data);
|
||||
|
||||
const contact = contactResult[0];
|
||||
|
||||
this._checkAccess(contact.contact_type);
|
||||
|
||||
return await createNotificationErrorSparepartDb(data);
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async update(id, data) {
|
||||
const contactResult = await getContactByIdDb(data.contact_id);
|
||||
static async update(id, data) {
|
||||
try {
|
||||
if (!data || typeof data !== 'object') data = {};
|
||||
|
||||
if (!contactResult || contactResult.length < 1)
|
||||
throw new ErrorHandler(404, "Contact tidak ditemukan");
|
||||
const dataExist = await getNotificationErrorSparepartByIdDb(id);
|
||||
|
||||
const contact = contactResult[0];
|
||||
if (dataExist.length < 1) {
|
||||
throw new ErrorHandler(404, 'Roles not found');
|
||||
}
|
||||
|
||||
this._checkAccess(contact.contact_type);
|
||||
const result = await updateNotificationErrorSparepartDb(id, data);
|
||||
|
||||
const exist = await getNotificationErrorSparepartByIdDb(id);
|
||||
|
||||
if (exist.length < 1)
|
||||
throw new ErrorHandler(404, "Notification Error Sparepart not found");
|
||||
|
||||
return await updateNotificationErrorSparepartDb(id, data);
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new ErrorHandler(error.statusCode, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async delete(id, 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);
|
||||
static async delete(id) {
|
||||
|
||||
const exist = await getNotificationErrorSparepartByIdDb(id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user