Skip to content

Commit c11b2d4

Browse files
committed
refactor(typeorm): Update to specify the update and create types
1 parent 57b36d6 commit c11b2d4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

packages/query-typeorm/src/services/typeorm-query.service.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export interface TypeOrmQueryServiceOpts<Entity> {
4141
* }
4242
* ```
4343
*/
44-
export class TypeOrmQueryService<Entity> extends RelationQueryService<Entity> implements QueryService<Entity> {
44+
export class TypeOrmQueryService<Entity>
45+
extends RelationQueryService<Entity>
46+
implements QueryService<Entity, DeepPartial<Entity>, DeepPartial<Entity>> {
4547
readonly filterQueryBuilder: FilterQueryBuilder<Entity>;
4648

4749
readonly useSoftDelete: boolean;
@@ -127,7 +129,7 @@ export class TypeOrmQueryService<Entity> extends RelationQueryService<Entity> im
127129
* ```
128130
* @param record - The entity to create.
129131
*/
130-
async createOne<C extends DeepPartial<Entity>>(record: C): Promise<Entity> {
132+
async createOne(record: DeepPartial<Entity>): Promise<Entity> {
131133
const entity = await this.ensureIsEntityAndDoesNotExist(record);
132134
return this.repo.save(entity);
133135
}
@@ -144,7 +146,7 @@ export class TypeOrmQueryService<Entity> extends RelationQueryService<Entity> im
144146
* ```
145147
* @param records - The entities to create.
146148
*/
147-
async createMany<C extends DeepPartial<Entity>>(records: C[]): Promise<Entity[]> {
149+
async createMany(records: DeepPartial<Entity>[]): Promise<Entity[]> {
148150
const entities = await Promise.all(records.map((r) => this.ensureIsEntityAndDoesNotExist(r)));
149151
return this.repo.save(entities);
150152
}
@@ -160,11 +162,7 @@ export class TypeOrmQueryService<Entity> extends RelationQueryService<Entity> im
160162
* @param update - A `Partial` of the entity with fields to update.
161163
* @param opts - Additional options.
162164
*/
163-
async updateOne<U extends DeepPartial<Entity>>(
164-
id: number | string,
165-
update: U,
166-
opts?: UpdateOneOptions<Entity>,
167-
): Promise<Entity> {
165+
async updateOne(id: number | string, update: DeepPartial<Entity>, opts?: UpdateOneOptions<Entity>): Promise<Entity> {
168166
this.ensureIdIsNotPresent(update);
169167
const entity = await this.getById(id, opts);
170168
return this.repo.save(this.repo.merge(entity, update));
@@ -183,7 +181,7 @@ export class TypeOrmQueryService<Entity> extends RelationQueryService<Entity> im
183181
* @param update - A `Partial` of entity with the fields to update
184182
* @param filter - A Filter used to find the records to update
185183
*/
186-
async updateMany<U extends DeepPartial<Entity>>(update: U, filter: Filter<Entity>): Promise<UpdateManyResponse> {
184+
async updateMany(update: DeepPartial<Entity>, filter: Filter<Entity>): Promise<UpdateManyResponse> {
187185
this.ensureIdIsNotPresent(update);
188186
const updateResult = await this.filterQueryBuilder
189187
.update({ filter })

0 commit comments

Comments
 (0)