swaf/src/auth/models/UserEmail.ts

27 lines
892 B
TypeScript
Raw Normal View History

2020-04-24 12:12:27 +02:00
import User from "./User";
import Model, {EMAIL_REGEX} from "../../db/Model";
import {OneModelRelation} from "../../db/ModelRelation";
2020-07-24 12:13:28 +02:00
import ModelFactory from "../../db/ModelFactory";
2020-04-24 12:12:27 +02:00
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;
2020-04-24 12:12:27 +02:00
2020-07-24 12:13:28 +02:00
public readonly user = new OneModelRelation<UserEmail, User>(this, ModelFactory.get(User), {
localKey: 'user_id',
foreignKey: 'id'
});
2020-07-26 11:37:01 +02:00
constructor(factory: ModelFactory<UserEmail>) {
super(factory);
2020-04-24 12:12:27 +02:00
}
protected init(): void {
2020-07-24 12:13:28 +02:00
this.setValidation('user_id').acceptUndefined().exists(User, 'id');
this.setValidation('email').defined().regexp(EMAIL_REGEX).unique(this);
this.setValidation('main').defined();
2020-04-24 12:12:27 +02:00
}
2020-07-24 12:13:28 +02:00
}