/**
 * Create a map of values between Elvis and Serviceprovider. Using the schema definition as default, and override
 * specified values.
 *
 * @param schema {Object} Schema definition.
 * @param remap {Object} Values to override.
 * @returns {Object} Map.
 */
function createMap(schema, remap) {
  const schemaMap = {};
  // Map property keys to values as default.
  Object.keys(schema.properties).forEach(key => {schemaMap[key] = key;});

  // Override with remap values.
  return Object.assign(schemaMap, remap);
}

/**
 * Add CRUD capabilities to Entity type.
 *
 * @param type {String} Entity type e.g. group.
 * @param router {Object} Router add CRUD methods to.
 * @param utils {Object} Object for mapping and validating values between Elvis and Serviceprovider objects.
 * @returns {Object} Router.
 */
export default function createCRUD(elvisType, type, router, remap, schema) {
  const request = (req, res, crudType) => {
    const provider = req.app.get('serviceProvider');
    return provider.execute('entityRequest', {
      type: crudType,
      createTest: req.query.createTest,
      query: req.query,
      body: req.body,
      params: req.params,
      etParams: {
        type,
        elvisType,
        schemaMap: createMap(schema, remap),
        schema
      }
    }, req.context);
  };

  // Setup CRUD transport
  router.all('/:id?', (req, res) => {
    const provider = req.app.get('serviceProvider');
    const context = req.context;
    context.crud = true;

    const query = Object.assign(
      {},
      req.params,
      req.body,
      req.query,
      {_meta: {type, elvisType, schemaMap: createMap(schema, remap), schema}}
    );

    let event;
    switch (req.method) {
      case 'GET': {
        event = req.params.id ? 'getEntity' : 'listEntities';
        break;
      }
      case 'PUT': {
        event = 'updateEntity';
        break;
      }
      case 'POST': {
        event = 'createEntity';
        break;
      }
      case 'DELETE': {
        event = 'deleteEntity';
        break;
      }
      default: {
        break;
      }
    }

    provider.execute(event, query, context).then(result => res.json(result));
  });

  return router;
}

@@ -887,431 +887,8 @@
  %7B%0A 
- const request = (req, res, crudType) =%3E %7B%0A    const provider = req.app.get('serviceProvider');%0A    return provider.execute('entityRequest', %7B%0A      type: crudType,%0A      createTest: req.query.createTest,%0A      query: req.query,%0A      body: req.body,%0A      params: req.params,%0A      etParams: %7B%0A        type,%0A        elvisType,%0A        schemaMap: createMap(schema, remap),%0A        schema%0A      %7D%0A    %7D, req.context);%0A  %7D;%0A%0A
   //

remove unused code