Fixed filtering posts by empty collections error

https://github.com/TryGhost/Arch/issues/90

- Ghost produced an error when a collection filter was applied over Posts API and that collection contained no posts.
This commit is contained in:
Naz 2023-09-14 13:29:04 +08:00 committed by naz
parent 1d7bb44a94
commit 11624e48ca

View File

@ -57,9 +57,26 @@ class PostsService {
}
const postIds = collection.posts;
options.filter = `id:[${postIds.join(',')}]+type:post`;
options.status = 'all';
posts = await this.models.Post.findPage(options);
if (postIds.length !== 0) {
options.filter = `id:[${postIds.join(',')}]+type:post`;
options.status = 'all';
posts = await this.models.Post.findPage(options);
} else {
posts = {
data: [],
meta: {
pagination: {
page: 1,
pages: 1,
total: 0,
limit: options.limit || 15,
next: null,
prev: null
}
}
};
}
} else {
posts = await this.models.Post.findPage(options);
}