@sphereon/ssi-sdk.data-store
Version:
89 lines (77 loc) • 2.66 kB
text/typescript
import typeorm from 'typeorm'
const {
BaseEntity,
BeforeInsert,
BeforeUpdate,
Column,
CreateDateColumn,
Entity,
JoinColumn,
OneToOne,
PrimaryGeneratedColumn,
TableInheritance,
UpdateDateColumn,
} = typeorm
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { ImageAttributesEntity } from './ImageAttributesEntity'
import { BackgroundAttributesEntity } from './BackgroundAttributesEntity'
import { TextAttributesEntity } from './TextAttributesEntity'
import { validate, Validate, ValidationError } from 'class-validator'
import { IsNonEmptyStringConstraint } from '../validators'
('BaseLocaleBranding')
({ column: { type: 'varchar', name: 'type' } })
export class BaseLocaleBrandingEntity extends BaseEntity {
('uuid')
id!: string
('varchar', { name: 'alias', length: 255, nullable: true, unique: false })
(IsNonEmptyStringConstraint, { message: 'Blank aliases are not allowed' })
alias?: string
('varchar', { name: 'locale', length: 255, nullable: false, unique: false })
locale?: string
(() => ImageAttributesEntity, {
cascade: true,
onDelete: 'CASCADE',
eager: true,
nullable: true,
})
({ name: 'logoId' })
logo?: ImageAttributesEntity
('varchar', { name: 'description', length: 255, nullable: true, unique: false })
(IsNonEmptyStringConstraint, { message: 'Blank descriptions are not allowed' })
description?: string
(() => BackgroundAttributesEntity, {
cascade: true,
onDelete: 'CASCADE',
eager: true,
nullable: true,
})
({ name: 'backgroundId' })
background?: BackgroundAttributesEntity
(() => TextAttributesEntity, {
cascade: true,
onDelete: 'CASCADE',
eager: true,
nullable: true,
})
({ name: 'textId' })
text?: TextAttributesEntity
({ 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
}
}