NOOB: Help with simple preprocess script

Hello -

I want to create a simple preprocess script that will read in the query parameters, test for their existence and then to create a filter based upon the parameters. My script never seems to run anything.

var params, required, anon, lastsync, resource, result;
var lodash = require("lodash.min.js");
 

// get query params from request
params = event.request.parameters;

// get resource, /math β€”> "", /math/add β€”> "add"  ?
resource = event.resource;
if (resource !== "") {
    // check for required params
    required = ["anon","lastsync"];
    lodash._.each( required, function( element ) {
    if (!params.hasOwnProperty(element) || !params[element]) {
        throw( "Missing '" + element + "' in params\n" );
    }
});
    anon = Number(params.anon);
    lastsync = Number(params.lastsync);

    //WHAT DO I DO WITH THIS?
    //event.request.body.filter = 'id = 1';
    event.request.parameters["filter"]= UNIX_TIMESTAMP(lastUpdate)+" > "+UNIX_TIMESTAMP(lastsync);

}   

What am I doing wrong?

This worked for me…

var params, required, anon, lastsync, resource;
var lodash = require("lodash.min.js");


// get query params from request
params = event.request.parameters;

resource = event.resource;

if (resource !== "") {
    // check for required params
    required = ["anon","lastsync"];
    lodash._.each( required, function( element ) {
    if (!params.hasOwnProperty(element) || !params[element]) {
        throw( "Missing '" + element + "' in params\n" );
    }
});
anon = (params.anon);
lastsync = (params.lastsync);

//Create filter and pass along:
event.request.parameters["filter"]='lastUpdate > '+lastsync;
}
2 Likes