translated error
This commit is contained in:
		@@ -6,6 +6,7 @@ import AbstractProductService from '../services/abstractproduct.js';
 | 
				
			|||||||
import ProductService from '../services/product.js';
 | 
					import ProductService from '../services/product.js';
 | 
				
			||||||
import translate from '../utils/translate.js';
 | 
					import translate from '../utils/translate.js';
 | 
				
			||||||
import responseCodes from '../response/responseCodes.js';
 | 
					import responseCodes from '../response/responseCodes.js';
 | 
				
			||||||
 | 
					import customError from '../response/customError.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TAG = "/controllers/userjs"
 | 
					const TAG = "/controllers/userjs"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -23,7 +24,7 @@ class UserController {
 | 
				
			|||||||
        const { username, password } = req.body;
 | 
					        const { username, password } = req.body;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const user = await UserService.getByUsername(username);
 | 
					        const user = await UserService.getByUsername(username);
 | 
				
			||||||
        if (!bcrypt.compareSync(password, user.password)) return res.status(401).send("Wrong password");
 | 
					        if (!bcrypt.compareSync(password, user.password)) throw new customError(`Wrong user password`, responseCodes.responses.passwords.invalid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const token = genToken(user);
 | 
					        const token = genToken(user);
 | 
				
			||||||
        return res.status(200).send(token);
 | 
					        return res.status(200).send(token);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ import errorHandler from '../utils/pgerrorhandler.js';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class UserService {
 | 
					class UserService {
 | 
				
			||||||
    async create(username, password) {
 | 
					    async create(username, password) {
 | 
				
			||||||
 | 
					        if (await this.getByUsername(username)) throw new customError(`Such user exists`, responseCodes.responses.user.duplicate);
 | 
				
			||||||
        await db.query("INSERT INTO users (username, password) VALUES ($1, $2)", [username, bcrypt.hashSync(password, 12)]).catch((e) => {
 | 
					        await db.query("INSERT INTO users (username, password) VALUES ($1, $2)", [username, bcrypt.hashSync(password, 12)]).catch((e) => {
 | 
				
			||||||
            errorHandler(e, "user");
 | 
					            errorHandler(e, "user");
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user