From c4f0d65f4f19201b3a6b6ede2b4ce5eeb884ecb6 Mon Sep 17 00:00:00 2001 From: leca Date: Wed, 13 Nov 2024 11:38:32 +0300 Subject: [PATCH] renamed keys in json websocket send on synchronization --- docker-compose.yml | 1 + sample.config.json | 2 +- src/controllers/abstractproduct.js | 11 +++-------- src/controllers/category.js | 7 +++---- src/controllers/product.js | 14 +++++--------- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 30f297e..e7aefcf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,7 @@ services: ports: - 8012:8080 + - 8282:8282 depends_on: - database restart: on-failure diff --git a/sample.config.json b/sample.config.json index ef23984..0980fc7 100644 --- a/sample.config.json +++ b/sample.config.json @@ -1,7 +1,7 @@ { "debug": true, "port": "8081", - "wsport": "8082", + "wsport": "8282", "dbuser": "bsfe", "dbhost": "localhost", "dbport": "5432", diff --git a/src/controllers/abstractproduct.js b/src/controllers/abstractproduct.js index 5b1d06a..37a1043 100644 --- a/src/controllers/abstractproduct.js +++ b/src/controllers/abstractproduct.js @@ -32,7 +32,7 @@ class AbstractProductController { await AbstractProductService.create(groupId, localId, barcode, name, net_weight, image_filename, category, unit); notify(req.headers.authorization.split(' ')[1], groupId, 'create', 'abstractproduct', { - localId, barcode, name, net_weight, image_filename, category, unit + local_id: localId, barcode, name, net_weight, image_filename, category, unit }); return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok)); @@ -64,12 +64,7 @@ class AbstractProductController { if (unit) await AbstractProductService.updateUnit(groupId, localId, unit); - let data = { localId } - if (barcode) data.barcode = barcode - if (name) data.name = name - if (net_weight) data.net_weight = net_weight - if (category) data.category = category - if (unit) data.unit = unit + let data = await AbstractProductService.getByLocalId(groupId, localId) notify(req.headers.authorization.split(' ')[1], groupId, 'update', 'abstractproduct', data); @@ -100,7 +95,7 @@ class AbstractProductController { await AbstractProductService.delete(groupId, localId) - notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'abstractproduct', { localId }); + notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'abstractproduct', { local_id: localId }); return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok)) } diff --git a/src/controllers/category.js b/src/controllers/category.js index 3396348..5149cec 100644 --- a/src/controllers/category.js +++ b/src/controllers/category.js @@ -12,7 +12,7 @@ class CategoryController { await CategoryService.create(groupId, localId, categoryName); notify(req.headers.authorization.split(' ')[1], groupId, 'create', 'category', { - localId, categoryName + local_id: localId, name: categoryName }); return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok)); @@ -23,8 +23,7 @@ class CategoryController { await CategoryService.update(groupId, localId, categoryName); - let data = { localId } - if (categoryName) data.categoryName = categoryName + let data = await CategoryService.getById(groupId, localId) notify(req.headers.authorization.split(' ')[1], groupId, 'update', 'category', data); @@ -44,7 +43,7 @@ class CategoryController { await CategoryService.delete(groupId, localId); - notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'category', { localId }); + notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'category', { local_id: localId }); return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok)) } diff --git a/src/controllers/product.js b/src/controllers/product.js index 06afdc7..534f913 100644 --- a/src/controllers/product.js +++ b/src/controllers/product.js @@ -10,9 +10,9 @@ class AbstractProductController { await ProductService.create(groupId, localId, abstract_product_id, amount, date_of_production, expiry_date); - notify(req.headers.authorization.split(' ')[1], groupId, 'create', 'product', { - localId, abstract_product_id, amount, date_of_production, expiry_date - }); + let data = await ProductService.getByLocalId(groupId, localId) + + notify(req.headers.authorization.split(' ')[1], groupId, 'create', 'product', data); return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok)); } @@ -28,11 +28,7 @@ class AbstractProductController { if (expiry_date) await ProductService.updateExpiryDate(groupId, localId, expiry_date); - let data = { localId }; - if (abstract_product_id) data.abstract_product_id = abstract_product_id - if (amount) data.amount = amount - if (date_of_production) data.date_of_production = date_of_production - if (expiry_date) data.expiry_date = expiry_date + let data = await ProductService.getByLocalId(groupId, localId) notify(req.headers.authorization.split(' ')[1], groupId, 'update', 'product', data); @@ -54,7 +50,7 @@ class AbstractProductController { await ProductService.delete(id) - notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'product', { localId }); + notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'product', { local_id: localId }); return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok)); }