fixed wrong date inserting
This commit is contained in:
parent
757f5c13a5
commit
77d95824f3
|
@ -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) {
|
||||
|
|
|
@ -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")
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@ 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)
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue