import { Injectable } from '@nestjs/common' import { plainToClass } from 'class-transformer' import { isEmpty } from 'lodash' import { SubscriptionSmartfit } from '../models' import { HttpService } from '../services/http' import { BaseRepository } from './base.repository' const GET_REPORT = ` query getReport { reports: models_subscriptions_concilliation(order_by: {document_number: asc, addon_purchase_date: asc, addon_cancellation_date: asc}) { str_addon: addon_name str_cpf: document_number str_email: email date_compra_addon: addon_purchase_date date_cancelamento_addon: addon_cancellation_date date_solicitacao_cancelamento_addon: addon_cancellation_request_date str_addon_id: addon_id str_pais: country } } ` @Injectable() export class SubscriptionSmartfitRepository extends BaseRepository { constructor(protected readonly httpService: HttpService) { super(httpService, 'models_subscriptions_concilliation') } protected get endpoint(): string { return `${globalThis.secret.hasura_graphql.endpoint}${globalThis.secret.hasura_graphql.path}` } async getReport(): Promise> { const { data, errors } = await this.fetchGraphQL({ body: { query: GET_REPORT, }, throwErrors: false, }) if (errors) throw new Error(errors[0]?.message) return !isEmpty(data) && data.reports.map(report => plainToClass(SubscriptionSmartfit, report)) } }