orm/src/model/Scope.js

/**
 * @module flitter-orm/src/model/Scope
 */

const { Injectable } = require('flitter-di')

/**
 * Base class for a filter scope to apply to a model.
 * @extends module:flitter-di/src/Injectable~Injectable
 */
class Scope extends Injectable {

    /**
     * Load in the scope config.
     * @param {object} [config = {}]
     */
    constructor(config = {}) {
        super()

        /**
         * The scope config.
         * @type {Object}
         */
        this.config = config
    }

    /**
     * Apply the scope to the filter.
     * @param {module:flitter-orm/src/filter/Filter~Filter} to_filter - the Filter to modify
     * @returns {Promise<module:flitter-orm/src/filter/Filter~Filter>}
     */
    async filter(to_filter) {
        return to_filter
    }

    /**
     * Make modifications to the record before it is saved in the database.
     * @param {object} record
     * @returns {Promise<object>}
     */
    async save(record) {
        return record
    }
}

module.exports = exports = Scope