added endpoints for changing password and username
This commit is contained in:
		@@ -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()
 | 
			
		||||
		Reference in New Issue
	
	Block a user