<commit_before>"use strict";

import http from 'http';
import { Router } from 'express';
import list from './list';
import post from './post';
import put from './put';
import del from './delete';
import patch from './patch';
import get from './get';


const getRouter = (mongooseModel, { url, hooks, actions, options }) => {
  let resourceListURL = `/${url}`;
  let resourceURL = `${resourceListURL}\\(:id\\)`;

  let routes = [
    {
      method: 'post',
      url: resourceListURL,
      ctrl: post,
      hook: hooks.post,
    },
    {
      method: 'put',
      url: resourceURL,
      ctrl: put,
      hook: hooks.put,
    },
    {
      method: 'patch',
      url: resourceURL,
      controller: patch,
      config: hooks.patch,
    },
    {
      method: 'delete',
      url: resourceURL,
      ctrl: del,
      hook: hooks.delete,
    },
    {
      method: 'get',
      url: resourceURL,
      ctrl: get,
      hook: hooks.get,
    },
    {
      method: 'get',
      url: resourceListURL,
      ctrl: list,
      hook: hooks.list,
    },
  ];

  let router = Router();

  // add REST routes.
  routes.map((route) => {
    let { method, url, ctrl, hook } = route;
    router[method](url, (req, res, next) => {
      authorizePipe(req, res, hook.auth)
      .then(function() { return beforePipe(req, res, hook.before); })
      .then(function() { return ctrl(req, mongooseModel, options); })
      .then(function(result) { return respondPipe(req, res, result); })
      .then(function(data) { return afterPipe(req, res, hook.after, data); })
      .catch(function(err) { errorPipe(req, res, err); });
    });
  });

  // add ACTION routes.
  Object.keys(actions).map(function(url) {
    let action = actions[url];
    router.post(`${resourceURL}${url}`, (req, res, next) => {
      authorizePipe(req, res, action.auth).then(function() {
        action(req, res, next);
      }).catch(function(result) { errorPipe(req, res, result); });
    });
  });

  return router;
};

function authorizePipe(req, res, auth) {
  return new Promise((resolve, reject) => {
    if (auth !== undefined) {
      if (!auth(req, res)) {
        return reject({ status: 401 });<commit_msg>fixed delete will return undefined bug.<commit_after>"use strict";

import http from 'http';
import { Router } from 'express';
import list from './list';
import post from './post';
import put from './put';
import del from './delete';
import patch from './patch';
import get from './get';

const getRouter = (mongooseModel, { url, hooks, actions, options }) => {
  let resourceListURL = `/${url}`;
  let resourceURL = `${resourceListURL}\\(:id\\)`;

  let routes = [
    {
      method: 'post',
      url: resourceListURL,
      ctrl: post,
      hook: hooks.post,
    },
    {
      method: 'put',
      url: resourceURL,
      ctrl: put,
      hook: hooks.put,
    },
    {
      method: 'patch',
      url: resourceURL,
      controller: patch,
      config: hooks.patch,
    },
    {
      method: 'delete',
      url: resourceURL,
      ctrl: del,
      hook: hooks.delete,
    },
    {
      method: 'get',
      url: resourceURL,
      ctrl: get,
      hook: hooks.get,
    },
    {
      method: 'get',
      url: resourceListURL,
      ctrl: list,
      hook: hooks.list,
    },
  ];

  let router = Router();

  // add REST routes.
  routes.map((route) => {
    let { method, url, ctrl, hook } = route;
    router[method](url, (req, res, next) => {
      authorizePipe(req, res, hook.auth)
      .then(function() { return beforePipe(req, res, hook.before); })
      .then(function() { return ctrl(req, mongooseModel, options); })
      .then(function(result) { return respondPipe(req, res, result || {}); })
      .then(function(data) { return afterPipe(req, res, hook.after, data); })
      .catch(function(err) { errorPipe(req, res, err); });
    });
  });

  // add ACTION routes.
  Object.keys(actions).map(function(url) {
    let action = actions[url];
    router.post(`${resourceURL}${url}`, (req, res, next) => {
      authorizePipe(req, res, action.auth).then(function() {
        action(req, res, next);
      }).catch(function(result) { errorPipe(req, res, result); });
    });
  });

  return router;
};

function authorizePipe(req, res, auth) {
  return new Promise((resolve, reject) => {
    if (auth !== undefined) {
      if (!auth(req, res)) {
        return reject({ status: 401 });
{'fraction_non_alphanumeric': 0.17263397947548462, 'fraction_numerical': 0.0013683010262257698, 'mean_word_length': 2.5485436893203883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2834833', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1417, 'n_words': 371}