sourcefuse/loopback4-soft-delete

Ability to query soft deleted records

Closed this issue · 2 comments

Is your feature request related to a problem? Please describe.
It could be useful in some use cases to query for deleted records. E.g.: Send notification to all users of tenant A that tenant A was deleted. On tenant A soft delete, all its user tenants will also be deleted so querying that information after delete will yield no results.

Describe the solution you'd like
By default deleted: false is applied whenever a query to database is made. E.g.:
{where: {'firstName': 'John'}} is modified to {where: {'firstName': 'John', deleted: false}}
Before modifying this query directly, we can check if query has a deleted parameter. If it has then don't modify the query.
{where: {'firstName': 'John'}} is modified to {where: {'firstName': 'John', deleted: false}}
but
{where: {'firstName': 'John', deleted: true}} is not modified because user is explicitly searching for deleted records

Pseudo code for implementation could look like:

modifyQuery(where: Where<SoftDeleteEntity>) {
  const modifiedWhere = {...where, deleted: where?.deleted ? where.deleted : false}
}

Describe alternatives you've considered
No alternatives considered yet.

Fixed with #32