
const {httpStatus} = require("../helpers/httpResponses");

function checkJson(req, res, next) {
    if(req.method === 'GET'){
        next()
    }

    if (['POST', 'PUT', 'PATCH'].includes(req.method) && req.headers['content-type'] !== 'application/json') {
        return res.status(httpStatus.BAD_REQUEST).json({message: "Body missing in action."});
    }

    next();
}

module.exports = checkJson;