a lot of bugfixes, completed abstract products and products

This commit is contained in:
2024-10-27 04:45:13 +03:00
parent a27ce5762c
commit 75f9fb6d7d
24 changed files with 462 additions and 284 deletions

View File

@@ -1,11 +0,0 @@
import { createHash } from 'node:crypto'
const hashAbstractProduct = (barcode, name, net_weight, image_filename, category, unit) => {
return createHash('md5').update(`${barcode}${name}${net_weight}${image_filename}${category}${unit}`).digest('hex');
}
const hashProduct = (abstract_product_id, amount, date_of_production, expiry_date) => {
return createHash('md5').update(`${abstract_product_id}${amount}${date_of_production}${expiry_date}`).digest('hex');
}
export default { hashAbstractProduct, hashProduct };

View File

@@ -3,7 +3,7 @@ import config from '../../config.json' with {type: "json"};
const genToken = (login) => {
const payload = { login };
return jwt.sign(payload, config.secret, {expiresIn: "7d"});
return jwt.sign(payload, config.secret, { expiresIn: "7d" });
};
export default genToken;

View File

@@ -0,0 +1,29 @@
import statuses from "./status.js"
const errorHandler = (e, obj) => {
switch (e.code) {
case '23505':
throw {
status: statuses.duplicate,
message: `Such ${obj} already exists`
}
case '22007':
throw {
status: statuses.invalid_syntax,
message: `Invalid syntax in ${obj}`
}
case '22001':
throw {
status: statuses.invalid_syntax,
message: `Value too long (${obj})`
}
default:
throw {
status: statuses.unknown,
message: `Unknown error. Please, report to the developer`,
original: e
}
}
};
export default errorHandler;

View File

@@ -1,7 +1,9 @@
const statuses = {
ok: "ok",
duplicate: "duplicate",
not_found: "not found"
not_found: "not found",
invalid_syntax: "invalid syntax",
unknown: "unknown"
}
export default statuses