Centralized errors and added their translations. Didn't test
This commit is contained in:
		@@ -1,9 +1,9 @@
 | 
			
		||||
import { Router } from 'express';
 | 
			
		||||
import auth from '../middlewares/auth.js';
 | 
			
		||||
import AbstractProductController from '../controllers/abstractproduct.js';
 | 
			
		||||
import existance from '../middlewares/existance.js';
 | 
			
		||||
import multer from 'multer';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
import tryHandler from '../response/errorHandler.js';
 | 
			
		||||
 | 
			
		||||
const upload = multer(({
 | 
			
		||||
    dest: path.join(path.resolve(path.dirname('')), "/temp")
 | 
			
		||||
@@ -11,7 +11,7 @@ const upload = multer(({
 | 
			
		||||
 | 
			
		||||
const AbstractProductRouter = new Router();
 | 
			
		||||
 | 
			
		||||
AbstractProductRouter.post('/create', upload.single("file"), auth.authenticate, existance.groupExists, auth.userIsInGroup, AbstractProductController.create);
 | 
			
		||||
AbstractProductRouter.post('/update', upload.single("file"), auth.authenticate, existance.groupExists, auth.userIsInGroup, existance.abstractProductExists, AbstractProductController.update);
 | 
			
		||||
AbstractProductRouter.post('/create', upload.single("file"), tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(AbstractProductController.create));
 | 
			
		||||
AbstractProductRouter.post('/update', upload.single("file"), tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(AbstractProductController.update));
 | 
			
		||||
 | 
			
		||||
export default AbstractProductRouter;
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
import { Router } from 'express';
 | 
			
		||||
import auth from '../middlewares/auth.js';
 | 
			
		||||
import existance from '../middlewares/existance.js';
 | 
			
		||||
import CategoryController from '../controllers/category.js';
 | 
			
		||||
import tryHandler from '../response/errorHandler.js';
 | 
			
		||||
 | 
			
		||||
const CategoryRouter = new Router();
 | 
			
		||||
 | 
			
		||||
CategoryRouter.post('/create', auth.authenticate, existance.groupExists, existance.categoryNameDoesntExist, CategoryController.create);
 | 
			
		||||
CategoryRouter.post('/update', auth.authenticate, existance.groupExists, existance.categoryExists, CategoryController.update);
 | 
			
		||||
CategoryRouter.post('/create', tryHandler(auth.authenticate), tryHandler(CategoryController.create));
 | 
			
		||||
CategoryRouter.post('/update', tryHandler(auth.authenticate), tryHandler(CategoryController.update));
 | 
			
		||||
 | 
			
		||||
export default CategoryRouter;
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import { Router } from 'express';
 | 
			
		||||
import auth from '../middlewares/auth.js';
 | 
			
		||||
import GroupController from '../controllers/group.js';
 | 
			
		||||
import existance from '../middlewares/existance.js';
 | 
			
		||||
import tryHandler from '../response/errorHandler.js';
 | 
			
		||||
 | 
			
		||||
const GroupRouter = new Router();
 | 
			
		||||
 | 
			
		||||
GroupRouter.post('/create/:groupName', auth.authenticate, existance.groupNameDoesntExist, GroupController.create);
 | 
			
		||||
GroupRouter.post('/join/:groupId', auth.authenticate, existance.groupExists, auth.requirePassword, auth.checkGroupPassword, GroupController.join);
 | 
			
		||||
GroupRouter.post('/password/:groupId', auth.authenticate, existance.groupExists, auth.authorizeGroupOwner, auth.requirePassword, GroupController.updatePassword);
 | 
			
		||||
GroupRouter.post('/create/:groupName', tryHandler(auth.authenticate), tryHandler(GroupController.create));
 | 
			
		||||
GroupRouter.post('/join/:groupId', tryHandler(auth.authenticate), tryHandler(auth.requirePassword), tryHandler(auth.checkGroupPassword), tryHandler(GroupController.join));
 | 
			
		||||
GroupRouter.post('/password/:groupId', tryHandler(auth.authenticate), tryHandler(auth.authorizeGroupOwner), tryHandler(auth.requirePassword), tryHandler(GroupController.updatePassword));
 | 
			
		||||
 | 
			
		||||
export default GroupRouter;
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
import { Router } from 'express';
 | 
			
		||||
import auth from '../middlewares/auth.js';
 | 
			
		||||
import ProductController from '../controllers/product.js'
 | 
			
		||||
import existance from '../middlewares/existance.js';
 | 
			
		||||
import tryHandler from '../response/errorHandler.js';
 | 
			
		||||
 | 
			
		||||
const ProductRouter = new Router();
 | 
			
		||||
 | 
			
		||||
ProductRouter.post('/create', auth.authenticate, existance.groupExists, auth.userIsInGroup, ProductController.create);
 | 
			
		||||
ProductRouter.post('/update', auth.authenticate, existance.groupExists, auth.userIsInGroup, existance.productExists, ProductController.update);
 | 
			
		||||
ProductRouter.post('/create', tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(ProductController.create));
 | 
			
		||||
ProductRouter.post('/update', tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(ProductController.update));
 | 
			
		||||
 | 
			
		||||
export default ProductRouter;
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import { Router } from 'express';
 | 
			
		||||
import auth from '../middlewares/auth.js';
 | 
			
		||||
import existance from '../middlewares/existance.js';
 | 
			
		||||
import UserController from '../controllers/user.js';
 | 
			
		||||
import tryHandler from '../response/errorHandler.js';
 | 
			
		||||
 | 
			
		||||
const UserRouter = new Router();
 | 
			
		||||
 | 
			
		||||
UserRouter.post('/register', auth.requireUsername, auth.requirePassword, existance.usernameDoesntExist, UserController.register);
 | 
			
		||||
UserRouter.post('/login', auth.requireUsername, auth.requirePassword, existance.usernameExists, UserController.login);
 | 
			
		||||
UserRouter.get('/synchronize/:groupId', auth.authenticate, existance.groupExists, auth.userIsInGroup, UserController.synchronize);
 | 
			
		||||
UserRouter.post('/register', tryHandler(auth.requireUsername), tryHandler(auth.requirePassword), tryHandler(UserController.register));
 | 
			
		||||
UserRouter.post('/login', tryHandler(auth.requireUsername), tryHandler(auth.requirePassword), tryHandler(UserController.login));
 | 
			
		||||
UserRouter.get('/synchronize/:groupId', tryHandler(auth.authenticate), tryHandler(auth.userIsInGroup), tryHandler(UserController.synchronize));
 | 
			
		||||
 | 
			
		||||
export default UserRouter;
 | 
			
		||||
		Reference in New Issue
	
	Block a user