import {Orders} from "../../models/index";
import {roles} from "../../utils/constans/signUp";

module.exports = (req, res, next) => {

    if(req.body.role == roles.ADMIN && req.body.decryptedData) {

        Orders.destroy({
            where: {
                id: req.params.id
            }
        }).then(() => {
            next();
        }).catch(err => {
            next(err);
        })
    }else {

        Orders.destroy({
            where: {
                userId: req.body.id,
                goodsId: req.params.id
            }
        }).then(() => {
            next();
        }).catch(err => {
            next(err);
        })
    }
};