TypeOrm supports soft deletes. This feature does not delete records but instead updates the column decorated with @DeleteDateColumn.
Before continuing it is recommended that you read the following.
- https://typeorm.io/#/decorator-reference/deletedatecolumn
- https://typeorm.io/#/delete-query-builder/soft-delete
Setting up your entity.
Before enabling soft deletes you must add the DeleteDateColumn to your entity.todo-item.entity.ts
deletedAt column in the above example. Without this column soft deletes will not work. If you add this column all reads from the typeorm repository will add a where clause checking that the column IS NULL.
Soft Delete Service
Once you have added the column to your entity you need to declare your service setting theuseSoftDelete flag.
todo-item.service.ts
super the useSoftDelete option is set to true. This will ensure that all deletes use the softRemove when deleting one or softDelete when deleting many.
Adding restore mutations.
nestjs-query does not automatically expose restore mutations. In this example we add the restore mutations.
todo-item.resolver.ts