diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index 3177462456..731d877735 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -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({}); }); @@ -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(); diff --git a/src/Routers/FunctionsRouter.js b/src/Routers/FunctionsRouter.js index 197536654b..b29aa99a8c 100644 --- a/src/Routers/FunctionsRouter.js +++ b/src/Routers/FunctionsRouter.js @@ -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 { @@ -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,