Soft delete
BaseEntity includes a deletedAt (@DeleteDateColumn) column. Pass softDelete: true to @Crud() to turn delete operations into soft deletes and to generate the trash / restore routes.
ts
@Crud({
entity: User,
path: 'users',
softDelete: true,
routes: {
delete: { enabled: true },
restore: { enabled: true },
deleteFromTrash: { enabled: true },
restoreMany: { enabled: true },
deleteFromTrashMany: { enabled: true },
},
})
export class UserController {
constructor(public service: UserService) {}
}Behaviour
DELETE /:idsetsdeletedAtinstead of removing the row.- Soft-deleted rows are hidden from
findMany/findOneby default. GET /?withDeleted=trueincludes them;GET /?onlyDeleted=truereturns only them.PUT /:id/restoreclearsdeletedAt(un-trashes).DELETE /:id/trashpermanently removes a (soft-deleted) row.- Bulk variants:
PUT /restore/bulk(body{ ids }),DELETE /trash/bulk?ids=….
bash
curl -X DELETE localhost:3000/users/<id> # soft delete
curl 'localhost:3000/users?onlyDeleted=true' # list trash
curl -X PUT localhost:3000/users/<id>/restore # restore
curl -X DELETE localhost:3000/users/<id>/trash # permanent deleteSee querying.md for the withDeleted / onlyDeleted flags on read endpoints.