@sphereon/ssi-sdk.data-store
Version:
63 lines (55 loc) • 1.94 kB
text/typescript
import {
BaseEntity,
BeforeInsert,
BeforeUpdate,
Column,
CreateDateColumn,
Entity,
Index,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm'
import { ArrayMinSize, IsNotEmpty, validate, ValidationError } from 'class-validator'
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { IssuerLocaleBrandingEntity } from './IssuerLocaleBrandingEntity'
('IssuerBranding')
('IDX_IssuerBrandingEntity_issuerCorrelationId', ['issuerCorrelationId'])
export class IssuerBrandingEntity extends BaseEntity {
('uuid')
id!: string
('varchar', { name: 'issuerCorrelationId', length: 255, nullable: false, unique: true })
({ message: 'Blank issuerCorrelationIds are not allowed' })
issuerCorrelationId!: string
(
() => IssuerLocaleBrandingEntity,
(issuerLocaleBrandingEntity: IssuerLocaleBrandingEntity) => issuerLocaleBrandingEntity.issuerBranding,
{
cascade: true,
onDelete: 'CASCADE',
eager: true,
nullable: false,
},
)
(1, { message: 'localeBranding cannot be empty' })
localeBranding!: Array<IssuerLocaleBrandingEntity>
({ name: 'created_at', nullable: false, type: typeOrmDateTime() })
createdAt!: Date
({ name: 'last_updated_at', nullable: false, type: typeOrmDateTime() })
lastUpdatedAt!: Date
// By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
()
()
updateUpdatedDate(): void {
this.lastUpdatedAt = new Date()
}
()
()
async validate(): Promise<undefined> {
const validation: Array<ValidationError> = await validate(this)
if (validation.length > 0) {
return Promise.reject(Error(Object.values(validation[0].constraints!)[0]))
}
return
}
}