import { Injectable } from '@nestjs/common' import { plainToClass } from 'class-transformer' import { Country } from '../models' import { HttpService } from '../services/http' import { BaseRepository } from './base.repository' const ATTRIBUTES = ` id code name_iso name_pt main_language_code ` const ALL = ` query countries { countries(order_by: {name_iso: asc}) { ${ATTRIBUTES} } } ` @Injectable() export class CountryRepository extends BaseRepository { constructor(protected readonly httpService: HttpService) { super(httpService, 'countries') } async findAll(): Promise> { const { data } = await this.fetchGraphQL({ body: { query: ALL }, }) return (data.countries || []).map(country => plainToClass(Country, country)) } }