mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
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
This commit is contained in:
parent
98ea0b1ac3
commit
df1f9e8a5c
2 changed files with 7 additions and 3 deletions
|
@ -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<number> {
|
||||
return 0;
|
||||
const result = await this.models.Snippet.findPage({
|
||||
filter: filter
|
||||
});
|
||||
|
||||
return result.meta.pagination.total;
|
||||
}
|
||||
|
||||
async getAll(): Promise<Snippet[]> {
|
||||
|
|
|
@ -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}));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue