repair: notification error sparepart
This commit is contained in:
@@ -11,10 +11,10 @@ const getAllNotificationErrorSparepartDb = async (searchParams = {}) => {
|
|||||||
const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike(
|
const { whereOrConditions, whereParamOr } = pool.buildStringOrIlike(
|
||||||
[
|
[
|
||||||
"a.brand_sparepart_id",
|
"a.brand_sparepart_id",
|
||||||
"a.contact_id",
|
"a.device_id",
|
||||||
|
"a.sparepart_id",
|
||||||
"b.sparepart_name",
|
"b.sparepart_name",
|
||||||
"d.contact_name",
|
"d.device_name",
|
||||||
"d.contact_type"
|
|
||||||
],
|
],
|
||||||
searchParams.criteria,
|
searchParams.criteria,
|
||||||
queryParams
|
queryParams
|
||||||
@@ -25,11 +25,10 @@ const getAllNotificationErrorSparepartDb = async (searchParams = {}) => {
|
|||||||
const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
|
const { whereConditions, whereParamAnd } = pool.buildFilterQuery(
|
||||||
[
|
[
|
||||||
{ column: "a.brand_sparepart_id", param: searchParams.name, type: "int" },
|
{ column: "a.brand_sparepart_id", param: searchParams.name, type: "int" },
|
||||||
{ column: "a.contact_id", param: searchParams.code, type: "int" },
|
{ column: "a.device_id", param: searchParams.code, type: "int" },
|
||||||
{ column: "a.unit", param: searchParams.unit, type: "string" },
|
{ column: "a.unit", param: searchParams.unit, type: "string" },
|
||||||
{ column: "b.sparepart_name", param: searchParams.device, type: "string" },
|
{ column: "b.sparepart_name", param: searchParams.device, type: "string" },
|
||||||
{ column: "d.contact_name", param: searchParams.device, type: "string" },
|
{ column: "d.device_name", param: searchParams.device, type: "string" },
|
||||||
{ column: "d.contact_type", param: searchParams.device, type: "string" },
|
|
||||||
],
|
],
|
||||||
queryParams
|
queryParams
|
||||||
);
|
);
|
||||||
@@ -41,14 +40,23 @@ const getAllNotificationErrorSparepartDb = async (searchParams = {}) => {
|
|||||||
COUNT(*) OVER() AS total_data,
|
COUNT(*) OVER() AS total_data,
|
||||||
a.*,
|
a.*,
|
||||||
b.sparepart_name,
|
b.sparepart_name,
|
||||||
b.brand_sparepart_description,
|
b.sparepart_foto,
|
||||||
d.contact_name,
|
b.sparepart_stok,
|
||||||
d.contact_type
|
b.sparepart_qty,
|
||||||
|
b.sparepart_description,
|
||||||
|
b.sparepart_model,
|
||||||
|
b.sparepart_merk,
|
||||||
|
b.sparepart_unit,
|
||||||
|
b.sparepart_item_type,
|
||||||
|
d.device_name
|
||||||
|
|
||||||
FROM notification_error_sparepart a
|
FROM notification_error_sparepart a
|
||||||
|
|
||||||
LEFT JOIN brand_sparepart b ON a.brand_sparepart_id = b.brand_sparepart_id
|
LEFT JOIN brand_sparepart c ON a.brand_sparepart_id = c.brand_sparepart_id
|
||||||
|
|
||||||
LEFT JOIN contact d on a.contact_id = d.contact_id
|
LEFT JOIN m_sparepart b ON c.sparepart_id = b.sparepart_id
|
||||||
|
|
||||||
|
LEFT JOIN m_device d on c.device_id = d.device_id
|
||||||
|
|
||||||
WHERE a.deleted_at IS NULL
|
WHERE a.deleted_at IS NULL
|
||||||
${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""}
|
${whereConditions.length > 0 ? ` AND ${whereConditions.join(" AND ")}` : ""}
|
||||||
@@ -69,15 +77,26 @@ const getAllNotificationErrorSparepartDb = async (searchParams = {}) => {
|
|||||||
|
|
||||||
const getNotificationErrorSparepartByIdDb = async (id) => {
|
const getNotificationErrorSparepartByIdDb = async (id) => {
|
||||||
const queryText = `
|
const queryText = `
|
||||||
SELECT
|
|
||||||
a.*,
|
a.*,
|
||||||
b.sparepart_name,
|
b.sparepart_name,
|
||||||
b.brand_sparepart_description,
|
b.sparepart_foto,
|
||||||
d.contact_name,
|
b.sparepart_stok,
|
||||||
d.contact_type
|
b.sparepart_qty,
|
||||||
|
b.sparepart_description,
|
||||||
|
b.sparepart_model,
|
||||||
|
b.sparepart_merk,
|
||||||
|
b.sparepart_unit,
|
||||||
|
b.sparepart_item_type,
|
||||||
|
d.device_name
|
||||||
|
|
||||||
FROM notification_error_sparepart a
|
FROM notification_error_sparepart a
|
||||||
LEFT JOIN brand_sparepart b ON a.brand_sparepart_id = b.brand_sparepart_id
|
|
||||||
LEFT JOIN contact d on a.contact_id = d.contact_id
|
LEFT JOIN brand_sparepart c ON a.brand_sparepart_id = c.brand_sparepart_id
|
||||||
|
|
||||||
|
LEFT JOIN m_sparepart b ON c.sparepart_id = b.sparepart_id
|
||||||
|
|
||||||
|
LEFT JOIN m_device d on c.device_id = d.device_id
|
||||||
|
|
||||||
WHERE a.notification_error_sparepart_id = $1
|
WHERE a.notification_error_sparepart_id = $1
|
||||||
AND a.deleted_at IS NULL
|
AND a.deleted_at IS NULL
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -6,31 +6,23 @@ const {
|
|||||||
deleteNotificationErrorSparepartDb,
|
deleteNotificationErrorSparepartDb,
|
||||||
} = require("../db/notification_error_sparepart.db");
|
} = require("../db/notification_error_sparepart.db");
|
||||||
|
|
||||||
const { getContactByIdDb } = require("../db/contact.db");
|
|
||||||
const { ErrorHandler } = require("../helpers/error");
|
const { ErrorHandler } = require("../helpers/error");
|
||||||
|
|
||||||
class NotificationErrorSparepartService {
|
class NotificationErrorSparepartService {
|
||||||
static _checkAccess(contactType) {
|
|
||||||
if (contactType !== "gudang") {
|
static async getAll(param) {
|
||||||
throw new ErrorHandler(
|
try {
|
||||||
403,
|
const results = await getAllNotificationErrorSparepartDb(param);
|
||||||
"Akses ditolak. Hanya contact_type 'gudang' yang dapat getAll/create/update/delete."
|
|
||||||
);
|
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) {
|
static async getById(id) {
|
||||||
const result = await getNotificationErrorSparepartByIdDb(id);
|
const result = await getNotificationErrorSparepartByIdDb(id);
|
||||||
|
|
||||||
@@ -41,45 +33,36 @@ class NotificationErrorSparepartService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async create(data) {
|
static async create(data) {
|
||||||
const contactResult = await getContactByIdDb(data.contact_id);
|
try {
|
||||||
|
if (!data || typeof data !== 'object') data = {};
|
||||||
|
|
||||||
if (!contactResult || contactResult.length < 1)
|
const result = await createNotificationErrorSparepartDb(data);
|
||||||
throw new ErrorHandler(404, "Contact tidak ditemukan");
|
|
||||||
|
|
||||||
const contact = contactResult[0];
|
return result;
|
||||||
|
} catch (error) {
|
||||||
this._checkAccess(contact.contact_type);
|
throw new ErrorHandler(error.statusCode, error.message);
|
||||||
|
}
|
||||||
return await createNotificationErrorSparepartDb(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async update(id, data) {
|
static async update(id, data) {
|
||||||
const contactResult = await getContactByIdDb(data.contact_id);
|
try {
|
||||||
|
if (!data || typeof data !== 'object') data = {};
|
||||||
|
|
||||||
if (!contactResult || contactResult.length < 1)
|
const dataExist = await getNotificationErrorSparepartByIdDb(id);
|
||||||
throw new ErrorHandler(404, "Contact tidak ditemukan");
|
|
||||||
|
|
||||||
const contact = contactResult[0];
|
if (dataExist.length < 1) {
|
||||||
|
throw new ErrorHandler(404, 'Roles not found');
|
||||||
this._checkAccess(contact.contact_type);
|
|
||||||
|
|
||||||
const exist = await getNotificationErrorSparepartByIdDb(id);
|
|
||||||
|
|
||||||
if (exist.length < 1)
|
|
||||||
throw new ErrorHandler(404, "Notification Error Sparepart not found");
|
|
||||||
|
|
||||||
return await updateNotificationErrorSparepartDb(id, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async delete(id, contact_id) {
|
const result = await updateNotificationErrorSparepartDb(id, data);
|
||||||
const contactResult = await getContactByIdDb(contact_id);
|
|
||||||
|
|
||||||
if (!contactResult || contactResult.length < 1)
|
return result;
|
||||||
throw new ErrorHandler(404, "Contact tidak ditemukan");
|
} catch (error) {
|
||||||
|
throw new ErrorHandler(error.statusCode, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const contact = contactResult[0];
|
static async delete(id) {
|
||||||
|
|
||||||
this._checkAccess(contact.contact_type);
|
|
||||||
|
|
||||||
const exist = await getNotificationErrorSparepartByIdDb(id);
|
const exist = await getNotificationErrorSparepartByIdDb(id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user