import { Injectable } from '@nestjs/common' import { isEmpty } from 'lodash' import { plainToClass } from 'class-transformer' import { AppointmentCancelReason } from '../models' import { HttpService } from '../services/http' import { BaseRepository } from './base.repository' const GET = ` query appointmentCancelReason($value: String) { appointment_cancel_reason(where: {value: {_eq: $value}}) { value description decrease_credit visible type block_when_transfer } } ` @Injectable() export class AppointmentCancelReasonRepository extends BaseRepository { constructor(protected readonly httpService: HttpService) { super(httpService, 'appointment_cancel_reason') } async get(value: string): Promise { const { data } = await this.fetchGraphQL({ body: { query: GET, variables: { value } }, }) return isEmpty(data.appointment_cancel_reason) ? null : plainToClass(AppointmentCancelReason, data.appointment_cancel_reason[0]) } }