https://github.com/chancehudson/loopback-archive-mixin
A mixin to archive models instead of delete them
https://github.com/chancehudson/loopback-archive-mixin
Last synced: over 1 year ago
JSON representation
A mixin to archive models instead of delete them
- Host: GitHub
- URL: https://github.com/chancehudson/loopback-archive-mixin
- Owner: chancehudson
- Created: 2017-04-05T00:06:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-07T19:57:03.000Z (over 9 years ago)
- Last Synced: 2024-07-21T00:41:15.000Z (about 2 years ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Archive
=============
This module is designed for the [Strongloop Loopback](https://github.com/strongloop/loopback) framework. It allows entities of any Model to be archived by adding `deletedAt` and `isDeleted` attributes. Queries following the standard format will not return these entities; they can only be accessed by adding `{ deleted: true }` to the query object (at the same level as `where`, `include` etc).
By default `count` and `update` operations will only apply to models that are not deleted. This is overridden by specifying a defined value for either `deletedAt` or `isDeleted`.
This is heavily based on the [loopback-softdelete-mixin](https://github.com/gausie/loopback-softdelete-mixin) by [Samuel Gauss](https://github.com/gausie). (Thanks!)
Install
-------
```bash
npm install --save loopback-archive-mixin
```
Configure
----------
To use with your Models add the `mixins` attribute to the definition object of your model config.
```json
{
"name": "Message",
"properties": {
"name": {
"type": "string",
},
},
"mixins": {
"Archive" : {}
},
},
```
This is a minimal mixin, the only customization is the property names assigned for indicating deletion. The default properties are `deletedAt` and `isDeleted`.
```json
"mixins": {
"Archive": {
"deletedAt": "deletedAt",
"isDeleted": "isDeleted"
},
},
```
Retrieving deleted entities
---------------------------
To run queries that include deleted items in the response, add `{ deleted: true }` to the query object (at the same level as `where`, `include` etc).
By default count and update queries will only operate on models that have not been deleted. Specifying either `deletedAt` or `isDeleted` in the matching clause will run the query like normal.