Sharkey/packages/backend/src/models/entities/AttestationChallenge.ts

47 lines
1 KiB
TypeScript
Raw Normal View History

import { PrimaryColumn, Entity, JoinColumn, Column, ManyToOne, Index } from 'typeorm';
import { id } from '../id.js';
2022-09-17 21:27:08 +03:00
import { User } from './User.js';
@Entity()
export class AttestationChallenge {
@PrimaryColumn(id())
public id: string;
@Index()
@PrimaryColumn(id())
public userId: User['id'];
@ManyToOne(type => User, {
2021-12-09 16:58:30 +02:00
onDelete: 'CASCADE',
})
@JoinColumn()
public user: User | null;
@Index()
@Column('varchar', {
length: 64,
2021-12-09 16:58:30 +02:00
comment: 'Hex-encoded sha256 hash of the challenge.',
})
public challenge: string;
@Column('timestamp with time zone', {
2021-12-09 16:58:30 +02:00
comment: 'The date challenge was created for expiry purposes.',
})
public createdAt: Date;
@Column('boolean', {
comment:
'Indicates that the challenge is only for registration purposes if true to prevent the challenge for being used as authentication.',
2021-12-09 16:58:30 +02:00
default: false,
})
public registrationChallenge: boolean;
constructor(data: Partial<AttestationChallenge>) {
if (data == null) return;
for (const [k, v] of Object.entries(data)) {
(this as any)[k] = v;
}
}
}