Centralized errors and added their translations. Didn't test
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import db from '../db.js';
|
||||
import statuses from '../utils/status.js';
|
||||
import errorHandler from '../utils/pgerrorhandler.js';
|
||||
import customError from '../response/customError.js';
|
||||
import responseCodes from '../response/responseCodes.js';
|
||||
|
||||
class ProductService {
|
||||
async create(groupid, localid, abstract_product_id, amount, date_of_production, expiry_date) {
|
||||
await db.query("INSERT INTO products (group_id, local_id, abstract_product_id, amount, date_of_production, expiry_date) VALUES ($1, $2, $3, $4, $5, $6)", [groupid, localid, abstract_product_id, amount, date_of_production, expiry_date])
|
||||
.catch((e) => {
|
||||
errorHandler(e, "Abstract Product")
|
||||
errorHandler(e, "product")
|
||||
});
|
||||
}
|
||||
|
||||
async updateAbstractProductId(groupId, localId, abstract_product_id) {
|
||||
await db.query("UPDATE products SET abstract_product_id = $1 WHERE group_id = $2 AND local_id = $3", [abstract_product_id, groupId, localId])
|
||||
.catch((e) => {
|
||||
errorHandler(e, "abstract product id")
|
||||
errorHandler(e, "abstractproductid")
|
||||
});
|
||||
|
||||
}
|
||||
@@ -28,20 +29,20 @@ class ProductService {
|
||||
async updateDateOfProduction(groupId, localId, date_of_production) {
|
||||
await db.query("UPDATE products SET date_of_production = $1 WHERE group_id = $2 AND local_id = $3", [date_of_production, groupId, localId])
|
||||
.catch((e) => {
|
||||
errorHandler(e, "date of production")
|
||||
errorHandler(e, "dateofproduction")
|
||||
});
|
||||
}
|
||||
|
||||
async updateExpiryDate(groupId, localId, expiry_date) {
|
||||
await db.query("UPDATE products SET expiry_date = $1 WHERE group_id = $2 AND local_id = $3", [expiry_date, groupId, localId])
|
||||
.catch((e) => {
|
||||
errorHandler(e, "expiry date")
|
||||
errorHandler(e, "expirydate")
|
||||
});
|
||||
}
|
||||
|
||||
async getAll(groupId) {
|
||||
let result = (await db.query("SELECT local_id, abstract_product_id, amount, date_of_production, expiry_date FROM products WHERE group_id = $1", [groupId])).rows;
|
||||
if (!result) return statuses.not_found;
|
||||
if (!result) throw new customError(`getAll product not found`, responseCodes.responses.products.not_found);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user