mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: support createMany method
This commit is contained in:
parent
5c4d9af9cf
commit
7489648bae
@ -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);
|
const docs = await this.model.create(dtoArray);
|
||||||
|
|
||||||
return docs.map((doc) =>
|
return docs.map((doc) =>
|
||||||
|
@ -144,13 +144,9 @@ export abstract class BaseService<
|
|||||||
return await this.repository.count(criteria);
|
return await this.repository.count(criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
async create<
|
async create<D extends Omit<T, keyof BaseSchema>>(
|
||||||
D extends DtoInfer<
|
dto: DtoInfer<DtoOperations.Create, DTOCruds, D>,
|
||||||
DtoOperations.Create,
|
): Promise<T> {
|
||||||
DTOCruds,
|
|
||||||
Omit<T, keyof BaseSchema>
|
|
||||||
>,
|
|
||||||
>(dto: D): Promise<T> {
|
|
||||||
try {
|
try {
|
||||||
return await this.repository.create(dto);
|
return await this.repository.create(dto);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -163,13 +159,10 @@ export abstract class BaseService<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOneOrCreate<
|
async findOneOrCreate<D extends Omit<T, keyof BaseSchema>>(
|
||||||
D extends DtoInfer<
|
criteria: string | TFilterQuery<T>,
|
||||||
DtoOperations.Create,
|
dto: DtoInfer<DtoOperations.Create, DTOCruds, D>,
|
||||||
DTOCruds,
|
): Promise<T> {
|
||||||
Omit<T, keyof BaseSchema>
|
|
||||||
>,
|
|
||||||
>(criteria: string | TFilterQuery<T>, dto: D): Promise<T> {
|
|
||||||
const result = await this.findOne(criteria);
|
const result = await this.findOne(criteria);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return await this.create(dto);
|
return await this.create(dto);
|
||||||
@ -178,7 +171,7 @@ export abstract class BaseService<
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createMany<D extends Omit<T, keyof BaseSchema>>(
|
async createMany<D extends Omit<T, keyof BaseSchema>>(
|
||||||
dtoArray: D[],
|
dtoArray: DtoInfer<DtoOperations.Create, DTOCruds, D>[],
|
||||||
): Promise<T[]> {
|
): Promise<T[]> {
|
||||||
return await this.repository.createMany(dtoArray);
|
return await this.repository.createMany(dtoArray);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user