Add device tokens for resuming user sessions
This commit is contained in:
36
app/models/api/DeviceToken.model.js
Normal file
36
app/models/api/DeviceToken.model.js
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
Reference in New Issue
Block a user