diff --git a/src/controllers/user.js b/src/controllers/user.js index b1a5286..330068a 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -8,6 +8,7 @@ import CategoryService from '../services/category.js'; import translate from '../utils/translate.js'; import responseCodes from '../response/responseCodes.js'; import customError from '../response/customError.js'; +import { createHash } from 'crypto'; const TAG = "/controllers/userjs" @@ -36,8 +37,22 @@ class UserController { let result = {}; result.abstract_products = await AbstractProductService.getAll(groupId); + result.abstract_products.forEach((abstractproduct) => { + let data = `${abstractproduct.local_id}:${abstractproduct.barcode}:${abstractproduct.name}:${abstractproduct.net_weight}:${abstractproduct.image_filename}:${abstractproduct.category}:${abstractproduct.unit}` + abstractproduct.hash = createHash('md5').update(data).digest('hex'); + }); + result.products = await ProductService.getAll(groupId); + result.products.forEach((product) => { + let data = `${product.local_id}:${product.abstract_product_id}:${product.amount}:${new Date(product.date_of_production).valueOf() / 1000}:${new Date(product.expiry_date).valueOf() / 1000}` + product.hash = createHash('md5').update(data).digest('hex'); + }); + result.categories = await CategoryService.getAll(groupId); + result.categories.forEach((category) => { + let data = `${category.local_id}:${category.name}` + category.hash = createHash('md5').update(data).digest('hex'); + }); return res.status(200).send(result); }