0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

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.
This commit is contained in:
Naz 2023-05-17 13:52:27 +07:00 committed by naz
parent 2d1eb881fc
commit 606bd383f1
2 changed files with 17 additions and 3 deletions

View file

@ -21,8 +21,22 @@ export class CollectionsService {
return await this.repository.getById(id);
}
async getAll(): Promise<Collection[]> {
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<void> {

View file

@ -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);