You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(chore): remove duplicate code and deprecate DefaultTransactionSoftCrudRepository (#131)
* fix(chore): add #122 changes in mixin and transaction repository
add development note to ensure future modifications universal
add changes made in PR #122 in
soft-crud mixin and transaction-soft-crud repository
GH-129
* refactor(chore): add common service and decorator for filter modification
created soft crud service file containing common code among artifacts
created softFilter and
excludeSoftDeleted decorator for the common tasks
GH-128
* refactor(repository): deprecate `DefaultTransactionSoftCrudRepository`
in favor of SoftCrudRepositoryMixin for improving maintainability
GH-132
* refactor(repository): replace modify functions with custom soft filter builder
removed soft-crud service and used custom soft filter builder class providing methods like
imposeCondition, fields etc.
GH-0
* refactor(chore): resolve sonar code smells
ignore transactional respotory file in sonar as this is deprecated and kept duplicacy of the code
just for few months of support
add avoid rule for arrowParens in prettier
GH-0
For a quick starter guide, you can refer to our [loopback 4 starter](https://github.com/sourcefuse/loopback4-starter) application which utilizes this package for soft-deletes in a multi-tenant application.
24
24
25
-
## Transaction support
25
+
## Usage
26
26
27
-
With version 3.0.0, transaction repository support has been added. In place of SoftCrudRepository, extend your repository with DefaultTransactionSoftCrudRepository. For further usage guidelines, refer below.
27
+
The package exports following classes and mixins:
28
28
29
-
## Usage
29
+
1.[SoftDeleteEntity](#softdeleteentity) - To add required soft delete props in the model.
30
+
2.[SoftCrudRepository](#softcrudrepository) - Class providing soft crud capabilitiies (to be used in place of `DefaultCrudRepository`).
31
+
3.[SoftCrudRepositoryMixin](#softcrudrepositorymixin) - Mixin accepting any respository that extends the DefaultCrudRepository to add soft delete functionality to. Can be used as a wrapper for `DefaultCrudRepository`, `DefaultTransactionalRepository` etc.
32
+
4.[SoftDeleteEntityMixin](#softdeleteentitymixin)
33
+
5.[DefaultTransactionSoftCrudRepository](#defaulttransactionsoftcrudrepository-deprecated) (Deprecated) - Class providing soft crud capabilitiies. To be used in place of `DefaultTransactionalRepository`.
34
+
35
+
Following are more details on the usage of above artifcats:
36
+
37
+
### SoftDeleteEntity
38
+
39
+
An abstract base class for all models which require soft delete feature.
40
+
This class is a wrapper over Entity class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository) adding three attributes to the model class for handling soft-delete, namely, deleted, deletedOn, deletedBy.
41
+
The column names needed to be there in DB within that table are - 'deleted', 'deleted_on', 'deleted_by'.
42
+
If you are using auto-migration of loopback 4, then, you may not need to do anything specific to add this column.
43
+
If not, then please add these columns to the DB table.
44
+
45
+
### SoftCrudRepository
46
+
47
+
An abstract base class for all repositories which require soft delete feature.
48
+
This class is going to be the one which handles soft delete operations and ensures soft deleted entries are not returned in responses, However if there is a need to query soft deleted entries as well, there is an options to achieve that and you can use findAll() in place of find() , findOneIncludeSoftDelete() in place of findOne() and findByIdIncludeSoftDelete() in place of findById(), these will give you the responses including soft deleted entries.
49
+
This class is a wrapper over DefaultCrudRepository class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository).
Right now, this extension exports three abstract classes which are actually helping with soft delete operations.
53
+
> Note: `DefaultTransactionSoftCrudRepository` is deprecated in favour of [SoftCrudRepositoryMixin](#softcrudrepositorymixin) and will be removed in future releases.
32
54
33
-
-**SoftDeleteEntity** -
34
-
An abstract base class for all models which require soft delete feature.
35
-
This class is a wrapper over Entity class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository) adding three attributes to the model class for handling soft-delete, namely, deleted, deletedOn, deletedBy.
36
-
The column names needed to be there in DB within that table are - 'deleted', 'deleted_on', 'deleted_by'.
37
-
If you are using auto-migration of loopback 4, then, you may not need to do anything specific to add this column.
38
-
If not, then please add these columns to the DB table.
39
-
-**SoftCrudRepository** -
40
-
An abstract base class for all repositories which require soft delete feature.
41
-
This class is going to be the one which handles soft delete operations and ensures soft deleted entries are not returned in responses, However if there is a need to query soft deleted entries as well,there is an options to achieve that and you can use findAll() in place of find() , findOneIncludeSoftDelete() in place of findOne() and findByIdIncludeSoftDelete() in place of findById(), these will give you the responses including soft deleted entries.
42
-
This class is a wrapper over DefaultCrudRepository class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository).
43
-
-**DefaultTransactionSoftCrudRepository** -
44
-
An abstract base class for all repositories which require soft delete feature with transaction support.
45
-
This class is going to be the one which handles soft delete operations and ensures soft deleted entries are not returned in responses, However if there is a need to query soft deleted entries as well,there is an options to achieve that and you can use findAll() in place of find() , findOneIncludeSoftDelete() in place of findOne() and findByIdIncludeSoftDelete() in place of findById(), these will give you the responses including soft deleted entries.
46
-
This class is a wrapper over DefaultTransactionalRepository class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository).
55
+
An abstract base class similar to [SoftCrudRepository](#softcrudrepository) but with transaction support.
47
56
48
-
In order to use this extension in your LB4 application, please follow below steps.
57
+
This class is a wrapper over `DefaultTransactionalRepository` class from [@loopback/repository](https://github.com/strongloop/loopback-next/tree/master/packages/repository).
49
58
50
-
1. Extend models with SoftDeleteEntity class replacing Entity. For example,
59
+
In order to use this extension in your application, please follow below steps.
60
+
61
+
1. Extend models with SoftDeleteEntity class replacing Entity. Like below:
@@ -117,20 +128,17 @@ export class UserRepository extends DefaultTransactionSoftCrudRepository<
117
128
}
118
129
```
119
130
131
+
## Mixins Usage
132
+
120
133
The package also provides the following mixins which can be used for soft delete functionality:
121
134
122
-
-**SoftDeleteEntityMixin**: This mixin adds the soft delete properties to your model. The properties added are represented by the IBaseEntity interface:
135
+
### SoftDeleteEntityMixin
123
136
124
-
```ts
125
-
interfaceIBaseEntity {
126
-
deleted?:boolean;
127
-
deletedOn?:Date;
128
-
deletedBy?:string;
129
-
}
130
-
```
137
+
This mixin adds the soft delete properties to your model. The properties added are represented by the [IBaseEntity](#ibaseentity) interface:
131
138
132
-
There is also an option to provide config for the @property decorator for all these properties.
133
-
Usage of SoftDeleteEntityMixin is as follows:
139
+
There is also an option to provide config for the `@property` decorator for all these properties.
-**SoftCrudRepositoryMixin**: You can make use of this mixin to get the soft delete functionality for DefaultCrudRepository or any respository that extends the DefaultCrudRepository. You need to extend your repository with this mixin and provide DefaultCrudRepository (or any repository that extends DefaultCrudRepository) as input. This means that this same mixin can also be used to provide soft delete functionality for DefaultTransactionSoftCrudRepository ( as DefaultTransactionSoftCrudRepository extends DefaultCrudRepository).You will have to inject the getter for IAuthUser in the contructor of your repository.
162
-
Example:
171
+
#### IBaseEntity
172
+
173
+
The soft deleted properties added by [SoftDeleteEntityMixin](#softdeleteentitymixin) are represented by `IBaseEntity` interface.
174
+
175
+
```ts
176
+
interfaceIBaseEntity {
177
+
deleted?:boolean;
178
+
deletedOn?:Date;
179
+
deletedBy?:string;
180
+
}
181
+
```
182
+
183
+
### SoftCrudRepositoryMixin
184
+
185
+
You can make use of this mixin to get the soft delete functionality for `DefaultCrudRepository` or any respository that extends the `DefaultCrudRepository`. You need to extend your repository with this mixin and provide DefaultCrudRepository (or any repository that extends DefaultCrudRepository) as input. This means that this same mixin can also be used to provide soft delete functionality for DefaultTransactionSoftCrudRepository (as DefaultTransactionSoftCrudRepository extends DefaultCrudRepository). You will have to inject the getter for IAuthUser in the contructor of your repository.
0 commit comments