backend/app/models/api/DeviceToken.model.js
garrettmills b37faa87b3
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Add device tokens for resuming user sessions
2020-10-21 23:51:12 -05:00

37 lines
939 B
JavaScript

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