@@ -28,35 +28,35 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
28
28
readonly queryService : QueryService < Entity , CE , UE >
29
29
) { }
30
30
31
- public addRelations < Relation > (
31
+ public async addRelations < Relation > (
32
32
relationName : string ,
33
33
id : string | number ,
34
34
relationIds : ( string | number ) [ ] ,
35
35
opts ?: ModifyRelationOptions < DTO , Relation >
36
36
) : Promise < DTO > {
37
- return this . assembler . convertAsyncToDTO (
38
- this . queryService . addRelations ( relationName , id , relationIds , this . convertModifyRelationsOptions ( opts ) )
37
+ return this . assembler . convertToDTO (
38
+ await this . queryService . addRelations ( relationName , id , relationIds , this . convertModifyRelationsOptions ( opts ) )
39
39
)
40
40
}
41
41
42
- public createMany ( items : C [ ] ) : Promise < DTO [ ] > {
42
+ public async createMany ( items : C [ ] ) : Promise < DTO [ ] > {
43
43
const { assembler } = this
44
- const converted = assembler . convertToCreateEntities ( items )
45
- return this . assembler . convertAsyncToDTOs ( this . queryService . createMany ( converted ) )
44
+ const converted = await assembler . convertToCreateEntities ( items )
45
+ return this . assembler . convertToDTOs ( await this . queryService . createMany ( converted ) )
46
46
}
47
47
48
- public createOne ( item : C ) : Promise < DTO > {
49
- const c = this . assembler . convertToCreateEntity ( item )
50
- return this . assembler . convertAsyncToDTO ( this . queryService . createOne ( c ) )
48
+ public async createOne ( item : C ) : Promise < DTO > {
49
+ const c = await this . assembler . convertToCreateEntity ( item )
50
+ return this . assembler . convertToDTO ( await this . queryService . createOne ( c ) )
51
51
}
52
52
53
53
public async deleteMany ( filter : Filter < DTO > ) : Promise < DeleteManyResponse > {
54
54
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55
55
return this . queryService . deleteMany ( this . assembler . convertQuery ( { filter } ) . filter )
56
56
}
57
57
58
- public deleteOne ( id : number | string , opts ?: DeleteOneOptions < DTO > ) : Promise < DTO > {
59
- return this . assembler . convertAsyncToDTO ( this . queryService . deleteOne ( id , this . convertFilterable ( opts ) ) )
58
+ public async deleteOne ( id : number | string , opts ?: DeleteOneOptions < DTO > ) : Promise < DTO > {
59
+ return this . assembler . convertToDTO ( await this . queryService . deleteOne ( id , this . convertFilterable ( opts ) ) )
60
60
}
61
61
62
62
public async findById ( id : string | number , opts ?: FindByIdOptions < DTO > ) : Promise < DTO | undefined > {
@@ -67,12 +67,12 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
67
67
return this . assembler . convertToDTO ( entity )
68
68
}
69
69
70
- public getById ( id : string | number , opts ?: GetByIdOptions < DTO > ) : Promise < DTO > {
71
- return this . assembler . convertAsyncToDTO ( this . queryService . getById ( id , this . convertFilterable ( opts ) ) )
70
+ public async getById ( id : string | number , opts ?: GetByIdOptions < DTO > ) : Promise < DTO > {
71
+ return this . assembler . convertToDTO ( await this . queryService . getById ( id , this . convertFilterable ( opts ) ) )
72
72
}
73
73
74
- public query ( query : Query < DTO > , opts ?: QueryOptions < DTO > ) : Promise < DTO [ ] > {
75
- return this . assembler . convertAsyncToDTOs ( this . queryService . query ( this . assembler . convertQuery ( query ) , opts as never ) )
74
+ public async query ( query : Query < DTO > , opts ?: QueryOptions < DTO > ) : Promise < DTO [ ] > {
75
+ return this . assembler . convertToDTOs ( await this . queryService . query ( this . assembler . convertQuery ( query ) , opts as never ) )
76
76
}
77
77
78
78
public async aggregate (
@@ -128,7 +128,7 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
128
128
query : Query < Relation >
129
129
) : Promise < Relation [ ] | Map < DTO , Relation [ ] > > {
130
130
if ( Array . isArray ( dto ) ) {
131
- const entities = this . assembler . convertToEntities ( dto )
131
+ const entities = await this . assembler . convertToEntities ( dto )
132
132
const relationMap = await this . queryService . queryRelations ( RelationClass , relationName , entities , query )
133
133
134
134
return entities . reduce ( ( map , e , index ) => {
@@ -140,7 +140,7 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
140
140
} , new Map < DTO , Relation [ ] > ( ) )
141
141
}
142
142
143
- return this . queryService . queryRelations ( RelationClass , relationName , this . assembler . convertToEntity ( dto ) , query )
143
+ return this . queryService . queryRelations ( RelationClass , relationName , await this . assembler . convertToEntity ( dto ) , query )
144
144
}
145
145
146
146
public countRelations < Relation > (
@@ -164,15 +164,15 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
164
164
filter : Filter < Relation >
165
165
) : Promise < number | Map < DTO , number > > {
166
166
if ( Array . isArray ( dto ) ) {
167
- const entities = this . assembler . convertToEntities ( dto )
167
+ const entities = await this . assembler . convertToEntities ( dto )
168
168
const relationMap = await this . queryService . countRelations ( RelationClass , relationName , entities , filter )
169
169
return entities . reduce ( ( map , e , index ) => {
170
170
const entry = relationMap . get ( e ) ?? 0
171
171
map . set ( dto [ index ] , entry )
172
172
return map
173
173
} , new Map < DTO , number > ( ) )
174
174
}
175
- return this . queryService . countRelations ( RelationClass , relationName , this . assembler . convertToEntity ( dto ) , filter )
175
+ return this . queryService . countRelations ( RelationClass , relationName , await this . assembler . convertToEntity ( dto ) , filter )
176
176
}
177
177
178
178
/**
@@ -210,71 +210,71 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
210
210
opts ?: FindRelationOptions < Relation >
211
211
) : Promise < ( Relation | undefined ) | Map < DTO , Relation | undefined > > {
212
212
if ( Array . isArray ( dto ) ) {
213
- const entities = this . assembler . convertToEntities ( dto )
213
+ const entities = await this . assembler . convertToEntities ( dto )
214
214
const relationMap = await this . queryService . findRelation ( RelationClass , relationName , entities , opts )
215
215
return entities . reduce ( ( map , e , index ) => {
216
216
map . set ( dto [ index ] , relationMap . get ( e ) )
217
217
return map
218
218
} , new Map < DTO , Relation | undefined > ( ) )
219
219
}
220
- return this . queryService . findRelation ( RelationClass , relationName , this . assembler . convertToEntity ( dto ) )
220
+ return this . queryService . findRelation ( RelationClass , relationName , await this . assembler . convertToEntity ( dto ) )
221
221
}
222
222
223
- public removeRelation < Relation > (
223
+ public async removeRelation < Relation > (
224
224
relationName : string ,
225
225
id : string | number ,
226
226
relationId : string | number ,
227
227
opts ?: ModifyRelationOptions < DTO , Relation >
228
228
) : Promise < DTO > {
229
- return this . assembler . convertAsyncToDTO (
230
- this . queryService . removeRelation ( relationName , id , relationId , this . convertModifyRelationsOptions ( opts ) )
229
+ return this . assembler . convertToDTO (
230
+ await this . queryService . removeRelation ( relationName , id , relationId , this . convertModifyRelationsOptions ( opts ) )
231
231
)
232
232
}
233
233
234
- public removeRelations < Relation > (
234
+ public async removeRelations < Relation > (
235
235
relationName : string ,
236
236
id : string | number ,
237
237
relationIds : ( string | number ) [ ] ,
238
238
opts ?: ModifyRelationOptions < DTO , Relation >
239
239
) : Promise < DTO > {
240
- return this . assembler . convertAsyncToDTO (
241
- this . queryService . removeRelations ( relationName , id , relationIds , this . convertModifyRelationsOptions ( opts ) )
240
+ return this . assembler . convertToDTO (
241
+ await this . queryService . removeRelations ( relationName , id , relationIds , this . convertModifyRelationsOptions ( opts ) )
242
242
)
243
243
}
244
244
245
- public setRelations < Relation > (
245
+ public async setRelations < Relation > (
246
246
relationName : string ,
247
247
id : string | number ,
248
248
relationIds : ( string | number ) [ ] ,
249
249
opts ?: ModifyRelationOptions < DTO , Relation >
250
250
) : Promise < DTO > {
251
- return this . assembler . convertAsyncToDTO (
252
- this . queryService . setRelations ( relationName , id , relationIds , this . convertModifyRelationsOptions ( opts ) )
251
+ return this . assembler . convertToDTO (
252
+ await this . queryService . setRelations ( relationName , id , relationIds , this . convertModifyRelationsOptions ( opts ) )
253
253
)
254
254
}
255
255
256
- public setRelation < Relation > (
256
+ public async setRelation < Relation > (
257
257
relationName : string ,
258
258
id : string | number ,
259
259
relationId : string | number ,
260
260
opts ?: ModifyRelationOptions < DTO , Relation >
261
261
) : Promise < DTO > {
262
- return this . assembler . convertAsyncToDTO (
263
- this . queryService . setRelation ( relationName , id , relationId , this . convertModifyRelationsOptions ( opts ) )
262
+ return this . assembler . convertToDTO (
263
+ await this . queryService . setRelation ( relationName , id , relationId , this . convertModifyRelationsOptions ( opts ) )
264
264
)
265
265
}
266
266
267
- public updateMany ( update : U , filter : Filter < DTO > ) : Promise < UpdateManyResponse > {
267
+ public async updateMany ( update : U , filter : Filter < DTO > ) : Promise < UpdateManyResponse > {
268
268
return this . queryService . updateMany (
269
- this . assembler . convertToUpdateEntity ( update ) ,
269
+ await this . assembler . convertToUpdateEntity ( update ) ,
270
270
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
271
271
this . assembler . convertQuery ( { filter } ) . filter
272
272
)
273
273
}
274
274
275
- public updateOne ( id : string | number , update : U , opts ?: UpdateOneOptions < DTO > ) : Promise < DTO > {
276
- return this . assembler . convertAsyncToDTO (
277
- this . queryService . updateOne ( id , this . assembler . convertToUpdateEntity ( update ) , this . convertFilterable ( opts ) )
275
+ public async updateOne ( id : string | number , update : U , opts ?: UpdateOneOptions < DTO > ) : Promise < DTO > {
276
+ return this . assembler . convertToDTO (
277
+ await this . queryService . updateOne ( id , await this . assembler . convertToUpdateEntity ( update ) , this . convertFilterable ( opts ) )
278
278
)
279
279
}
280
280
@@ -300,7 +300,7 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
300
300
aggregate : AggregateQuery < Relation >
301
301
) : Promise < AggregateResponse < Relation > [ ] | Map < DTO , AggregateResponse < Relation > [ ] > > {
302
302
if ( Array . isArray ( dto ) ) {
303
- const entities = this . assembler . convertToEntities ( dto )
303
+ const entities = await this . assembler . convertToEntities ( dto )
304
304
const relationMap = await this . queryService . aggregateRelations ( RelationClass , relationName , entities , filter , aggregate )
305
305
return entities . reduce ( ( map , e , index ) => {
306
306
const entry = relationMap . get ( e ) ?? [ ]
@@ -311,7 +311,7 @@ export class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepP
311
311
return this . queryService . aggregateRelations (
312
312
RelationClass ,
313
313
relationName ,
314
- this . assembler . convertToEntity ( dto ) ,
314
+ await this . assembler . convertToEntity ( dto ) ,
315
315
filter ,
316
316
aggregate
317
317
)
0 commit comments