diff --git a/src/response/errorHandler.js b/src/response/errorHandler.js index 646ca7f..be47e97 100644 --- a/src/response/errorHandler.js +++ b/src/response/errorHandler.js @@ -5,7 +5,7 @@ import translate from '../utils/translate.js'; const errorHandler = (err, req, res) => { log.error(err); - + console.log(err); let language = req.headers["accept-language"]; if (err instanceof customError) { @@ -23,4 +23,4 @@ const tryHandler = (func) => { } } -export default tryHandler; \ No newline at end of file +export default tryHandler; diff --git a/src/services/product.js b/src/services/product.js index 679ffad..e7d0e3f 100644 --- a/src/services/product.js +++ b/src/services/product.js @@ -5,7 +5,7 @@ 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]) + await db.query("INSERT INTO products (group_id, local_id, abstract_product_id, amount, date_of_production, expiry_date) VALUES ($1, $2, $3, $4, to_timestamp($5)::date, to_timestamp($6)::date)", [groupid, localid, abstract_product_id, amount, date_of_production, expiry_date]) .catch((e) => { errorHandler(e, "product") }); @@ -27,14 +27,14 @@ 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]) + await db.query("UPDATE products SET date_of_production = to_timestamp($1)::date WHERE group_id = $2 AND local_id = $3", [date_of_production, groupId, localId]) .catch((e) => { 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]) + await db.query("UPDATE products SET expiry_date = to_timestamp($1)::date WHERE group_id = $2 AND local_id = $3", [expiry_date, groupId, localId]) .catch((e) => { errorHandler(e, "expirydate") }); @@ -59,4 +59,4 @@ class ProductService { } }; -export default new ProductService(); \ No newline at end of file +export default new ProductService(); diff --git a/src/utils/pgerrorhandler.js b/src/utils/pgerrorhandler.js index 8b19cad..9047cc0 100644 --- a/src/utils/pgerrorhandler.js +++ b/src/utils/pgerrorhandler.js @@ -10,8 +10,9 @@ const errorHandler = (e, obj) => { case '22001': throw new customError(`Value too long ${obj}`, responseCodes.responses[obj].too_long) default: + console.log(e) throw new customError(`Unknown error ${obj}`, responseCodes.responses.general.unknown) }; }; -export default errorHandler; \ No newline at end of file +export default errorHandler;