;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
This commit is contained in:
		@@ -53,9 +53,9 @@ 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
 | 
			
		||||
        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) return statuses.not_found;
 | 
			
		||||
        return result
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async exists(groupId, localId) {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@ import statuses from '../utils/status.js';
 | 
			
		||||
 | 
			
		||||
class CategoryService {
 | 
			
		||||
    async create(groupId, categoryId, name) {
 | 
			
		||||
        await db.query("INSERT INTO categories (group_id, local_id, name) VALUES ($1, $2, $3)", [groupId, categoryId, name])
 | 
			
		||||
        await db.query("INSERT INTO categories (group_id, local_id, name) VALUES ($1, $2, $3)", [groupId, categoryId, name]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async update(groupId, categoryId, name) {
 | 
			
		||||
@@ -13,7 +13,7 @@ class CategoryService {
 | 
			
		||||
    async getById(groupId, localId) {
 | 
			
		||||
        let result = (await db.query("SELECT * FROM categories WHERE group_id = $1 AND local_id = $2", [groupId, localId]))
 | 
			
		||||
        if (result.rowCount == 0) return statuses.not_found;
 | 
			
		||||
        return result.rows[0]
 | 
			
		||||
        return result.rows[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByName(groupId, localId, name) {
 | 
			
		||||
 
 | 
			
		||||
@@ -4,19 +4,19 @@ import status from '../utils/status.js';
 | 
			
		||||
 | 
			
		||||
class GroupService {
 | 
			
		||||
    async create(name, creatorId) {
 | 
			
		||||
        let res = await db.query("INSERT INTO groups (name, admin_id) VALUES ($1, $2) RETURNING ID", [name, creatorId]).catch(errorHandler)
 | 
			
		||||
        let res = await db.query("INSERT INTO groups (name, admin_id) VALUES ($1, $2) RETURNING ID", [name, creatorId]).catch(errorHandler);
 | 
			
		||||
 | 
			
		||||
        return res.rows[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getById(id) {
 | 
			
		||||
        let res = (await db.query("SELECT * FROM groups WHERE id = $1", [id]))
 | 
			
		||||
        let res = (await db.query("SELECT * FROM groups WHERE id = $1", [id]));
 | 
			
		||||
        if (res.rowCount == 0) return status.not_found;
 | 
			
		||||
        return res.rows[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getAdminId(id) {
 | 
			
		||||
        return (await db.query("SELECT admin_id FROM groups WHERE ID = $1", [id])).rows[0].admin_id
 | 
			
		||||
        return (await db.query("SELECT admin_id FROM groups WHERE ID = $1", [id])).rows[0].admin_id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async updatePassword(id, password) {
 | 
			
		||||
@@ -28,7 +28,7 @@ class GroupService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByName(name) {
 | 
			
		||||
        return (await db.query("SELECT * FROM groups WHERE name = $1", [name])).rows[0]
 | 
			
		||||
        return (await db.query("SELECT * FROM groups WHERE name = $1", [name])).rows[0];
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ class ProductService {
 | 
			
		||||
        await db.query("INSERT INTO products (group_id, local_id, abstract_product_id, amount, date_of_production, expiry_date) VALUES ($1, $2, $3, $4, $5, $6)", [groupid, localid, abstract_product_id, amount, date_of_production, expiry_date])
 | 
			
		||||
            .catch((e) => {
 | 
			
		||||
                errorHandler(e, "Abstract Product")
 | 
			
		||||
            })
 | 
			
		||||
            });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async updateAbstractProductId(groupId, localId, abstract_product_id) {
 | 
			
		||||
@@ -29,20 +29,20 @@ class ProductService {
 | 
			
		||||
        await db.query("UPDATE products SET date_of_production = $1 WHERE group_id = $2 AND local_id = $3", [date_of_production, groupId, localId])
 | 
			
		||||
            .catch((e) => {
 | 
			
		||||
                errorHandler(e, "date of production")
 | 
			
		||||
            })
 | 
			
		||||
            });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async updateExpiryDate(groupId, localId, expiry_date) {
 | 
			
		||||
        await db.query("UPDATE products SET expiry_date = $1 WHERE group_id = $2 AND local_id = $3", [expiry_date, groupId, localId])
 | 
			
		||||
            .catch((e) => {
 | 
			
		||||
                errorHandler(e, "expiry date")
 | 
			
		||||
            })
 | 
			
		||||
            });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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) return statuses.not_found;
 | 
			
		||||
        return result
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async exists(groupId, localId) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,14 +5,14 @@ import bcrypt from 'bcrypt';
 | 
			
		||||
class UserService {
 | 
			
		||||
    async create(username, password) {
 | 
			
		||||
        await db.query("INSERT INTO users (username, password) VALUES ($1, $2)", [username, bcrypt.hashSync(password, 12)]).catch((e) => {
 | 
			
		||||
            errorHandler(e, "user")
 | 
			
		||||
            errorHandler(e, "user");
 | 
			
		||||
        })
 | 
			
		||||
        return statuses.ok
 | 
			
		||||
        return statuses.ok;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByUsername(username) {
 | 
			
		||||
        let user = (await db.query("SELECT * FROM Users WHERE username = $1", [username])).rows
 | 
			
		||||
        if (user == undefined) return statuses.not_found
 | 
			
		||||
        let user = (await db.query("SELECT * FROM Users WHERE username = $1", [username])).rows;
 | 
			
		||||
        if (user == undefined) return statuses.not_found;
 | 
			
		||||
        return (user[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user