mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Fixed return values of CollectionService
Our service layer should not expose the Entities, it should return the DTOs. This is to allow us to make internal refactors without having to modify the entire stack.
This commit is contained in:
parent
43b76056ca
commit
3a624ec3a1
@ -560,12 +560,20 @@ export class CollectionsService {
|
||||
});
|
||||
}
|
||||
|
||||
async getById(id: string, options?: {transaction: Knex.Transaction}): Promise<Collection | null> {
|
||||
return await this.collectionsRepository.getById(id, options);
|
||||
async getById(id: string, options?: {transaction: Knex.Transaction}): Promise<CollectionDTO | null> {
|
||||
const collection = await this.collectionsRepository.getById(id, options);
|
||||
if (!collection) {
|
||||
return null;
|
||||
}
|
||||
return this.toDTO(collection);
|
||||
}
|
||||
|
||||
async getBySlug(slug: string, options?: {transaction: Knex.Transaction}): Promise<Collection | null> {
|
||||
return await this.collectionsRepository.getBySlug(slug, options);
|
||||
async getBySlug(slug: string, options?: {transaction: Knex.Transaction}): Promise<CollectionDTO | null> {
|
||||
const collection = await this.collectionsRepository.getBySlug(slug, options);
|
||||
if (!collection) {
|
||||
return null;
|
||||
}
|
||||
return this.toDTO(collection);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@ -605,7 +613,7 @@ export class CollectionsService {
|
||||
}
|
||||
|
||||
async destroy(id: string): Promise<Collection | null> {
|
||||
const collection = await this.getById(id);
|
||||
const collection = await this.collectionsRepository.getById(id);
|
||||
|
||||
if (collection) {
|
||||
if (collection.deletable === false) {
|
||||
|
@ -56,7 +56,7 @@ class PostsService {
|
||||
});
|
||||
}
|
||||
|
||||
const postIds = collection.posts;
|
||||
const postIds = collection.posts.map(post => post.id);
|
||||
|
||||
if (postIds.length !== 0) {
|
||||
options.filter = `id:[${postIds.join(',')}]+type:post`;
|
||||
|
Loading…
Reference in New Issue
Block a user