import { Injectable } from '@nestjs/common' import { isEmpty } from 'lodash' import { SmartfitTeacher } from '../models' import { HttpService } from '../services/http' import { BaseRepository } from './base.repository' const ATTRIBUTES = ` id name email document_number photo_url ` const GET_BY_UNIT = ` query smartfit_teachers_by_unit($smartfit_unit_id: Int!) { smartfit_teachers(where: {smartfit_teacher_units: {smartfit_unit_id: {_eq: $smartfit_unit_id}}}) { ${ATTRIBUTES} } } ` @Injectable() export class SmartfitTeacherRepository extends BaseRepository { constructor(protected readonly httpService: HttpService) { super(httpService, 'smartfit_teachers') } async getByUnitId(smartfit_unit_id: number): Promise> { const { data } = await this.fetchGraphQL({ body: { query: GET_BY_UNIT, variables: { smartfit_unit_id } }, }) return isEmpty(data?.smartfit_teachers) ? [] : data.smartfit_teachers.map((value: SmartfitTeacher) => SmartfitTeacher.toInstance(value)) } }