@kravc/dos 1.7.3 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Document.js +7 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kravc/dos",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "Convention-based, easy-to-use library for building API-driven serverless services.",
5
5
  "keywords": [
6
6
  "Service",
package/src/Document.js CHANGED
@@ -158,7 +158,7 @@ class Document extends Component {
158
158
  return { items, count: items.length }
159
159
  }
160
160
 
161
- static async update(context, query, mutation) {
161
+ static async update(context, query, mutation, originalDocument = null) {
162
162
  mutation = omit(mutation, [ this.idKey, 'createdAt', 'createdBy' ])
163
163
 
164
164
  const accountId = get(context, 'identity.accountId')
@@ -176,7 +176,9 @@ class Document extends Component {
176
176
 
177
177
  /* NOTE: ensure that document to be updated exists and save it in the
178
178
  context so can be referenced in the after action helper */
179
- const originalDocument = await this.read(context, query)
179
+ if (!originalDocument) {
180
+ originalDocument = await this.read(context, query)
181
+ }
180
182
 
181
183
  const updatedItem = await this._update(query, mutation)
182
184
 
@@ -249,7 +251,9 @@ class Document extends Component {
249
251
  }
250
252
 
251
253
  async update(mutation, shouldMutate = false) {
252
- const document = await this.constructor.update(this.context, this._query, mutation)
254
+ const originalDocument = new this.constructor(this.context, { ...this._attributes })
255
+
256
+ const document = await this.constructor.update(this.context, this._query, mutation, originalDocument)
253
257
 
254
258
  if (shouldMutate) {
255
259
  this._attributes = document._attributes