-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nestjs-json-rpc): Add support soft delete
Allow set options for soft delete for DeleteOne
- Loading branch information
Showing
4 changed files
with
14 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 12 additions & 10 deletions
22
libs/json-api/json-api-nestjs/src/lib/helper/orm/methods/delete-one/delete-one.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { Entity, TypeormServiceObject } from '../../../../types'; | ||
import { FindOptionsWhere } from 'typeorm'; | ||
|
||
export async function deleteOne<E extends Entity>( | ||
this: TypeormServiceObject<E>, | ||
id: number | string | ||
): Promise<void> { | ||
await this.repository | ||
.createQueryBuilder(this.typeormUtilsService.currentAlias) | ||
.delete() | ||
.where( | ||
`${this.typeormUtilsService.currentPrimaryColumn.toString()} = :params` | ||
) | ||
.setParameters({ | ||
params: id, | ||
}) | ||
.execute(); | ||
const data = await this.repository.findOne({ | ||
where: { | ||
[this.typeormUtilsService.currentPrimaryColumn.toString()]: id, | ||
} as FindOptionsWhere<E>, | ||
}); | ||
if (!data) return void 0; | ||
|
||
this.config.useSoftDelete | ||
? await this.repository.softRemove(data) | ||
: await this.repository.remove(data); | ||
|
||
return void 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters