27 lines
889 B
TypeScript
27 lines
889 B
TypeScript
import User from "./User";
|
|
import {OneModelRelation} from "../../db/ModelRelation";
|
|
import ModelFactory from "../../db/ModelFactory";
|
|
import {EMAIL_REGEX} from "../../db/Validator";
|
|
|
|
export default class UserEmail extends Model {
|
|
public readonly id?: number = undefined;
|
|
public user_id?: number = undefined;
|
|
public readonly email?: string = undefined;
|
|
public created_at?: Date = undefined;
|
|
|
|
public readonly user = new OneModelRelation<UserEmail, User>(this, ModelFactory.get(User), {
|
|
localKey: 'user_id',
|
|
foreignKey: 'id'
|
|
});
|
|
|
|
constructor(factory: ModelFactory<UserEmail>) {
|
|
super(factory);
|
|
}
|
|
|
|
protected init(): void {
|
|
this.setValidation('user_id').acceptUndefined().exists(User, 'id');
|
|
this.setValidation('email').defined().regexp(EMAIL_REGEX).unique(this);
|
|
this.setValidation('main').defined();
|
|
}
|
|
}
|