a lot of bugfixes, completed abstract products and products
This commit is contained in:
		@@ -10,9 +10,9 @@ const requireUsername = async (req, res, next) => {
 | 
			
		||||
    if (req.method == "OPTIONS") next();
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
        const {username} = req.body;
 | 
			
		||||
            if (!username) return res.status(400).send("Username is required");
 | 
			
		||||
            next();
 | 
			
		||||
        const { username } = req.body;
 | 
			
		||||
        if (!username) return res.status(400).send("Username is required");
 | 
			
		||||
        next();
 | 
			
		||||
    } catch (e) { return res.status(500).send(unknownError(`${TAG}/requireUsername: ${e}`)); }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -20,9 +20,9 @@ const requirePassword = async (req, res, next) => {
 | 
			
		||||
    if (req.method == "OPTIONS") next();
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
        const {password} = req.body;
 | 
			
		||||
            if (!password) return res.status(400).send("Password is required");
 | 
			
		||||
            next();
 | 
			
		||||
        const { password } = req.body;
 | 
			
		||||
        if (!password) return res.status(400).send("Password is required");
 | 
			
		||||
        next();
 | 
			
		||||
    } catch (e) { return res.status(500).send(unknownError(`${TAG}/requirePassword: ${e}`)); }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -48,7 +48,7 @@ const authorizeGroupOwner = async (req, res, next) => {
 | 
			
		||||
        const { groupId } = req.params;
 | 
			
		||||
 | 
			
		||||
        let user = jwt.decode(token, config.secret)
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        let adminId = await GroupService.getAdminId(groupId);
 | 
			
		||||
        if (user.login.id != adminId) return res.status(403).send("Not your group");
 | 
			
		||||
        next();
 | 
			
		||||
@@ -67,7 +67,7 @@ const checkGroupPassword = async (req, res, next) => {
 | 
			
		||||
        if (groupPassword != password) return res.status(403).send("Wrong password");
 | 
			
		||||
        next();
 | 
			
		||||
 | 
			
		||||
    } catch (e) {return res.status(500).send(log.unknownError(`${TAG}/checkGroupPassword: ${e}`));}
 | 
			
		||||
    } catch (e) { return res.status(500).send(log.unknownError(`${TAG}/checkGroupPassword: ${e}`)); }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const userIsInGroup = async (req, res, next) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,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 log from '../utils/log.js';
 | 
			
		||||
import statuses from '../utils/status.js';
 | 
			
		||||
 | 
			
		||||
@@ -57,4 +59,34 @@ const groupNameDoesntExist = async (req, res, next) => {
 | 
			
		||||
    } catch (e) { return res.status(500).send(log.unknownError(`${TAG}/groupNameDoesntExist: ${e}`)) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default { usernameExists, usernameDoesntExist, groupExists, groupDoesntExist, groupNameDoesntExist }
 | 
			
		||||
const abstractProductExists = async (req, res, next) => {
 | 
			
		||||
    try {
 | 
			
		||||
        const { groupId, localId } = req.body;
 | 
			
		||||
 | 
			
		||||
        let result = await AbstractProductService.exists(groupId, localId);
 | 
			
		||||
        if (!result) return res.status(404).send("Abstract product not found");
 | 
			
		||||
        next();
 | 
			
		||||
    } catch (e) { return res.status(500).send(log.unknownError(`${TAG}/abstractProductExists: ${e}`)) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const productExists = async (req, res, next) => {
 | 
			
		||||
    try {
 | 
			
		||||
        const { groupId, localId } = req.body;
 | 
			
		||||
 | 
			
		||||
        let result = await ProductService.exists(groupId, localId);
 | 
			
		||||
        if (!result) return res.status(404).send("Product not found");
 | 
			
		||||
        next();
 | 
			
		||||
    } catch (e) { return res.status(500).send(log.unknownError(`${TAG}/productExists: ${e}`)) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    usernameExists,
 | 
			
		||||
    usernameDoesntExist,
 | 
			
		||||
 | 
			
		||||
    groupExists,
 | 
			
		||||
    groupDoesntExist,
 | 
			
		||||
    groupNameDoesntExist,
 | 
			
		||||
 | 
			
		||||
    abstractProductExists,
 | 
			
		||||
    productExists
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user