backend/app/models/auth/PublicUserPermission.model.js

35 lines
907 B
JavaScript
Raw Normal View History

const { Model } = require('flitter-orm')
const uuid = require('uuid/v4')
class PublicUserPermissionModel extends Model {
static get schema() {
return {
associated_user_id: String,
permission: String,
grant_date: { type: Date, default: () => new Date },
UUID: { type: String, default: uuid },
}
}
static async can(permission) {
const permission_parts = permission.split(':')
const permission_checks = []
const current_check = []
for ( const part of permission_parts ) {
current_check.push(part)
permission_checks.push(current_check.join(':'))
}
const match = await this.findOne({
permission: {
$in: permission_checks
}
})
return !!match
}
}
module.exports = exports = PublicUserPermissionModel