a lot of fixes, implementing abstract product api endpoints

This commit is contained in:
2024-10-26 20:18:14 +03:00
parent e78f20d44e
commit a27ce5762c
11 changed files with 112 additions and 34 deletions

View File

@@ -0,0 +1,14 @@
import AbstractProductService from '../services/abstractproduct.js';
const TAG = "/controllers/abstractproduct.js"
class AbstractProductController {
async create(req, res) {
const { groupId, barcode, name, net_weight, image_filename, category, unit } = req.body;
// console.log(groupId, barcode, name, net_weight, image_filename, category, unit)
await AbstractProductService.create(groupId, barcode, name, net_weight, image_filename, category, unit);
return res.status(200).send("Successfull");
}
};
export default new AbstractProductController();

View File

@@ -10,12 +10,12 @@ const TAG = "/controllers/group.js"
class GroupController {
async create(req, res) {
try {
let { name } = req.params;
let { groupName } = req.params;
let user = jwt.decode(req.headers.authorization.split(' ')[1], config.secret);
let status = await GroupService.create(name, user.login.id);
let status = await GroupService.create(groupName, user.login.id);
log.info(`New group with name ${name} was just created by user ${user.login.username}`);
log.info(`New group with name ${groupName} was just created by user ${user.login.username}`);
UserService.joinGroup(user.login.id, status.id);
return res.status(200).send("Successfull");
@@ -23,27 +23,25 @@ class GroupController {
}
async join(req, res) {
try {
let { id } = req.params;
await GroupService.getById(id);
let { groupId } = req.params;
let user = jwt.decode(req.headers.authorization.split(' ')[1], config.secret);
let status = await UserService.joinGroup(user.login.id, id);
let status = await UserService.joinGroup(user.login.id, groupId);
if (status == statuses.duplicate) return res.status(400).send("Already in group");
log.info(`User ${user.login.username} has just joined group with ID ${id}`);
log.info(`User ${user.login.username} has just joined group with ID ${groupId}`);
return res.status(200).send("Successfull");
} catch (e) { return res.status(500).send(log.unknownError(`${TAG}/join: ${e}`)); }
}
async updatePassword(req, res) {
try {
let { id } = req.params;
let { groupId } = req.params;
let { password } = req.body;
await GroupService.updatePassword(id, password);
log.info(`Password for group with ID ${id} was updated`);
await GroupService.updatePassword(groupId, password);
log.info(`Password for group with ID ${groupId} was updated`);
return res.status(200).send("Successfull");
} catch (e) { return res.status(500).send(log.unknownError(`${TAG}/updatePassword ${e}`)); }