const { sendResponse } = require('../helpers/responseHelper');
const {httpStatus, httpStatusMessages} = 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 sendResponse(res, httpStatus.BAD_REQUEST, httpStatusMessages[httpStatus.BAD_REQUEST]);
    }

    next();
}

module.exports = checkJson;