36 lines
819 B
JavaScript
36 lines
819 B
JavaScript
|
const { Model } = require('flitter-orm')
|
||
|
|
||
|
// For organizational purposes only.
|
||
|
class GroupModel extends Model {
|
||
|
static get services() {
|
||
|
return [...super.services, 'models']
|
||
|
}
|
||
|
|
||
|
static get schema() {
|
||
|
return {
|
||
|
name: String,
|
||
|
user_ids: [String],
|
||
|
active: { type: Boolean, default: true },
|
||
|
}
|
||
|
}
|
||
|
|
||
|
identifier() {
|
||
|
return this.name.toLowerCase().replace(/\s/g, '_')
|
||
|
}
|
||
|
|
||
|
async users() {
|
||
|
const User = this.models.get('auth:User')
|
||
|
return await User.find({ _id: { $in: this.user_ids.map(x => this.constructor.to_object_id(x)) } })
|
||
|
}
|
||
|
|
||
|
async to_api() {
|
||
|
return {
|
||
|
id: this.id,
|
||
|
name: this.name,
|
||
|
user_ids: this.user_ids,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = exports = GroupModel
|