diff --git a/src/controllers/abstractproduct.js b/src/controllers/abstractproduct.js index 12ddaf2..67bbc24 100644 --- a/src/controllers/abstractproduct.js +++ b/src/controllers/abstractproduct.js @@ -12,6 +12,8 @@ class AbstractProductController { async create(req, res) { const { groupId, localId, barcode, name, net_weight, category, unit } = req.body; + if (!req.file) throw new customError(`user hasn't supplied a file for abstract product creation`, responseCodes.responses.image_filename) + const tempPath = req.file.path; const image_buffer = fs.readFileSync(tempPath); const image_filename = createHash('md5').update(image_buffer).digest('hex'); diff --git a/src/controllers/user.js b/src/controllers/user.js index ef166aa..b1a5286 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -4,10 +4,10 @@ import bcrypt from 'bcrypt'; import jwtutils from '../utils/jwt.js'; import AbstractProductService from '../services/abstractproduct.js'; import ProductService from '../services/product.js'; +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 jwt from 'jsonwebtoken'; const TAG = "/controllers/userjs" diff --git a/src/services/abstractproduct.js b/src/services/abstractproduct.js index 4f3c22b..e955e28 100644 --- a/src/services/abstractproduct.js +++ b/src/services/abstractproduct.js @@ -55,7 +55,7 @@ class AbstractProductService { async getAll(groupId) { let result = (await db.query("SELECT local_id, barcode, name, net_weight, image_filename, category, unit FROM abstract_products WHERE group_id = $1", [groupId])).rows; - if (!result) throw new customError("getAll abstract products not found", responses.responses.abstractproducts.not_found) + // if (!result) throw new customError("getAll abstract products not found", responses.responses.abstractproducts.not_found) return result; } diff --git a/src/services/category.js b/src/services/category.js index f7337a8..e14f00c 100644 --- a/src/services/category.js +++ b/src/services/category.js @@ -22,6 +22,11 @@ class CategoryService { if (result.rowCount == 0) throw new customError(`getByName categories not found`, responseCodes.responses.category.not_found) return result.rows[0]; } + + async getAll(groupId) { + let result = (await db.query("SELECT group_id, local_id, name FROM categories WHERE group_id = $1", [groupId])).rows + return result + } } export default new CategoryService(); \ No newline at end of file diff --git a/src/services/product.js b/src/services/product.js index d09868c..ef8b924 100644 --- a/src/services/product.js +++ b/src/services/product.js @@ -42,7 +42,7 @@ class ProductService { async getAll(groupId) { let result = (await db.query("SELECT local_id, abstract_product_id, amount, date_of_production, expiry_date FROM products WHERE group_id = $1", [groupId])).rows; - if (!result) throw new customError(`getAll product not found`, responseCodes.responses.products.not_found); + // if (!result) throw new customError(`getAll product not found`, responseCodes.responses.products.not_found); return result; }