示例#1
0
   parseCriteria: function (child) {
 
     // Allow customizable blacklist for params NOT to include as criteria.
     options.criteria = options.criteria || {};
     options.criteria.blacklist = options.criteria.blacklist || ['limit', 'skip', 'sort', 'populate'];
 
     // Validate blacklist to provide a more helpful error msg.
     var blacklist = options.criteria && options.criteria.blacklist;
     
     Hoek.assert(_.isArray(blacklist), 'Invalid `options.criteria.blacklist`. Should be an array of strings (parameter names.)');
 
     // Look for explicitly specified `where` parameter.
     var where = request.query.where;
 
     // If `where` parameter is a string, try to interpret it as JSON
     if (_.isString(where)) {
       where = tryToParseJSON(where);
     }
 
     // If `where` has not been specified, but other unbound parameter variables
     // **ARE** specified, build the `where` option using them.
     if (!where) {
 
       // Prune params which aren't fit to be used as `where` criteria
       // to build a proper where query
       where = request.query;
 
       // Omit built-in runtime config (like query modifiers)
       where = _.omit(where, blacklist || ['limit', 'skip', 'sort']);
 
       // Omit any params w/ undefined values
       where = _.omit(where, function (p){ return _.isUndefined(p); });
 
       // Omit jsonp callback param (but only if jsonp is enabled)
       if (request.route.jsonp) {
         delete where[request.route.jsonp]
       }
     }
 
     // Merge w/ options.where and return
     where = _.merge({}, options.where || {}, where) || undefined;
     
     // Deal with ownership
     if (options.actAsUser && options.requireOwner) {
       
       // Grab appropriate transformation object
       var ownerAttrTransformation = child ? options.childOwnerAttrs : options.ownerAttrs;
       Hoek.assert(_.isObject(ownerAttrTransformation), 'Owner attribute options (`options.childOwnerAttr`/`options.ownerAttr`/`options.childOwnerAttrs`/`options.ownerAttrs`) should be set for use with `options.requireOwner`.');
       
       // Get new values with transformation
       var requireWhere = Hoek.transform(request.auth.credentials, ownerAttrTransformation);
       
       _.merge(where, requireWhere);
       
     }
     
     return where;
   },
示例#2
0
        .then(function(data){

            if (data.length === 0) {
                throw Boom.notFound("The resource does not exist.");
            }

            data = args.raw === true ? data : Hoek.transform(data, internals.transformMap);
            return done(null, data);
        })
示例#3
0
	transformArray: function(array, transformMap, options){
	    if(!_.isArray(array)){ array = [array]; }		

	    var i, li;
        for(i=0, li=array.length; i<li; i++){ 
            array[i] = Hoek.transform(array[i], transformMap, options);
        }

        return array;
	},
示例#4
0
        .then(function(deletedData){
            debugger;
            // this should never happen, but we check anyway
            if (deletedData.length === 0) {
                throw Boom.notFound("The resource was created/updated but does not exist anymore.");
            }

            deletedData = (args.raw === true) ? 
                                        deletedData : 
                                        Hoek.transform(deletedData, internals.fromDbToPublicAPI);

            return done(null, deletedData);
        })
示例#5
0
        .then(function(upsertedData){

            // this is very unlikely to happen, but we check anyway
            if (upsertedData.length === 0) {
                throw Boom.notFound("The resource was created/updated but does not exist anymore.");
            }

            upsertedData = (args.raw === true) ? 
                                        upsertedData : 
                                        Hoek.transform(upsertedData, internals.fromDbToPublicAPI);

            return done(null, upsertedData);
        })
示例#6
0
 validOwnership: function(record, child) {
   
   if (!options.actAsUser || !options.requireOwner) {
     return true;
   }
   
   // Grab appropriate transformation object
   var ownerAttrTransformation = child ? options.childOwnerAttrs : options.ownerAttrs;
   Hoek.assert(_.isObject(ownerAttrTransformation), 'Owner attribute options (`options.childOwnerAttr`/`options.ownerAttr`/`options.childOwnerAttrs`/`options.ownerAttrs`) should be set for use with `options.requireOwner`.');
   
   // There're no owner attrs set for this record
   if (_.isEmpty(ownerAttrTransformation)) {
     return true;
   }
   
   // Get new values with transformation
   var requiredValues = Hoek.transform(request.auth.credentials, ownerAttrTransformation);
   
   // Check for a non-match
   var requiredValue, recordOwnerValue;
   for (var attributeName in requiredValues) {
     requiredValue = requiredValues[attributeName];
     
     recordOwnerValue = record[attributeName];
     Hoek.assert(!_.isUndefined(recordOwnerValue), 'Record does not have provided owner attribute `' + attributeName + '`.')
     
     if (recordOwnerValue != requiredValue) {
       return false;
     }
     
   }
   
   // Passed all the tests.
   return true;
   
 },
示例#7
0
   parseValues: function (child) {
 
     // Allow customizable blacklist for params NOT to include as values.
     options.values = options.values || {};
 
     // Validate blacklist to provide a more helpful error msg.
     var blacklist = options.values.blacklist || [];
     Hoek.assert(_.isArray(blacklist), 'Invalid `options.values.blacklist`. Should be an array of strings (parameter names.)');
 
     // Merge payload into req.options.values, omitting the blacklist.
     var values = mergeDefaults(_.cloneDeep(request.payload), _.omit(options.values, 'blacklist'));
 
     // Omit values that are in the blacklist (like query modifiers)
     values = _.omit(values, blacklist);
 
     // Omit any values w/ undefined values
     values = _.omit(values, function (p){ return _.isUndefined(p); });
     
     // Set owner value if we ought
     if (options.actAsUser &&
         options.setOwner) {
       
       // Grab appropriate transformation object
       var ownerAttrTransformation = child ? options.childOwnerAttrs : options.ownerAttrs;
       Hoek.assert(_.isObject(ownerAttrTransformation), 'Owner attribute options (`options.childOwnerAttr`/`options.ownerAttr`/`options.childOwnerAttrs`/`options.ownerAttrs`) should be set for use with `options.setOwner`.');
       
       // Get new values with transformation
       var newValues = Hoek.transform(request.auth.credentials, ownerAttrTransformation);
       
       // Set new values
       _.merge(values, newValues);
       
     }
     
     return values;
   },
示例#8
0
        .then(function(data) {

            data = args.raw === true ? data : Hoek.transform(data, internals.transformMap);
            return done(null, data);
        })
var Fs = require("fs");
var Xlsx = require("xlsx");
var Hoek = require('hoek');

var file = 'CATALISE_RC_mapa_V8';
var workbook = Xlsx.readFile(file + '.xls');

var worksheet = workbook.Sheets[workbook.SheetNames[0]];

var keyTransform = {
	"projectName": "projectname",
	"network": "rededeorigem",
	"url": "projecturl",
	"studyCase": "casodeestudo",
	"lat": "lat",
	"lng": "lng"
};

var outputData = Hoek.transform(Xlsx.utils.sheet_to_json(worksheet), keyTransform);

Fs.writeFileSync(file.toLowerCase() + ".json", JSON.stringify(outputData, null, 4));
//debugger;



示例#10
0
        .then(function(data) {

            data = args.raw === true ? data : Hoek.transform(data, internals.fromDbToPublicAPI);
            return done(null, data);
        })
示例#11
0
            tags: Transformer.getTags(sails),
            definitions: Transformer.getDefinitions(sails),
            paths: Transformer.getPaths(sails)
        }
    },

    /**
     * Convert a package.json file into a Swagger Info Object
     * http://swagger.io/specification/#infoObject
     */
    getInfo(pkg) {
        return hoek.transform(pkg, {
            'title': 'name',
            'description': 'description',
            'version': 'version',

            'contact.name': 'author',
            'contact.url': 'homepage',

            'license.name': 'license'
        })
    },

    /**
     * http://swagger.io/specification/#tagObject
     */
    getTags(sails) {
        return _.map(_.pluck(sails.controllers, 'globalId'), tagName => {
            return {
                name: tagName
                    //description: `${tagName} Controller`
            }