From de8dc3f80412aaf2d0c1c2fde281a6a55a9c090b Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Thu, 9 Jan 2020 09:41:17 +0100 Subject: [PATCH 1/2] update with source option --- src/controllers/document.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/document.js b/src/controllers/document.js index 5927c846b..ea2664098 100644 --- a/src/controllers/document.js +++ b/src/controllers/document.js @@ -213,8 +213,10 @@ class DocumentController extends BaseController { _id, body, action: 'update', - retryOnConflict: options.retryOnConflict + retryOnConflict: options.retryOnConflict, + source: options.source }; + delete options.source; delete options.retryOnConflict; return this.query(request, options) From f5cb94bb00c1f2fc6f56f9280c57c20422680b3c Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Thu, 9 Jan 2020 10:18:15 +0100 Subject: [PATCH 2/2] test and doc --- doc/7/controllers/document/update/index.md | 3 +- test/controllers/document.test.js | 34 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/doc/7/controllers/document/update/index.md b/doc/7/controllers/document/update/index.md index a2587af85..8cc02918b 100644 --- a/doc/7/controllers/document/update/index.md +++ b/doc/7/controllers/document/update/index.md @@ -35,10 +35,11 @@ Additional query options | `queuable` |
boolean

(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | | `refresh` |
string

(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) | | `retryOnConflict` |
int

(`0`) | The number of times the database layer should retry in case of version conflict | +| `source` |
boolean

(`false`)| If true, returns the updated document inside the response ## Resolves -Resolves to an object containing the the document update result. +Resolves to an object containing the document update result. ## Usage diff --git a/test/controllers/document.test.js b/test/controllers/document.test.js index e25e619ff..2cbada2b0 100644 --- a/test/controllers/document.test.js +++ b/test/controllers/document.test.js @@ -512,7 +512,8 @@ describe('Document Controller', () => { collection: 'collection', _id: 'document-id', body: {foo: 'bar'}, - retryOnConflict: undefined + retryOnConflict: undefined, + source: undefined }, options); should(res).be.equal(result); @@ -539,7 +540,36 @@ describe('Document Controller', () => { collection: 'collection', _id: 'document-id', body: {foo: 'bar'}, - retryOnConflict: true + retryOnConflict: true, + source: undefined + }, {}); + + should(res).be.equal(result); + }); + }); + + it('should inject the "source" option into the request', () => { + const result = { + _id: 'document-id', + _version: 1, + _source: { foo: 'bar' }, + created: false + }; + kuzzle.query.resolves({ result }); + + return kuzzle.document.update('index', 'collection', 'document-id', { foo: 'bar' }, { source: true }) + .then(res => { + should(kuzzle.query) + .be.calledOnce() + .be.calledWith({ + controller: 'document', + action: 'update', + index: 'index', + collection: 'collection', + _id: 'document-id', + body: { foo: 'bar' }, + retryOnConflict: undefined, + source: true }, {}); should(res).be.equal(result);