Skip to content

Adds batchIndex and batchCount properties to beforeSave and afterSave hooks #5896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ function RestWrite(
// Processing this operation may mutate our data, so we operate on a
// copy
this.query = deepcopy(query);
this.data = deepcopy(data);

// Remove batch data because this should not be stored in the database
const { _batchIndex, _batchCount, ...rest } = data;
this.context.batchCount = _batchCount;
this.context.batchIndex = _batchIndex;
this.data = deepcopy(rest);

// We never change originalData, so we do not need a deep copy
this.originalData = originalData;

Expand Down Expand Up @@ -109,6 +115,8 @@ RestWrite.prototype.execute = function() {
return this.deleteEmailResetTokenIfNeeded();
})
.then(() => {
delete this.data._batchCount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove those then it will not pass the schema validation. When this is called via this function, it sets this.data back to the request.body params which includes the _batchCount and _batchIndex properties. Do you have any suggestions?

delete this.data._batchIndex;
return this.validateSchema();
})
.then(schemaController => {
Expand Down