added 2 new endpoints

This commit is contained in:
2024-11-02 21:51:29 +03:00
parent 07ffeb8de4
commit 317fba81aa
7 changed files with 38 additions and 8 deletions

View File

@@ -46,7 +46,16 @@ class GroupController {
let group = await GroupService.getByName(groupName);
return res.status(200).send(group.id.toString());
return res.status(200).send(group["id"].toString());
}
async getUsersInGroup(req, res) {
const groupId = req.params.groupId;
let result = await GroupService.getUsersInGroup(groupId);
return res.status(200).send(result);
}
}

View File

@@ -1,7 +1,7 @@
import UserService from '../services/user.js';
import log from '../utils/log.js';
import bcrypt from 'bcrypt';
import genToken from '../utils/jwt.js';
import jwtutils from '../utils/jwt.js';
import AbstractProductService from '../services/abstractproduct.js';
import ProductService from '../services/product.js';
import translate from '../utils/translate.js';
@@ -27,7 +27,7 @@ class UserController {
const user = await UserService.getByUsername(username);
if (!bcrypt.compareSync(password, user.password)) throw new customError(`Wrong user password`, responseCodes.responses.passwords.invalid);
const token = genToken(user);
const token = jwtutils.genToken(user);
return res.status(200).send(token);
}
@@ -43,7 +43,7 @@ class UserController {
}
async changeUsername(req, res) {
const userId = jwt.decode(req.headers.authorization.split(' ')[1]).login.id
const userId = jwtutils.getUserIdFromToken(req.headers.authorization.split(' ')[1]);
const { username } = req.body;
await UserService.changeUsername(userId, username);
@@ -52,12 +52,20 @@ class UserController {
}
async changePassword(req, res) {
const userId = jwt.decode(req.headers.authorization.split(' ')[1]).login.id
const userId = jwtutils.getUserIdFromToken(req.headers.authorization.split(' ')[1]);
const { password } = req.body;
await UserService.changePassword(userId, password);
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok))
}
async getAllGroupsForUser(req, res) {
const userId = jwtutils.getUserIdFromToken(req.headers.authorization.split(' ')[1]);
let result = await UserService.getAllGroupsForUser(userId);
return res.status(200).send(result);
}
}
export default new UserController()