How to represent the recycle (soft-delete) and restore objects in Feathers? #2377
-
Hello! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Take a look at soft-delete Technically, it's only a flag that you toggle to make it soft-deleted or restored |
Beta Was this translation helpful? Give feedback.
-
Personnaly, I would use a property like deletedAt with a date, like you would have createdAt or updatedAt with mongoose. Then if you want to only return non deleted records, you can add a hook that would modify the query with |
Beta Was this translation helpful? Give feedback.
-
Both your answers are good, especially combined together.
This was quote from https://docs.feathersjs.com/guides/basics/services.html#feathers-services I just do not see a built-in way in feathers to have methods set like this instead:
is there a way to add new "verb" to Feathers service contract, and map it like this in REST transport:
Or in this way:
I do not want to reinvent whole new branch of Feathers or reinvent whole new library just for this aspect :) |
Beta Was this translation helpful? Give feedback.
-
Any service class can be extended with additional methods. // things.class.ts
// where `Service` is the database adapter
export class Things extends Service<IThing> {
constructor(options, app) {
super(options)
}
async remove(id: NullableId, params: Params) {
// override remove implementation ...
}
async recycle(id) {
// ...
}
async erase(id) {
return super.remove(id)
}
} With this, The "catch" here is that (at least in v4), those methods are internal-only and do not have any hooks. |
Beta Was this translation helpful? Give feedback.
Any service class can be extended with additional methods.
With this,
app.service('things').recycle(id)
is available anywhere in the app. If you want to have those methods avai…