/*
* GPII User Save Handler
*
* Copyright 2013 OCAD University
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The research leading to these results has received funding from the European Union's
* Seventh Framework Programme (FP7/2007-2013)
* under grant agreement no. 289016.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.flowManager");
fluid.defaults("gpii.flowManager.userSave.handler", {
gradeNames: ["kettle.request.http"],
invokers: {
handleRequest: {
funcName: "gpii.flowManager.userSave.handleRequest",
args: [
"{flowManager}.preferencesDataSource",
"{request}.req.params.userToken",
"{request}.req.body",
"{request}"
]
}
}
});
gpii.flowManager.userSave.handleRequest = function (preferencesDataSource, userToken, preferences, request) {
// TODO: Slight faultiness here - we must encode a "missing value" as the empty string, since this value
// is transmitted directly as a URL request parameter to the upstream DataSource. We need to make sure that
// round-tripping via a DataSource's directModel (via "termMap" etc.) is not lossy
userToken = userToken || "";
var directModel = {
userToken: userToken
};
var writeMethod = request.req.method.toUpperCase();
var promise = preferencesDataSource.set(directModel, preferences, { writeMethod: writeMethod });
promise.then(request.events.onSuccess.fire, request.events.onError.fire);
};
|