@sphereon/ssi-sdk.data-store
Version:
36 lines (30 loc) • 1.33 kB
text/typescript
import { IsNotEmpty, validate, ValidationError } from 'class-validator'
import { BeforeInsert, BeforeUpdate, ChildEntity, Column } from 'typeorm'
import { ValidationConstraint } from '../../types'
import { getConstraint } from '../../utils/ValidatorUtils'
import { BaseContactEntity } from './BaseContactEntity'
('Organization')
export class OrganizationEntity extends BaseContactEntity {
('varchar', { name: 'legal_name', length: 255, nullable: false, unique: true })
({ message: 'Blank legal names are not allowed' })
legalName!: 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))
}
}
}
}