check for group name
This commit is contained in:
		@@ -11,6 +11,15 @@ const groupExists = async (req, res, next) => {
 | 
				
			|||||||
    next();
 | 
					    next();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const groupNameExists = async (req, res, next) => {
 | 
				
			||||||
 | 
					    let groupName = req.params.groupName || req.body.groupName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let group = await GroupService.getByName(groupName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!group) throw new customError(`group does not exists`, responseCodes.responses.groups.name_not_found);
 | 
				
			||||||
 | 
					    next();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const localIdExists = async (req, res, next) => {
 | 
					const localIdExists = async (req, res, next) => {
 | 
				
			||||||
    let localId = req.params.localId || req.body.localId;
 | 
					    let localId = req.params.localId || req.body.localId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -18,4 +27,5 @@ const localIdExists = async (req, res, next) => {
 | 
				
			|||||||
    next();
 | 
					    next();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default { groupExists, localIdExists }
 | 
					
 | 
				
			||||||
 | 
					export default { groupExists, localIdExists, groupNameExists }
 | 
				
			||||||
@@ -9,6 +9,6 @@ const GroupRouter = new Router();
 | 
				
			|||||||
GroupRouter.post('/create/:groupName', tryHandler(auth.authenticate), tryHandler(GroupController.create));
 | 
					GroupRouter.post('/create/:groupName', tryHandler(auth.authenticate), tryHandler(GroupController.create));
 | 
				
			||||||
GroupRouter.post('/join/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.requirePassword), tryHandler(auth.checkGroupPassword), tryHandler(GroupController.join));
 | 
					GroupRouter.post('/join/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.requirePassword), tryHandler(auth.checkGroupPassword), tryHandler(GroupController.join));
 | 
				
			||||||
GroupRouter.post('/password/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.authorizeGroupOwner), tryHandler(auth.requirePassword), tryHandler(GroupController.updatePassword));
 | 
					GroupRouter.post('/password/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.authorizeGroupOwner), tryHandler(auth.requirePassword), tryHandler(GroupController.updatePassword));
 | 
				
			||||||
GroupRouter.get('/byName/:groupName', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(GroupController.getByName))
 | 
					GroupRouter.get('/byName/:groupName', tryHandler(auth.authenticate), tryHandler(existance.groupNameExists), tryHandler(GroupController.getByName))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default GroupRouter;
 | 
					export default GroupRouter;
 | 
				
			||||||
		Reference in New Issue
	
	Block a user