@sphereon/ssi-sdk.data-store
Version:
49 lines (39 loc) • 1.84 kB
text/typescript
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { Entity, Column, PrimaryGeneratedColumn, BaseEntity, ManyToOne, BeforeInsert, BeforeUpdate } from 'typeorm'
import { IMetadataEntity, ValidationConstraint } from '../../types'
import { IdentityEntity } from './IdentityEntity'
import { IsNotEmpty, validate, ValidationError } from 'class-validator'
import { getConstraint } from '../../utils/ValidatorUtils'
('IdentityMetadata')
export class IdentityMetadataItemEntity extends BaseEntity implements IMetadataEntity {
('uuid')
id!: string
('varchar', { name: 'label', length: 255, nullable: false })
({ message: 'Blank metadata labels are not allowed' })
label!: string
('varchar', { name: 'valueType', nullable: false })
({ message: 'valueType must not be empty' })
valueType!: string
('varchar', { name: 'stringValue', length: 255, nullable: true })
stringValue?: string
('numeric', { name: 'numberValue', nullable: true })
numberValue?: number
({ name: 'dateValue', nullable: true, type: typeOrmDateTime() })
dateValue?: Date
('boolean', { name: 'boolValue', nullable: true })
boolValue?: boolean
(() => IdentityEntity, (identity: IdentityEntity) => identity.metadata, { cascade: ['insert', 'update'], onDelete: 'CASCADE' })
identity!: IdentityEntity
()
()
async validate(): Promise<void> {
const validation: Array<ValidationError> = await validate(this)
if (validation.length > 0) {
const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
if (constraint) {
const message: string = Object.values(constraint!)[0]
return Promise.reject(Error(message))
}
}
}
}