mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05: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
2 changed files with 14 additions and 6 deletions
|
@ -560,12 +560,20 @@ export class CollectionsService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getById(id: string, options?: {transaction: Knex.Transaction}): Promise<Collection | null> {
|
async getById(id: string, options?: {transaction: Knex.Transaction}): Promise<CollectionDTO | null> {
|
||||||
return await this.collectionsRepository.getById(id, options);
|
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> {
|
async getBySlug(slug: string, options?: {transaction: Knex.Transaction}): Promise<CollectionDTO | null> {
|
||||||
return await this.collectionsRepository.getBySlug(slug, options);
|
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
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
@ -605,7 +613,7 @@ export class CollectionsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async destroy(id: string): Promise<Collection | null> {
|
async destroy(id: string): Promise<Collection | null> {
|
||||||
const collection = await this.getById(id);
|
const collection = await this.collectionsRepository.getById(id);
|
||||||
|
|
||||||
if (collection) {
|
if (collection) {
|
||||||
if (collection.deletable === false) {
|
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) {
|
if (postIds.length !== 0) {
|
||||||
options.filter = `id:[${postIds.join(',')}]+type:post`;
|
options.filter = `id:[${postIds.join(',')}]+type:post`;
|
||||||
|
|
Loading…
Add table
Reference in a new issue