2020-11-08 17:33:26 +00:00
|
|
|
const Scope = require('flitter-orm/src/model/Scope')
|
|
|
|
|
2020-11-08 18:34:50 +00:00
|
|
|
/**
|
|
|
|
* This is a model scope which excludes any models without is_active = true.
|
|
|
|
* In effect, this provides a mechanism for soft-deletes.
|
|
|
|
*
|
|
|
|
* @extends Scope
|
|
|
|
*/
|
2020-11-08 17:33:26 +00:00
|
|
|
class ActiveScope extends Scope {
|
2020-11-08 18:34:50 +00:00
|
|
|
/**
|
|
|
|
* Apply this scope's conditions to a model filter.
|
|
|
|
* @param to_filter
|
|
|
|
* @return {Promise<*>}
|
|
|
|
*/
|
2020-11-08 17:33:26 +00:00
|
|
|
async filter(to_filter) {
|
|
|
|
return to_filter.equal('is_active', true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = ActiveScope
|