1.0.5 • Published 2 years ago

loopback-soft-delete-cascade v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

loopback-soft-delete-cascade

Features

  • Soft delete your model
  • Soft deleted records are not displayed
  • Display soft deleted records with query or remote method
  • Restore your soft deleted model
  • Cascade supports 'hasMany' relations
  • Possibility to choose on which relations to activate the cascade
  • Restore cascade
  • Use as mixin

Installation

npm install loopback-soft-delete-cascade --save

How to use

Add the mixins property to your server/model-config.json like the following:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../common/mixins",
      "../node_modules/loopback-soft-delete-cascade"
    ]
  }
}

To use with your Models add the mixins attribute to the definition object of your model config.

{
  "name": "YourModel",
  "mixins": {
	"SoftDelete": {
      "cascade": true, // If you want to activate the cascade on related models
      "relations": [
        "relationName"
      ] // If you want to activate cascade only on specific relations. By default, it applies it to all of them
    },
  },
  "properties": {}
} 

Soft delete mixin add these properties to your model

{
  "is_deleted": {"type": "Boolean"},
  "deleted_at": {"type": "Date"}
} 

Remote method to soft deletation of the Model

POST /YourModel/{id}/soft_delete

Remote method to restore a Model soft deletated

POST /YourModel/{id}/soft_delete_restore

Cascade method add this property to related models

{
  "YourModel_deleted": {"type": "Boolean"}
} 

To also view soft deleted records use filter

YourModel.find({
  where: {
    all: true
  }
}

Or use the remote method to also view soft deleted records

GET /YourModel/all

License

MIT

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago