@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.
- package/package.json +1 -1
- package/src/Document.js +7 -3
package/package.json
CHANGED
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
|
-
|
|
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
|
|
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
|