import db from '../db.js'; import customError from '../response/customError.js'; import responseCodes from '../response/responseCodes.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]); } async update(groupId, categoryId, name) { await db.query("UPDATE categories SET name = $1 WHERE group_id = $2 AND local_id = $3", [name, groupId, categoryId]); } 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) throw new customError(`getById categorirs not found`, responseCodes.responses.category.not_found) return result.rows[0]; } async getByName(groupId, localId, name) { let result = (await db.query("SELECT * FROM categories WHERE group_id = $1 AND local_id = $2 AND name = $3", [groupId, localId, name])); if (result.rowCount == 0) throw new customError(`getByName categories not found`, responseCodes.responses.category.not_found) return result.rows[0]; } } export default new CategoryService();