Skip to content

Commit

Permalink
Fixed issue31
Browse files Browse the repository at this point in the history
* [FIXED] Can't remove on Many-To-Many relations [#31]
  • Loading branch information
doug-martin committed Feb 23, 2020
1 parent c7b14f1 commit 4989877
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
17 changes: 15 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# 0.3.1
# v0.3.4

* [FIXED] Can't remove on Many-To-Many relations [#31](https://github.com/doug-martin/nestjs-query/issues/31)

# v0.3.3

* Update typescript to 3.8.
* Update dependency versions.

# v0.3.2

* Switched to github actions

# v0.3.1

* Hardened TypeORM querying
* Added filter for entity ids on relations to prevent querying for too many rows.
* Qualify all filter and sorting columns, to prevent column name collisions.

# 0.3.0
# v0.3.0

* Added dataloader support!
* Fixed issue with loading of many-to-many relations [#22](https://github.com/doug-martin/nestjs-query/issues/22)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ describe('TypeOrmQueryService', (): void => {
when(entityQueryBuilder.relation(relationName)).thenReturn(instance(relationQueryBuilder));
when(relationQueryBuilder.of(objectContaining(entity))).thenReturn(instance(relationQueryBuilder));
when(relationQueryBuilder.remove(relationIds)).thenResolve();
const queryResult = await queryService.removeRelations(entity.testEntityPk, relationName, relationIds);
const queryResult = await queryService.removeRelations(relationName, entity.testEntityPk, relationIds);
expect(queryResult).toEqual(entity);
});
});
Expand All @@ -422,7 +422,7 @@ describe('TypeOrmQueryService', (): void => {
when(entityQueryBuilder.relation(relationName)).thenReturn(instance(relationQueryBuilder));
when(relationQueryBuilder.of(objectContaining(entity))).thenReturn(instance(relationQueryBuilder));
when(relationQueryBuilder.remove(relation.testRelationPk)).thenResolve();
const queryResult = await queryService.removeRelation(entity.testEntityPk, relationName, relation.testRelationPk);
const queryResult = await queryService.removeRelation(relationName, entity.testEntityPk, relation.testRelationPk);
expect(queryResult).toEqual(entity);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/query-typeorm/src/services/relation-query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export abstract class RelationQueryService<DTO, Entity = DTO> {
* @param relationIds - The ids of the relations to add.
*/
async removeRelations<Relation>(
id: string | number,
relationName: string,
id: string | number,
relationIds: (string | number)[],
): Promise<DTO> {
const entity = await this.repo.findOneOrFail(id);
Expand All @@ -156,7 +156,7 @@ export abstract class RelationQueryService<DTO, Entity = DTO> {
* @param relationName - The name of the relation to query for.
* @param relationId - The id of the relation to set on the entity.
*/
async removeRelation<Relation>(id: string | number, relationName: string, relationId: string | number): Promise<DTO> {
async removeRelation<Relation>(relationName: string, id: string | number, relationId: string | number): Promise<DTO> {
const entity = await this.repo.findOneOrFail(id);
await this.createRelationQueryBuilder(entity, relationName).remove(relationId);
return this.assembler.convertToDTO(entity);
Expand Down

0 comments on commit 4989877

Please sign in to comment.