import { Expose , Type } from 'class-transformer' ; import { IsEmail , IsEnum , IsObject , IsOptional , MaxLength , MinLength , ValidateIf , ValidateNested , } from 'class-validator' ; import { IsCog } from '@fc/cog' ; import { IsSafeString } from '@fc/common' ; import { MinIdentityDto } from '@fc/oidc-client' ; import { Genders } from '@fc/rnipp' ; const COG_FRANCE = '99100' ; class IdentityAddress { @ IsSafeString ( ) @ IsOptional ( ) @ Expose ( ) country ? : string ; @ IsSafeString ( ) @ IsOptional ( ) @ Expose ( ) formatted ? : string ; @ IsSafeString ( ) @ IsOptional ( ) @ Expose ( ) locality ? : string ; @ ValidateIf ( ( { postal_code : pc } ) => pc ) @ IsCog ( ) @ Expose ( ) postal_code ? : string ; @ IsSafeString ( ) @ IsOptional ( ) @ Expose ( ) street_address ? : string ; } export class OidcIdentityDto extends MinIdentityDto { @ IsSafeString ( ) @ MinLength ( 1 ) @ MaxLength ( 256 ) @ Expose ( ) readonly given_name : string ; @ IsSafeString ( ) @ MinLength ( 1 ) @ MaxLength ( 256 ) @ Expose ( ) readonly family_name : string ; @ IsSafeString ( ) @ Expose ( ) readonly birthdate : string ; @ IsSafeString ( ) @ IsEnum ( Genders ) @ Expose ( ) readonly gender : string ; @ ValidateIf ( OidcIdentityDto . shouldValidateBirthplace ) @ IsCog ( ) @ Expose ( ) readonly birthplace : string ; @ IsCog ( ) @ Expose ( ) readonly birthcountry : string ; @ IsSafeString ( ) @ IsOptional ( ) @ Expose ( ) readonly preferred_username ? : string ; @ IsEmail ( ) @ Expose ( ) readonly email : string ; todo author Nicolas Legeay
     *  date ticket @ IsSafeString ( ) @ IsOptional ( ) @ Expose ( ) readonly phone_number ? : string ; @ IsObject ( ) @ IsOptional ( ) @ ValidateNested ( ) @ Type ( ( ) => IdentityAddress ) @ Expose ( ) readonly address ? : IdentityAddress ; static shouldValidateBirthplace ( instance ) { return instance . birthcountry === COG_FRANCE ; } }