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:
Fabien "egg" O'Carroll 2023-09-21 14:10:51 +07:00 committed by Fabien 'egg' O'Carroll
parent 43b76056ca
commit 3a624ec3a1
2 changed files with 14 additions and 6 deletions

View File

@ -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) {

View File

@ -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`;