refactor: populate queries

This commit is contained in:
Mohamed Marrouchi
2024-09-21 12:15:36 +01:00
parent bb52f2a1d5
commit 7bc5270551
67 changed files with 661 additions and 1016 deletions

View File

@@ -17,13 +17,20 @@ import { StdOutgoingListMessage } from '@/chat/schemas/types/message';
import { ContentOptions } from '@/chat/schemas/types/options';
import { LoggerService } from '@/logger/logger.service';
import { BaseService } from '@/utils/generics/base-service';
import { PageQueryDto } from '@/utils/pagination/pagination-query.dto';
import { ContentRepository } from '../repositories/content.repository';
import { Content } from '../schemas/content.schema';
import {
Content,
ContentFull,
ContentPopulate,
} from '../schemas/content.schema';
@Injectable()
export class ContentService extends BaseService<Content> {
export class ContentService extends BaseService<
Content,
ContentPopulate,
ContentFull
> {
constructor(
readonly repository: ContentRepository,
private readonly attachmentService: AttachmentService,
@@ -32,33 +39,6 @@ export class ContentService extends BaseService<Content> {
super(repository);
}
/**
* Finds a content item by its ID and populates its related fields.
*
* @param id - The ID of the content to retrieve.
*
* @return The populated content entity.
*/
async findOneAndPopulate(id: string) {
return await this.repository.findOneAndPopulate(id);
}
/**
* Finds a page of content items based on filters and pagination options,
* and populates their related fields.
*
* @param filters - The query filters to apply.
* @param pageQuery - The pagination and sorting options.
*
* @return A list of populated content entities.
*/
async findPageAndPopulate(
filters: TFilterQuery<Content>,
pageQuery: PageQueryDto<Content>,
) {
return await this.repository.findPageAndPopulate(filters, pageQuery);
}
/**
* Performs a text search on the content repository.
*

View File

@@ -17,24 +17,22 @@ import {
import { OnEvent } from '@nestjs/event-emitter';
import { Cache } from 'cache-manager';
import { LoggerService } from '@/logger/logger.service';
import { MENU_CACHE_KEY } from '@/utils/constants/cache';
import { Cacheable } from '@/utils/decorators/cacheable.decorator';
import { BaseService } from '@/utils/generics/base-service';
import { MenuCreateDto } from '../dto/menu.dto';
import { MenuRepository } from '../repositories/menu.repository';
import { Menu } from '../schemas/menu.schema';
import { Menu, MenuFull, MenuPopulate } from '../schemas/menu.schema';
import { AnyMenu, MenuTree, MenuType } from '../schemas/types/menu';
@Injectable()
export class MenuService extends BaseService<Menu> {
export class MenuService extends BaseService<Menu, MenuPopulate, MenuFull> {
private RootSymbol: symbol = Symbol('RootMenu');
constructor(
readonly repository: MenuRepository,
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
private readonly logger: LoggerService,
) {
super(repository);
}