import { Transform } from 'class-transformer' import { isNil, isString } from 'lodash' import { parseISO } from '../utils/date' import { Timezone, CountryCode } from '../utils/countries' import { UserRestriction } from './user_restriction.model' import { UserGoal } from './user_objective.model' import { Roles } from './enums/roles.enum' export class User { id: string bio: string country_code: CountryCode professional_document: string document_number: string email: string external_id: string instagram: string is_definitive: string linkedin: string name: string whatsapp: string photo_url: string @Transform(value => parseISO(value), { toClassOnly: true }) updated_at: Date @Transform(value => parseISO(value), { toClassOnly: true }) created_at: Date @Transform(value => parseISO(value), { toClassOnly: true }) inactivated_at: Date @Transform(value => parseISO(value), { toClassOnly: true }) activated_at?: Date @Transform(value => parseISO(value), { toClassOnly: true }) approved_at?: Date @Transform(value => parseISO(value), { toClassOnly: true }) reproved_at?: Date reproved_reason?: string timezone: Timezone remuneration_teleconsultation_plan?: number remuneration_teleconsultation_single?: number @Transform( (value: Array) => value.map(restriction => isString(restriction) ? new UserRestriction({ restriction_id: restriction }) : restriction, ), { toClassOnly: true }, ) users_restrictions: UserRestriction[] @Transform((value: Array) => value.map(goal => (isString(goal) ? new UserGoal({ goal_id: goal }) : goal)), { toClassOnly: true, }) users_goals: UserGoal[] role: Roles constructor(args: Partial) { Object.assign(this, args) } get locale(): string { return this.country_code.split('_')[0] } get isActive(): boolean { return isNil(this.inactivated_at) } get restriction_ids(): string[] { return (this.users_restrictions ?? []).map((r: UserRestriction) => r.restriction_id) } get goal_ids(): string[] { return (this.users_goals ?? []).map((r: UserGoal) => r.goal_id) } get firstName(): string { return this.name.split(' ')[0] } }