added endpoints for changing password and username

This commit is contained in:
2024-11-02 01:36:25 +03:00
parent afa1edeb8d
commit 02b1a572d1
3 changed files with 28 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import ProductService from '../services/product.js';
import translate from '../utils/translate.js';
import responseCodes from '../response/responseCodes.js';
import customError from '../response/customError.js';
import jwt from 'jsonwebtoken';
const TAG = "/controllers/userjs"
@@ -40,6 +41,23 @@ class UserController {
return res.status(200).send(result);
}
async changeUsername(req, res) {
const userId = jwt.decode(req.headers.authorization.split(' ')[1]).login.id
const { username } = req.body;
await UserService.changeUsername(userId, username);
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok))
}
async changePassword(req, res) {
const userId = jwt.decode(req.headers.authorization.split(' ')[1]).login.id
const { password } = req.body;
await UserService.changePassword(userId, password);
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok))
}
}
export default new UserController()