fix: support createMany method

This commit is contained in:
yassinedorbozgithub 2025-01-10 08:54:04 +01:00
parent 5c4d9af9cf
commit 7489648bae
2 changed files with 11 additions and 16 deletions

View File

@ -466,7 +466,9 @@ export abstract class BaseRepository<
);
}
async createMany(dtoArray: U[]): Promise<T[]> {
async createMany(
dtoArray: DtoInfer<DtoOperations.Create, DTOCruds, U>[],
): Promise<T[]> {
const docs = await this.model.create(dtoArray);
return docs.map((doc) =>

View File

@ -144,13 +144,9 @@ export abstract class BaseService<
return await this.repository.count(criteria);
}
async create<
D extends DtoInfer<
DtoOperations.Create,
DTOCruds,
Omit<T, keyof BaseSchema>
>,
>(dto: D): Promise<T> {
async create<D extends Omit<T, keyof BaseSchema>>(
dto: DtoInfer<DtoOperations.Create, DTOCruds, D>,
): Promise<T> {
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<T, keyof BaseSchema>
>,
>(criteria: string | TFilterQuery<T>, dto: D): Promise<T> {
async findOneOrCreate<D extends Omit<T, keyof BaseSchema>>(
criteria: string | TFilterQuery<T>,
dto: DtoInfer<DtoOperations.Create, DTOCruds, D>,
): Promise<T> {
const result = await this.findOne(criteria);
if (!result) {
return await this.create(dto);
@ -178,7 +171,7 @@ export abstract class BaseService<
}
async createMany<D extends Omit<T, keyof BaseSchema>>(
dtoArray: D[],
dtoArray: DtoInfer<DtoOperations.Create, DTOCruds, D>[],
): Promise<T[]> {
return await this.repository.createMany(dtoArray);
}