tested and fixed
This commit is contained in:
		@@ -1,7 +1,5 @@
 | 
			
		||||
import db from '../db.js';
 | 
			
		||||
import statuses from '../utils/status.js';
 | 
			
		||||
import errorHandler from '../utils/pgerrorhandler.js';
 | 
			
		||||
import tryHandler from '../response/errorHandler.js';
 | 
			
		||||
import responses from '../response/responseCodes.js';
 | 
			
		||||
import customError from '../response/customError.js';
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
import db from '../db.js';
 | 
			
		||||
import customError from '../response/customError.js';
 | 
			
		||||
import responseCodes from '../response/responseCodes.js';
 | 
			
		||||
import statuses from '../utils/status.js';
 | 
			
		||||
 | 
			
		||||
class CategoryService {
 | 
			
		||||
    async create(groupId, categoryId, name) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,14 +5,14 @@ import errorHandler from '../utils/pgerrorhandler.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((e) => errorHandler(e, "group"));
 | 
			
		||||
        let res = await db.query("INSERT INTO groups (name, admin_id) VALUES ($1, $2) RETURNING ID", [name, creatorId]).catch((e) => errorHandler(e, "groups"));
 | 
			
		||||
 | 
			
		||||
        return res.rows[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getById(id) {
 | 
			
		||||
        let res = (await db.query("SELECT * FROM groups WHERE id = $1", [id]));
 | 
			
		||||
        if (res.rowCount == 0) throw new customError(`getByUd group not found`, responseCodes.responses.groups.id_not_found);
 | 
			
		||||
        if (res.rowCount == 0) throw new customError(`getById group not found`, responseCodes.responses.groups.id_not_found);
 | 
			
		||||
        return res.rows[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,21 +1,20 @@
 | 
			
		||||
import db from '../db.js'
 | 
			
		||||
import customError from '../response/customError.js';
 | 
			
		||||
import responseCodes from '../response/responseCodes.js';
 | 
			
		||||
import statuses from '../utils/status.js';
 | 
			
		||||
import bcrypt from 'bcrypt';
 | 
			
		||||
import errorHandler from '../utils/pgerrorhandler.js';
 | 
			
		||||
 | 
			
		||||
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");
 | 
			
		||||
        })
 | 
			
		||||
        return statuses.ok;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getByUsername(username) {
 | 
			
		||||
        let user = (await db.query("SELECT * FROM Users WHERE username = $1", [username])).rows;
 | 
			
		||||
        if (user == undefined) throw new customError(`getByUsername user not found`, responseCodes.responses.usernames.not_found);
 | 
			
		||||
        return (user[0]);
 | 
			
		||||
        let user = (await db.query("SELECT * FROM Users WHERE username = $1", [username]));
 | 
			
		||||
        if (user.rowCount == 0) throw new customError(`getByUsername user not found`, responseCodes.responses.usernames.not_found);
 | 
			
		||||
        return user.rows[0];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async getAll() {
 | 
			
		||||
@@ -31,7 +30,6 @@ class UserService {
 | 
			
		||||
    async joinGroup(userId, groupId) {
 | 
			
		||||
        if (await (this.isInGroup(userId, groupId))) throw new customError(`joinGroup user already in group`, responseCodes.responses.user.already_in_group);
 | 
			
		||||
        await db.query("UPDATE Users SET groups = array_append(groups, $1::integer) WHERE ID = $2", [groupId, userId]);
 | 
			
		||||
        return statuses.ok;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user