From f53589b06d74ee65155b62a5ade36c4e6596d04a Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Sat, 12 Oct 2024 12:44:32 +0100 Subject: [PATCH] refactor(api): simplify services logic --- api/src/chat/services/conversation.service.ts | 16 -------- api/src/chat/services/label.service.ts | 37 ------------------- api/src/chat/services/message.service.ts | 30 --------------- api/src/chat/services/subscriber.service.ts | 30 --------------- api/src/utils/generics/base-service.ts | 4 +- 5 files changed, 2 insertions(+), 115 deletions(-) diff --git a/api/src/chat/services/conversation.service.ts b/api/src/chat/services/conversation.service.ts index c545bae..010e981 100644 --- a/api/src/chat/services/conversation.service.ts +++ b/api/src/chat/services/conversation.service.ts @@ -7,7 +7,6 @@ */ import { Injectable, Logger } from '@nestjs/common'; -import { FilterQuery } from 'mongoose'; import EventWrapper from '@/channel/lib/EventWrapper'; import { LoggerService } from '@/logger/logger.service'; @@ -41,21 +40,6 @@ export class ConversationService extends BaseService< super(repository); } - /** - * Finds and retrieves a single conversation entity based on the provided criteria, - * while populating the necessary related data. - * - * @param criteria - The search criteria to find a conversation, which can be a string - * representing a unique identifier or a filter query object that specifies the conditions - * for the search. - * - * @returns A Promise that resolves with the found conversation, populated with any related data, - * or `null` if no conversation matches the criteria. - */ - async findOneAndPopulate(criteria: string | FilterQuery) { - return await this.repository.findOneAndPopulate(criteria); - } - /** * Marks the conversation as inactive. * diff --git a/api/src/chat/services/label.service.ts b/api/src/chat/services/label.service.ts index 8a5254c..e5db9ce 100644 --- a/api/src/chat/services/label.service.ts +++ b/api/src/chat/services/label.service.ts @@ -7,10 +7,8 @@ */ import { Injectable } from '@nestjs/common'; -import { TFilterQuery } from 'mongoose'; import { BaseService } from '@/utils/generics/base-service'; -import { PageQueryDto } from '@/utils/pagination/pagination-query.dto'; import { LabelRepository } from '../repositories/label.repository'; import { Label, LabelFull, LabelPopulate } from '../schemas/label.schema'; @@ -20,39 +18,4 @@ export class LabelService extends BaseService { constructor(readonly repository: LabelRepository) { super(repository); } - - /** - * Finds all labels and populates related data. - * - * @returns A promise that resolves with an array of labels with populated related data. - */ - async findAllAndPopulate() { - return await this.repository.findAllAndPopulate(); - } - - /** - * Finds a page of labels based on filters and page query, and populates related data. - * - * @param filters The filters to apply when querying the labels. - * @param pageQuery The pagination and sorting options. - * - * @returns A promise that resolves with a paginated list of labels with populated related data. - */ - async findPageAndPopulate( - filters: TFilterQuery