fixed /api/user/synchronize

This commit is contained in:
leca 2024-11-07 03:11:07 +03:00
parent 646bc77aa0
commit 1a557fd530
5 changed files with 10 additions and 3 deletions

View File

@ -12,6 +12,8 @@ class AbstractProductController {
async create(req, res) { async create(req, res) {
const { groupId, localId, barcode, name, net_weight, category, unit } = req.body; 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 tempPath = req.file.path;
const image_buffer = fs.readFileSync(tempPath); const image_buffer = fs.readFileSync(tempPath);
const image_filename = createHash('md5').update(image_buffer).digest('hex'); const image_filename = createHash('md5').update(image_buffer).digest('hex');

View File

@ -4,10 +4,10 @@ import bcrypt from 'bcrypt';
import jwtutils from '../utils/jwt.js'; import jwtutils from '../utils/jwt.js';
import AbstractProductService from '../services/abstractproduct.js'; import AbstractProductService from '../services/abstractproduct.js';
import ProductService from '../services/product.js'; import ProductService from '../services/product.js';
import CategoryService from '../services/category.js';
import translate from '../utils/translate.js'; import translate from '../utils/translate.js';
import responseCodes from '../response/responseCodes.js'; import responseCodes from '../response/responseCodes.js';
import customError from '../response/customError.js'; import customError from '../response/customError.js';
import jwt from 'jsonwebtoken';
const TAG = "/controllers/userjs" const TAG = "/controllers/userjs"

View File

@ -55,7 +55,7 @@ class AbstractProductService {
async getAll(groupId) { 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; 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; return result;
} }

View File

@ -22,6 +22,11 @@ class CategoryService {
if (result.rowCount == 0) throw new customError(`getByName categories not found`, responseCodes.responses.category.not_found) if (result.rowCount == 0) throw new customError(`getByName categories not found`, responseCodes.responses.category.not_found)
return result.rows[0]; 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(); export default new CategoryService();

View File

@ -42,7 +42,7 @@ class ProductService {
async getAll(groupId) { 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; 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; return result;
} }