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/LoginMessage.model.js

40 lines
938 B

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