added category
This commit is contained in:
		@@ -2,6 +2,7 @@ import UserService from '../services/user.js';
 | 
			
		||||
import GroupService from '../services/group.js';
 | 
			
		||||
import AbstractProductService from '../services/abstractproduct.js';
 | 
			
		||||
import ProductService from '../services/product.js';
 | 
			
		||||
import CategoryService from '../services/category.js';
 | 
			
		||||
import log from '../utils/log.js';
 | 
			
		||||
import statuses from '../utils/status.js';
 | 
			
		||||
 | 
			
		||||
@@ -79,6 +80,26 @@ const productExists = async (req, res, next) => {
 | 
			
		||||
    } catch (e) { return res.status(500).send(log.unknownError(`${TAG}/productExists: ${e}`)) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const categoryNameDoesntExist = async (req, res, next) => {
 | 
			
		||||
    try {
 | 
			
		||||
        const { categoryName, localId, groupId } = req.body;
 | 
			
		||||
 | 
			
		||||
        let result = await CategoryService.getByName(groupId, localId, categoryName);
 | 
			
		||||
        if (result != statuses.not_found) return res.status(400).send("Such category name exists");
 | 
			
		||||
        next();
 | 
			
		||||
    } catch (e) { return res.status(500).send(log.unknownError(`${TAG}/categoryNameDoesntExist: ${e}`)) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const categoryExists = async (req, res, next) => {
 | 
			
		||||
    try {
 | 
			
		||||
        const { localId, groupId } = req.body;
 | 
			
		||||
 | 
			
		||||
        let result = await CategoryService.getById(groupId, localId);
 | 
			
		||||
        if (!result || result == statuses.not_found) return res.status(404).send("No such category");
 | 
			
		||||
        next();
 | 
			
		||||
    } catch (e) { return res.status(500).send(log.unknownError(`${TAG}/categoryExists: ${e}`)) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    usernameExists,
 | 
			
		||||
    usernameDoesntExist,
 | 
			
		||||
@@ -88,5 +109,8 @@ export default {
 | 
			
		||||
    groupNameDoesntExist,
 | 
			
		||||
 | 
			
		||||
    abstractProductExists,
 | 
			
		||||
    productExists
 | 
			
		||||
    productExists,
 | 
			
		||||
 | 
			
		||||
    categoryNameDoesntExist,
 | 
			
		||||
    categoryExists
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user