import { isNil } from 'lodash' import { Appointment } from '../appointment.model' import { Subscription } from '../subscription.model' import { TeleconsultationCreditReason } from '../types/teleconsultation-credit-reason.type' import { Credit, CreditAuthor } from './credit.model' export class TeleconsultationsCredit extends Credit { appointment_id?: string other_reason?: string static createBy( this: { new (args?: any): T }, params: Partial & { objectModel?: Subscription | Appointment author?: CreditAuthor }, ): T { const { objectModel, reason } = params const credit = this['createCreditBy'](params) if (!isNil(objectModel)) { switch (reason) { case 'appointment_cancellation': case 'appointment_use': credit.appointment_id = objectModel.id break case 'period_renewal': case 'end_of_period_expiration': case 'plan_subscription': credit.subscription_id = objectModel.id break default: break } } if (reason === 'other') credit.other_reason = params.other_reason return credit } }