Skip to content

Commit

Permalink
fix for #2294
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Jul 15, 2016
1 parent 7d234e0 commit 20cd7eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
9 changes: 8 additions & 1 deletion spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ describe('Cloud Code', () => {
expect(req.params.complexStructure.deepDate.date[0].getTime()).toBe(1463907600000);
expect(req.params.complexStructure.deepDate2[0].date instanceof Date).toBe(true);
expect(req.params.complexStructure.deepDate2[0].date.getTime()).toBe(1463907600000);
expect(req.params.file instanceof Parse.File).toBe(true);
expect(req.params.file.url()).toEqual('https://some.url');
return res.success({});
});

Expand Down Expand Up @@ -361,7 +363,12 @@ describe('Cloud Code', () => {
}
}
]
}
},
'file': Parse.File.fromJSON({
__type: 'File',
name: 'name',
url: 'https://some.url'
})
};
Parse.Cloud.run('params', params).then((result) => {
done();
Expand Down
36 changes: 17 additions & 19 deletions src/Routers/FunctionsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ var express = require('express'),
import PromiseRouter from '../PromiseRouter';
import _ from 'lodash';

function parseDate(params) {
return _.mapValues(params, (obj) => {
if (Array.isArray(obj)) {
function parseObject(obj) {
if (Array.isArray(obj)) {
return obj.map((item) => {
if (item && item.__type == 'Date') {
return new Date(item.iso);
} else if (item && typeof item === 'object') {
return parseDate(item);
} else {
return item;
}
return parseObject(item);
});
} else if (obj && obj.__type == 'Date') {
return new Date(obj.iso);
} else if (obj && typeof obj === 'object') {
return parseDate(obj);
} else {
return obj;
}
});
} else if (obj && obj.__type == 'Date') {
return new Date(obj.iso);
} else if (obj && obj.__type == 'File') {
return Parse.File.fromJSON(obj);
} else if (obj && typeof obj === 'object') {
return parseParams(obj);
} else {
return obj;
}
}

function parseParams(params) {
return _.mapValues(params, parseObject);
}

export class FunctionsRouter extends PromiseRouter {
Expand Down Expand Up @@ -60,7 +58,7 @@ export class FunctionsRouter extends PromiseRouter {
var theValidator = triggers.getValidator(req.params.functionName, applicationId);
if (theFunction) {
let params = Object.assign({}, req.body, req.query);
params = parseDate(params);
params = parseParams(params);
var request = {
params: params,
master: req.auth && req.auth.isMaster,
Expand Down

0 comments on commit 20cd7eb

Please sign in to comment.