44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
|
|
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<IPaginatedResponse<ICardexResponse>> {
|
||
|
|
return this.http
|
||
|
|
.get<IPaginatedResponse<ICardexRawResponse>>(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,
|
||
|
|
})),
|
||
|
|
};
|
||
|
|
}),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|