{"size": 842, "ext": "js", "max_stars_repo_path": "lib/router/utils/check-update.js", "max_stars_repo_name": "dylnslck/restle", "max_stars_repo_stars_event_min_datetime": "2016-01-24T13:12:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-02-06T03:13:36.000Z", "max_issues_repo_path": "lib/router/utils/check-update.js", "max_issues_repo_name": "dylnslck/restle", "max_issues_repo_issues_event_min_datetime": "2016-02-12T18:09:43.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-12T23:09:49.000Z", "max_forks_repo_path": "lib/router/utils/check-update.js", "max_forks_repo_name": "dylnslck/restle", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 24.0571428571, "max_line_length": 101, "alphanum_fraction": 0.6413301663}
import { BadRequestError, ConflictError } from 'restle-error';

/**
 * Checks if the incoming request data is not conflicting.
 *
 * @private
 * @param {Object} req
 * @param {Object} res
 * @return {Boolean}
 */
export default function checkPost(req, res) {
  if (!(req.body && req.body.data && req.body.data.type)) {
    const badRequestError = new BadRequestError({
      detail: `A primary data object with a matching type key is required when creating a resource.`,
    });

    return {
      status: badRequestError.status,
      json: badRequestError.serialize(),
    }
  }

  if (req.params.id !== req.body.data.id) {
    const conflictError = new ConflictError({
      first: req.params.id,
      second: req.body.data.id,
    });

    return {
      status: conflictError.status,
      json: conflictError.serialize(),
    }
  }
}
