@sphereon/ssi-sdk.data-store
Version:
45 lines (37 loc) • 1.8 kB
text/typescript
import { ValidationConstraint } from '@sphereon/ssi-sdk.data-store-types'
import { IsNotEmpty, validate, Validate, ValidationError } from 'class-validator'
import { BeforeInsert, BeforeUpdate, ChildEntity, Column } from 'typeorm'
import { getConstraint } from '../../utils/ValidatorUtils'
import { IsNonEmptyStringConstraint } from '../validators'
import { BaseContactEntity } from './BaseContactEntity'
('NaturalPerson')
export class NaturalPersonEntity extends BaseContactEntity {
('varchar', { name: 'first_name', length: 255, nullable: false, unique: false })
({ message: 'Blank first names are not allowed' })
firstName!: string
('varchar', { name: 'middle_name', length: 255, nullable: true, unique: false })
(IsNonEmptyStringConstraint, { message: 'Blank middle names are not allowed' })
middleName?: string
('varchar', { name: 'last_name', length: 255, nullable: false, unique: false })
({ message: 'Blank last names are not allowed' })
lastName!: string
('varchar', { name: 'display_name', length: 255, nullable: false, unique: false })
({ message: 'Blank display names are not allowed' })
displayName!: string
('text', { name: 'owner_id', nullable: true })
ownerId?: string
('text', { name: 'tenant_id', nullable: true })
tenantId?: string
()
()
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))
}
}
}
}