import UserEmail from "./UserEmail"; import Model from "../../db/Model"; import Validator from "../../db/Validator"; export default class User extends Model { public static async fromEmail(email: string): Promise { const users = await this.models(this.select().where('id', UserEmail.select('user_id').where('email', email).first()).first()); return users.length > 0 ? users[0] : null; } public name?: string; private is_admin?: boolean; public created_at?: Date; public updated_at?: Date; protected defineProperties(): void { this.defineProperty('name', new Validator().acceptUndefined().between(3, 64)); this.defineProperty('is_admin', new Validator()); this.defineProperty('created_at'); this.defineProperty('updated_at'); } public isAdmin(): boolean { // @ts-ignore return this.is_admin === true || this.is_admin === 1; } }