Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/KuzzleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class KuzzleError extends Error {

this.status = apiError.status;
this.stack = apiError.stack;
this.id = apiError.id;
this.code = apiError.code;

// PartialError
if (this.status === 206) {
Expand Down
10 changes: 3 additions & 7 deletions src/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class AuthController extends BaseController {
/**
* Do not add the token for the checkToken route, to avoid getting a token error when
* a developer simply wish to verify his token
*
* @param {object} request
*
* @param {object} request
*/
authenticateRequest (request) {
if (!this.authenticationToken
if ( !this.authenticationToken
|| (request.controller === 'auth'
&& (request.action === 'checkToken' || request.action === 'login'))
) {
Expand Down Expand Up @@ -178,10 +178,6 @@ class AuthController extends BaseController {
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
*/
login (strategy, credentials = {}, expiresIn = null) {
if (typeof strategy !== 'string' || strategy === '') {
throw new Error('Kuzzle.auth.login: strategy is required');
}

const request = {
strategy,
expiresIn,
Expand Down
79 changes: 4 additions & 75 deletions src/controllers/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,17 @@ class CollectionController extends BaseController {
super(kuzzle, 'collection');
}

create (index, collection, body = {}, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.create: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.create: collection is required');
}

create (index, collection, mappings = {}, options = {}) {
return this.query({
index,
collection,
body,
body: mappings,
action: 'create'
}, options)
.then(response => response.result);
}

deleteSpecifications (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.deleteSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.deleteSpecifications: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -45,13 +31,6 @@ class CollectionController extends BaseController {
}

exists (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.exists: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.exists: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -61,13 +40,6 @@ class CollectionController extends BaseController {
}

getMapping (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.getMapping: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.getMapping: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -77,13 +49,6 @@ class CollectionController extends BaseController {
}

getSpecifications (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.getSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.getSpecifications: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -93,10 +58,6 @@ class CollectionController extends BaseController {
}

list (index, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.list: index is required');
}

const request = {
index,
action: 'list',
Expand All @@ -115,8 +76,10 @@ class CollectionController extends BaseController {
body,
action: 'searchSpecifications'
};

for (const opt of ['from', 'size', 'scroll']) {
request[opt] = options[opt];

delete options[opt];
}

Expand All @@ -125,13 +88,6 @@ class CollectionController extends BaseController {
}

truncate (index, collection, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.truncate: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.truncate: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -142,13 +98,6 @@ class CollectionController extends BaseController {
}

updateMapping (index, collection, body, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.updateMapping: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.updateMapping: collection is required');
}

return this.query({
index,
collection,
Expand All @@ -159,16 +108,6 @@ class CollectionController extends BaseController {
}

updateSpecifications (index, collection, specifications, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.updateSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.updateSpecifications: collection is required');
}
if (!specifications) {
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
}

const body = {
[index]: {
[collection]: specifications
Expand All @@ -183,16 +122,6 @@ class CollectionController extends BaseController {
}

validateSpecifications (index, collection, specifications, options = {}) {
if (!index) {
throw new Error('Kuzzle.collection.validateSpecifications: index is required');
}
if (!collection) {
throw new Error('Kuzzle.collection.validateSpecifications: collection is required');
}
if (!specifications) {
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
}

const body = {
[index]: {
[collection]: specifications
Expand Down
Loading