jesuspc / node_club-dictionaries

A dictionaries microservices for Workshare's Node club
1 stars 0 forks source link

Parameterize for upsert action #14

Closed jesuspc closed 8 years ago

jesuspc commented 8 years ago

In the current implementation of the API we have a bunch of code like that:

router.put('/:scope/:uuid/dictionaries/:name.json', parameterize, authorize, function(req, res, next) {
    var upsertParameterizer = function(dictionaryData, params){
      var filters = {'meta.uuid': params.uuid, 'meta.scope': params.scope, name: params.name};
      if (!dictionaryData.name){
        dictionaryData.name = params.name;
      }
      return {
        filters: filters,
        dictionaryData: dictionaryData
      };
    };

We need to extract that upsterParameterizer into a middleware we would pipe into the middlewares for that route. Maybe it is worth to change the name into something generic for write actions.

So that task consists in moving the function into the parameterizers module and inject it properly into the API. Also unit tests for the function should be added.