parent
b0b62cc50d
commit
b37faa87b3
@ -0,0 +1 @@
|
||||
796aaedc-91d9-4831-ae47-de330967e7b4
|
@ -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
|
Loading…
Reference in new issue