import { BeforeUpdate , Column , CreateDateColumn , Entity , Index , ManyToMany , PrimaryGeneratedColumn , UpdateDateColumn , } from 'typeorm' ; import { IsDate , IsOptional , IsString , Length } from 'class-validator' ; import config = require ( '../../../config' ) ; import { DatabaseType } from '../../index' ; import { ITagDb } from '../../Interfaces' ; import { WorkflowEntity } from './WorkflowEntity' ; function getTimestampSyntax ( ) { const dbType = config . get ( 'database.type' ) as DatabaseType ; const map = { sqlite : "STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')" , postgresdb : 'CURRENT_TIMESTAMP(3)' , mysqldb : 'CURRENT_TIMESTAMP(3)' , mariadb : 'CURRENT_TIMESTAMP(3)' , } ; return map [ dbType ] ; } @ Entity ( ) export class TagEntity implements ITagDb { @ PrimaryGeneratedColumn ( ) id : number ; @ Column ( { length : 24 } ) @ Index ( { unique : true } ) @ IsString ( { message : 'Tag name must be of type string.' } ) @ Length ( 1 , 24 , { message : 'Tag name must be 1 to 24 characters long.' } ) name : string ; @ CreateDateColumn ( { precision : 3 , default : ( ) => getTimestampSyntax ( ) } ) @ IsOptional ( ) @ IsDate ( ) createdAt : Date ; @ UpdateDateColumn ( { precision : 3 , default : ( ) => getTimestampSyntax ( ) , onUpdate : getTimestampSyntax ( ) , } ) @ IsOptional ( ) @ IsDate ( ) updatedAt : Date ; @ ManyToMany ( ( ) => WorkflowEntity , ( workflow ) => workflow . tags ) workflows : WorkflowEntity [ ] ; @ BeforeUpdate ( ) setUpdateDate ( ) { this . updatedAt = new Date ( ) ; } }