server/app/models/User.model.js
2020-11-26 19:57:37 -06:00

32 lines
712 B
JavaScript

const { Model } = require('flitter-orm')
const uuid = require('uuid').v4
class User extends Model {
static get services() {
return [...super.services, 'models']
}
static get schema() {
return {
uuid: { type: String, default: uuid },
username: String,
}
}
async get_token() {
const Token = this.models.get('Token')
const existing = await Token.findOne({
active: true,
user_uuid: this.uuid,
})
if ( existing ) return existing
const generated = new Token({ user_uuid: this.uuid })
await generated.save()
return generated
}
}
module.exports = exports = User