2022-05-10 19:26:44 +00:00
|
|
|
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
|
|
|
|
import ColumnType from '../Types/Database/ColumnType';
|
|
|
|
import ObjectID from '../Types/ObjectID';
|
|
|
|
import BaseModel from './BaseModel';
|
|
|
|
import User from './User';
|
|
|
|
import ColumnLength from '../Types/Database/ColumnLength';
|
|
|
|
import Email from '../Types/Email';
|
2022-05-20 12:30:11 +00:00
|
|
|
import TableColumn from '../Types/Database/TableColumn';
|
2022-06-29 20:51:49 +00:00
|
|
|
import CrudApiEndpoint from '../Types/Database/CrudApiEndpoint';
|
|
|
|
import Route from '../Types/API/Route';
|
2022-06-29 23:09:29 +00:00
|
|
|
import TableColumnType from '../Types/Database/TableColumnType';
|
2022-05-10 19:26:44 +00:00
|
|
|
|
2022-06-29 23:13:28 +00:00
|
|
|
@CrudApiEndpoint(new Route('/email-verification-token'))
|
2022-05-10 19:26:44 +00:00
|
|
|
@Entity({
|
|
|
|
name: 'EmailVerificationToken',
|
|
|
|
})
|
|
|
|
export default class EmailVerificationToken extends BaseModel {
|
2022-06-29 23:13:28 +00:00
|
|
|
@TableColumn({
|
|
|
|
manyToOneRelationColumn: 'userId',
|
|
|
|
required: true,
|
|
|
|
type: TableColumnType.Entity,
|
|
|
|
})
|
2022-05-10 19:26:44 +00:00
|
|
|
@ManyToOne(
|
|
|
|
(_type: string) => {
|
|
|
|
return User;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eager: false,
|
|
|
|
nullable: false,
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
orphanedRowAction: 'nullify',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
@JoinColumn({ name: 'userId' })
|
2022-05-18 20:49:52 +00:00
|
|
|
public user?: User;
|
2022-05-10 19:26:44 +00:00
|
|
|
|
2022-06-29 23:13:28 +00:00
|
|
|
@TableColumn({ type: TableColumnType.ObjectID })
|
2022-05-10 19:26:44 +00:00
|
|
|
@Column({
|
|
|
|
type: ColumnType.ObjectID,
|
|
|
|
nullable: false,
|
|
|
|
transformer: ObjectID.getDatabaseTransformer(),
|
|
|
|
})
|
2022-05-18 20:49:52 +00:00
|
|
|
public userId?: ObjectID;
|
2022-05-10 19:26:44 +00:00
|
|
|
|
2022-06-29 23:13:28 +00:00
|
|
|
@TableColumn({ type: TableColumnType.Email })
|
2022-05-10 19:26:44 +00:00
|
|
|
@Column({
|
|
|
|
type: ColumnType.Email,
|
|
|
|
length: ColumnLength.Email,
|
|
|
|
nullable: false,
|
|
|
|
transformer: Email.getDatabaseTransformer(),
|
|
|
|
})
|
2022-05-19 19:41:12 +00:00
|
|
|
public email?: Email = undefined;
|
2022-05-10 19:26:44 +00:00
|
|
|
|
|
|
|
@Index()
|
2022-06-29 23:13:28 +00:00
|
|
|
@TableColumn({
|
|
|
|
required: true,
|
|
|
|
unique: true,
|
|
|
|
type: TableColumnType.ObjectID,
|
|
|
|
})
|
2022-05-10 19:26:44 +00:00
|
|
|
@Column({
|
|
|
|
type: ColumnType.ObjectID,
|
|
|
|
nullable: false,
|
|
|
|
unique: true,
|
|
|
|
length: ColumnLength.ObjectID,
|
|
|
|
transformer: ObjectID.getDatabaseTransformer(),
|
|
|
|
})
|
2022-05-18 20:49:52 +00:00
|
|
|
public token?: ObjectID;
|
2022-05-10 19:26:44 +00:00
|
|
|
|
2022-06-29 23:09:29 +00:00
|
|
|
@TableColumn({ required: true, type: TableColumnType.Date })
|
2022-05-10 19:26:44 +00:00
|
|
|
@Column({
|
|
|
|
nullable: false,
|
|
|
|
type: ColumnType.Date,
|
|
|
|
})
|
2022-05-18 20:49:52 +00:00
|
|
|
public expires?: Date = undefined;
|
2022-05-10 19:26:44 +00:00
|
|
|
}
|