diff --git a/src/models/entities/Participant.ts b/src/models/entities/Participant.ts index b854160..89fe4c2 100644 --- a/src/models/entities/Participant.ts +++ b/src/models/entities/Participant.ts @@ -5,9 +5,11 @@ import { IsOptional, IsPhoneNumber, + IsPositive, + IsString } from "class-validator"; -import { Column, Entity, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; +import { BeforeInsert, BeforeUpdate, Column, Entity, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; import { config } from '../../config'; import { ResponseParticipant } from '../responses/ResponseParticipant'; import { Address } from "./Address"; @@ -83,6 +85,27 @@ export abstract class Participant { @IsString() created_via?: string; + @Column({ type: 'bigint', nullable: true, readonly: true }) + @IsInt() + @IsPositive() + created_at: number; + + @Column({ type: 'bigint', nullable: true }) + @IsInt() + @IsPositive() + updated_at: number; + + @BeforeInsert() + public setCreatedAt() { + this.created_at = Math.floor(Date.now() / 1000); + this.updated_at = Math.floor(Date.now() / 1000); + } + + @BeforeUpdate() + public setUpdatedAt() { + this.updated_at = Math.floor(Date.now() / 1000); + } + /** * Turns this entity into it's response class. */ diff --git a/src/models/responses/ResponseParticipant.ts b/src/models/responses/ResponseParticipant.ts index 9171466..6418e42 100644 --- a/src/models/responses/ResponseParticipant.ts +++ b/src/models/responses/ResponseParticipant.ts @@ -1,4 +1,4 @@ -import { IsInt, IsObject, IsOptional, IsString } from "class-validator"; +import { IsInt, IsObject, IsOptional, IsPositive, IsString } from "class-validator"; import { Address } from '../entities/Address'; import { Participant } from '../entities/Participant'; import { ResponseObjectType } from '../enums/ResponseObjectType'; @@ -63,6 +63,14 @@ export abstract class ResponseParticipant implements IResponse { @IsObject() address?: Address; + @IsInt() + @IsPositive() + created_at: number; + + @IsInt() + @IsPositive() + updated_at: number; + /** * Creates a ResponseParticipant object from a participant. * @param participant The participant the response shall be build for. @@ -76,5 +84,7 @@ export abstract class ResponseParticipant implements IResponse { this.phone = participant.phone; this.email = participant.email; this.address = participant.address; + this.created_at = participant.created_at; + this.updated_at = participant.updated_at; } }