a lot of bugfixes, completed abstract products and products
This commit is contained in:
		@@ -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 };
 | 
			
		||||
@@ -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;
 | 
			
		||||
							
								
								
									
										29
									
								
								src/utils/pgerrorhandler.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/utils/pgerrorhandler.js
									
									
									
									
									
										Normal 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;
 | 
			
		||||
@@ -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
 | 
			
		||||
		Reference in New Issue
	
	Block a user