Recursive parse date in cloud function (#2014)
* Recursive parse date in cloud function * Use _.mapValues
This commit is contained in:
@@ -5,6 +5,29 @@ var express = require('express'),
|
||||
triggers = require('../triggers');
|
||||
|
||||
import PromiseRouter from '../PromiseRouter';
|
||||
import _ from 'lodash';
|
||||
|
||||
function parseDate(params) {
|
||||
return _.mapValues(params, (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;
|
||||
}
|
||||
});
|
||||
} else if (obj && obj.__type == 'Date') {
|
||||
return new Date(obj.iso);
|
||||
} else if (obj && typeof obj === 'object') {
|
||||
return parseDate(obj);
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export class FunctionsRouter extends PromiseRouter {
|
||||
|
||||
@@ -36,15 +59,8 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
var theFunction = triggers.getFunction(req.params.functionName, applicationId);
|
||||
var theValidator = triggers.getValidator(req.params.functionName, applicationId);
|
||||
if (theFunction) {
|
||||
const params = Object.assign({}, req.body, req.query);
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
var value = params[key];
|
||||
if (value && value.__type == 'Date') {
|
||||
params[key] = new Date(value.iso);
|
||||
}
|
||||
}
|
||||
}
|
||||
let params = Object.assign({}, req.body, req.query);
|
||||
params = parseDate(params);
|
||||
var request = {
|
||||
params: params,
|
||||
master: req.auth && req.auth.isMaster,
|
||||
@@ -73,4 +89,3 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user