From 7489648baea4df8f48c401019ace37b15f33d427 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Fri, 10 Jan 2025 08:54:04 +0100 Subject: [PATCH] fix: support createMany method --- api/src/utils/generics/base-repository.ts | 4 +++- api/src/utils/generics/base-service.ts | 23 ++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/api/src/utils/generics/base-repository.ts b/api/src/utils/generics/base-repository.ts index 9de85f8c..63a2b145 100644 --- a/api/src/utils/generics/base-repository.ts +++ b/api/src/utils/generics/base-repository.ts @@ -466,7 +466,9 @@ export abstract class BaseRepository< ); } - async createMany(dtoArray: U[]): Promise { + async createMany( + dtoArray: DtoInfer[], + ): Promise { const docs = await this.model.create(dtoArray); return docs.map((doc) => diff --git a/api/src/utils/generics/base-service.ts b/api/src/utils/generics/base-service.ts index 652fd0a4..0b1389c0 100644 --- a/api/src/utils/generics/base-service.ts +++ b/api/src/utils/generics/base-service.ts @@ -144,13 +144,9 @@ export abstract class BaseService< return await this.repository.count(criteria); } - async create< - D extends DtoInfer< - DtoOperations.Create, - DTOCruds, - Omit - >, - >(dto: D): Promise { + async create>( + dto: DtoInfer, + ): Promise { try { return await this.repository.create(dto); } catch (error) { @@ -163,13 +159,10 @@ export abstract class BaseService< } } - async findOneOrCreate< - D extends DtoInfer< - DtoOperations.Create, - DTOCruds, - Omit - >, - >(criteria: string | TFilterQuery, dto: D): Promise { + async findOneOrCreate>( + criteria: string | TFilterQuery, + dto: DtoInfer, + ): Promise { const result = await this.findOne(criteria); if (!result) { return await this.create(dto); @@ -178,7 +171,7 @@ export abstract class BaseService< } async createMany>( - dtoArray: D[], + dtoArray: DtoInfer[], ): Promise { return await this.repository.createMany(dtoArray); }