eecs448-project-4/app/models/scopes/Active.scope.js

21 lines
504 B
JavaScript
Raw Normal View History

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