You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CoreID/app/models/Message.model.js

40 lines
996 B

const { Model } = require('flitter-orm')
class MessageModel extends Model {
static get schema() {
return {
dismissed: {type: Boolean, default: false},
expires: {type: Date, default: () => {
const date = new Date
date.setYear(date.getUTCFullYear() + 1)
return date
}},
display_type: {type: String, default: 'info'},
message: String,
user_id: String,
}
}
static async for_user(user) {
return this.find({ user_id: user.id, dismissed: false, expires: { $gt: new Date } })
}
static async create(user, message, display_type = 'info') {
const msg = new this({
message,
display_type,
user_id: user.id,
})
await msg.save()
return msg
}
async dismiss() {
this.dismissed = true
return this.save()
}
}
module.exports = exports = MessageModel