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.

37 lines
939 B

const { Model } = require('flitter-orm')
const uuid = require('uuid/v4')
class DeviceTokenModel extends Model {
static get schema() {
return {
user_id: String,
create_date: { type: Date, default: () => new Date },
expiration_date: {
type: Date,
default: () => {
const date = new Date();
date.setMonth(date.getMonth() + 1);
return date;
}
},
token: {
type: String,
default: () => {
return Array(5).fill('').map(_ => uuid()).join('').replace(/-/g, '')
}
},
}
}
static async grant_user(user) {
const tok = new this({
user_id: user.id,
})
await tok.save()
return tok
}
}
module.exports = exports = DeviceTokenModel