From 606bd383f1dbf6dd706a302e2c039ea7e71d3140 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 17 May 2023 13:52:27 +0700 Subject: [PATCH] Extended getAll method with paging metadata refs https://github.com/TryGhost/Team/issues/3167 - Having paging metadata is part of every API response and was missing from initial implementation - The getAll method has all of the values as "static" as there's nothing to page on. --- ghost/collections/src/CollectionsService.ts | 18 ++++++++++++++++-- ghost/collections/test/collections.test.ts | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ghost/collections/src/CollectionsService.ts b/ghost/collections/src/CollectionsService.ts index 47ab519aaf..ffcd35377b 100644 --- a/ghost/collections/src/CollectionsService.ts +++ b/ghost/collections/src/CollectionsService.ts @@ -21,8 +21,22 @@ export class CollectionsService { return await this.repository.getById(id); } - async getAll(): Promise { - return await this.repository.getAll(); + async getAll(options?: any): Promise<{data: Collection[], meta: any}> { + const collections = await this.repository.getAll(options); + + return { + data: collections, + meta: { + pagination: { + page: 1, + pages: 1, + limit: collections.length, + total: collections.length, + prev: null, + next: null + } + } + }; } async destroy(id: string): Promise { diff --git a/ghost/collections/test/collections.test.ts b/ghost/collections/test/collections.test.ts index 7a1e5511a4..4285c9692e 100644 --- a/ghost/collections/test/collections.test.ts +++ b/ghost/collections/test/collections.test.ts @@ -30,7 +30,7 @@ describe('collections', function () { assert.equal(createdCollection.title, 'testing collections', 'Collection title should match'); const allCollections = await collectionsService.getAll(); - assert.equal(allCollections.length, 1, 'There should be one collection'); + assert.equal(allCollections.data.length, 1, 'There should be one collection'); await collectionsService.destroy(savedCollection.id); const deletedCollection = await collectionsService.getById(savedCollection.id);