refactor: Add option to convert Parse.Object to instance in Cloud Function payload (#8656)
This commit is contained in:
@@ -9,7 +9,7 @@ import { jobStatusHandler } from '../StatusHandler';
|
||||
import _ from 'lodash';
|
||||
import { logger } from '../logger';
|
||||
|
||||
function parseObject(obj) {
|
||||
function parseObject(obj, config) {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => {
|
||||
return parseObject(item);
|
||||
@@ -18,21 +18,21 @@ function parseObject(obj) {
|
||||
return Object.assign(new Date(obj.iso), obj);
|
||||
} else if (obj && obj.__type == 'File') {
|
||||
return Parse.File.fromJSON(obj);
|
||||
} else if (obj && obj.__type == 'Pointer') {
|
||||
} else if (obj && obj.__type == 'Pointer' && config.encodeParseObjectInCloudFunction) {
|
||||
return Parse.Object.fromJSON({
|
||||
__type: 'Pointer',
|
||||
className: obj.className,
|
||||
objectId: obj.objectId,
|
||||
});
|
||||
} else if (obj && typeof obj === 'object') {
|
||||
return parseParams(obj);
|
||||
return parseParams(obj, config);
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
function parseParams(params) {
|
||||
return _.mapValues(params, parseObject);
|
||||
function parseParams(params, config) {
|
||||
return _.mapValues(params, item => parseObject(item, config));
|
||||
}
|
||||
|
||||
export class FunctionsRouter extends PromiseRouter {
|
||||
@@ -66,7 +66,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Invalid job.');
|
||||
}
|
||||
let params = Object.assign({}, req.body, req.query);
|
||||
params = parseParams(params);
|
||||
params = parseParams(params, req.config);
|
||||
const request = {
|
||||
params: params,
|
||||
log: req.config.loggerController,
|
||||
@@ -126,7 +126,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, `Invalid function: "${functionName}"`);
|
||||
}
|
||||
let params = Object.assign({}, req.body, req.query);
|
||||
params = parseParams(params);
|
||||
params = parseParams(params, req.config);
|
||||
const request = {
|
||||
params: params,
|
||||
master: req.auth && req.auth.isMaster,
|
||||
|
||||
Reference in New Issue
Block a user