import { IPaginatedResponse } from '@/core/models/service.model'; import { getFullName } from '@/utils'; import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { map, Observable } from 'rxjs'; import { CARDEX_API_ROUTES } from '../constants'; import { ICardexRawResponse, ICardexRequestPayload, ICardexResponse } from '../models'; @Injectable({ providedIn: 'root' }) export class CardexService { constructor(private http: HttpClient) {} private apiRoutes = CARDEX_API_ROUTES; getCardex(params: ICardexRequestPayload): Observable> { return this.http .get>(this.apiRoutes.cardex(), { params: { ...params }, }) .pipe( map((res) => { return { meta: res.meta, data: res.data.map((item) => ({ ...item, supplier: item.supplier ? { ...item.supplier, name: getFullName(item.supplier), } : undefined, customer: item.customer ? { ...item.customer, name: getFullName(item.customer), } : undefined, })), }; }), ); } }