fix: afterSave trigger removes pointer in Parse object (#7913)

This commit is contained in:
dblythy
2022-05-20 18:47:38 +10:00
committed by GitHub
parent 2e750b78cc
commit 47d796ea58
4 changed files with 75 additions and 4 deletions

View File

@@ -150,9 +150,15 @@ const defaultColumns: { [string]: SchemaFields } = Object.freeze({
},
});
// fields required for read or write operations on their respective classes.
const requiredColumns = Object.freeze({
_Product: ['productIdentifier', 'icon', 'order', 'title', 'subtitle'],
_Role: ['name', 'ACL'],
read: {
_User: ['username'],
},
write: {
_Product: ['productIdentifier', 'icon', 'order', 'title', 'subtitle'],
_Role: ['name', 'ACL'],
}
});
const invalidColumns = ['length'];
@@ -1269,7 +1275,7 @@ export default class SchemaController {
// Validates that all the properties are set for the object
validateRequiredColumns(className: string, object: any, query: any) {
const columns = requiredColumns[className];
const columns = requiredColumns.write[className];
if (!columns || columns.length == 0) {
return Promise.resolve(this);
}
@@ -1600,4 +1606,5 @@ export {
convertSchemaToAdapterSchema,
VolatileClassesSchemas,
SchemaController,
requiredColumns,
};

View File

@@ -15,6 +15,7 @@ var ClientSDK = require('./ClientSDK');
import RestQuery from './RestQuery';
import _ from 'lodash';
import logger from './logger';
import { requiredColumns } from './Controllers/SchemaController';
// query and data are both provided in REST API format. So data
// types are encoded by plain old objects.
@@ -1556,7 +1557,7 @@ RestWrite.prototype.runAfterSaveTrigger = function () {
this.response.response = result;
} else {
this.response.response = this._updateResponseWithData(
(result || updatedObject)._toFullJSON(),
(result || updatedObject).toJSON(),
this.data
);
}
@@ -1665,6 +1666,21 @@ RestWrite.prototype._updateResponseWithData = function (response, data) {
this.storage.fieldsChangedByTrigger.push(key);
}
}
const skipKeys = [
'objectId',
'createdAt',
'updatedAt',
...(requiredColumns.read[this.className] || []),
];
for (const key in response) {
if (skipKeys.includes(key)) {
continue;
}
const value = response[key];
if (value == null || (value.__type && value.__type === 'Pointer') || data[key] === value) {
delete response[key];
}
}
if (_.isEmpty(this.storage.fieldsChangedByTrigger)) {
return response;
}