diff --git a/app/repository/collection-index-repository.js b/app/repository/collection-index-repository.js index 78256097..84eaaf6b 100644 --- a/app/repository/collection-index-repository.js +++ b/app/repository/collection-index-repository.js @@ -1,4 +1,9 @@ +const CollectionIndex = require('../models/collection-index-model'); class CollectionIndexRepository { + constructor(model) { + this.model = model; + } + } -module.exports = CollectionIndexRepository; +module.exports = CollectionIndexRepository(CollectionIndex); diff --git a/app/services/collection-indexes-service.js b/app/services/collection-indexes-service.js index a09ac085..25bbe8d4 100644 --- a/app/services/collection-indexes-service.js +++ b/app/services/collection-indexes-service.js @@ -26,18 +26,14 @@ class CollectionIndexService { async retrieveAll(options) { - try { - const collectionIndexes = await CollectionIndex.find() - .skip(options.offset) - .limit(options.limit) - .lean() - .exec(); - - return collectionIndexes; - } catch (err) { - throw err; - } - }; + const collectionIndexes = await CollectionIndex.find() + .skip(options.offset) + .limit(options.limit) + .lean() + .exec(); + + return collectionIndexes; + } async retrieveById(id) { @@ -60,7 +56,7 @@ class CollectionIndexService { throw err; } } - }; + } async create(data) { @@ -85,7 +81,7 @@ class CollectionIndexService { throw err; } } - }; + } async updateFull(id, data) { @@ -117,24 +113,20 @@ class CollectionIndexService { throw err; } } - }; + } async delete(id) { - try { - if (!id) { - const error = new Error(this.errors.missingParameter); - error.parameterName = 'id'; - throw error; - } - - const collectionIndex = await CollectionIndex.findOneAndRemove({ "collection_index.id": id }); - - return collectionIndex; // Note: collectionIndex is null if not found - } catch (err) { - throw err; + if (!id) { + const error = new Error(this.errors.missingParameter); + error.parameterName = 'id'; + throw error; } - }; + + const collectionIndex = await CollectionIndex.findOneAndRemove({ "collection_index.id": id }); + + return collectionIndex; // Note: collectionIndex is null if not found + } /** @@ -171,21 +163,17 @@ class CollectionIndexService { throw err; } } - }; + } async refresh(id) { - try { - // Do nothing for now - await new Promise(resolve => process.nextTick(resolve)); - return {}; - } catch (err) { - throw err; - } - }; - + // Do nothing for now + await new Promise(resolve => process.nextTick(resolve)); + return {}; + } } + module.exports = new CollectionIndexService(null, CollectionIndexRepository); \ No newline at end of file diff --git a/app/tests/api/collection-indexes/collection-indexes.spec.js b/app/tests/api/collection-indexes/collection-indexes.spec.js index 2c82905e..6e13275a 100644 --- a/app/tests/api/collection-indexes/collection-indexes.spec.js +++ b/app/tests/api/collection-indexes/collection-indexes.spec.js @@ -99,7 +99,7 @@ describe('Collection Indexes Basic API', function () { it('POST /api/collection-indexes does not create an empty collection index', async function () { const body = {}; - const res = await request(app) + await request(app) .post('/api/collection-indexes') .send(body) .set('Accept', 'application/json')