Files
cod-api/services/notification_error_sparepart.service.js

77 lines
1.9 KiB
JavaScript

const {
getAllNotificationErrorSparepartDb,
getNotificationErrorSparepartByIdDb,
createNotificationErrorSparepartDb,
updateNotificationErrorSparepartDb,
deleteNotificationErrorSparepartDb,
} = require("../db/notification_error_sparepart.db");
const { ErrorHandler } = require("../helpers/error");
class NotificationErrorSparepartService {
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 getById(id) {
const result = await getNotificationErrorSparepartByIdDb(id);
if (result.length < 1)
throw new ErrorHandler(404, "Notification Error Sparepart not found");
return result;
}
static async create(data) {
try {
if (!data || typeof data !== 'object') data = {};
const result = await createNotificationErrorSparepartDb(data);
return result;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async update(id, data) {
try {
if (!data || typeof data !== 'object') data = {};
const dataExist = await getNotificationErrorSparepartByIdDb(id);
if (dataExist.length < 1) {
throw new ErrorHandler(404, 'Notification Error Sparepart not found');
}
const result = await updateNotificationErrorSparepartDb(id, data);
return result;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async delete(id) {
const exist = await getNotificationErrorSparepartByIdDb(id);
if (exist.length < 1)
throw new ErrorHandler(404, "Notification Error Sparepart not found");
return await deleteNotificationErrorSparepartDb(id);
}
}
module.exports = NotificationErrorSparepartService;