From df1f9e8a5c3f4c9a135bfebbfb6710ebe798624b Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 29 Nov 2023 13:39:22 +0800 Subject: [PATCH] Fixed count query in snippets bookshelf repository refs https://github.com/TryGhost/Arch/issues/99 - Added naive version of the count method using bookshelf models metadata. We aim to use knex anyway, so this is just to get the tests passing --- .../src/core/snippets/snippets.repository.bookshelf.ts | 8 ++++++-- ghost/ghost/src/http/controllers/snippets.controller.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ghost/ghost/src/core/snippets/snippets.repository.bookshelf.ts b/ghost/ghost/src/core/snippets/snippets.repository.bookshelf.ts index 316cca396a..fcc0b12e4f 100644 --- a/ghost/ghost/src/core/snippets/snippets.repository.bookshelf.ts +++ b/ghost/ghost/src/core/snippets/snippets.repository.bookshelf.ts @@ -1,11 +1,11 @@ import {Inject} from '@nestjs/common'; import {Snippet} from './snippet.entity'; import {SnippetsRepository} from './snippets.repository.interface'; -import {Pagination} from '../../common/pagination.type'; import ObjectID from 'bson-objectid'; type QueryOptions = { debug?: boolean; + filter?: string; } type BookshelfModels = { @@ -38,7 +38,11 @@ export class SnippetRepositoryBookshelf implements SnippetsRepository { } async getCount(filter?: string | undefined): Promise { - return 0; + const result = await this.models.Snippet.findPage({ + filter: filter + }); + + return result.meta.pagination.total; } async getAll(): Promise { diff --git a/ghost/ghost/src/http/controllers/snippets.controller.ts b/ghost/ghost/src/http/controllers/snippets.controller.ts index 74a0b45ff9..c0d1ab5566 100644 --- a/ghost/ghost/src/http/controllers/snippets.controller.ts +++ b/ghost/ghost/src/http/controllers/snippets.controller.ts @@ -69,7 +69,7 @@ export class SnippetsController { total = result.count; snippets = result.data; } - const pages = limit === 'all' ? 1 : Math.ceil(total / limit); + const pages = limit === 'all' ? 0 : Math.ceil(total / limit); const snippetDTOs = snippets.map(snippet => new SnippetDTO(snippet, {formats}));