Skip to content

How to represent the recycle (soft-delete) and restore objects in Feathers? #2377

Answered by robbyphillips
koteisaev asked this question in Q&A
Discussion options

You must be logged in to vote

I need to be able to do something like

await app.service("tasks").recycle(taksId);
await app.service("tasks").restore(taksId);
await app.service("tasks").erase(taksId);

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, app.service('things').recycle(id) is available anywhere in the app. If you want to have those methods avai…

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@J3m5
Comment options

@J3m5
Comment options

@koteisaev
Comment options

@J3m5
Comment options

@J3m5
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by koteisaev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants