Files
lti-web-client/src/services/api/closing.ts
T

185 lines
5.2 KiB
TypeScript

import axios from 'axios';
import { BaseApiService } from '@/services/api/base';
import {
Closing,
ClosingFinance,
ClosingGeneralInformation,
ClosingIncomingSapronak,
ClosingOutgoingSapronak,
ClosingOverhead,
ClosingSapronakCalculation,
ClosingProductionData,
ClosingHppExpedition,
} from '@/types/api/closing';
import { BaseApiResponse } from '@/types/api/api-general';
import { httpClient, httpClientFetcher } from '@/services/http/client';
import { ClosingSales } from '@/types/api/closing';
export class ClosingApiService extends BaseApiService<Closing, null, null> {
constructor(basePath: string) {
super(basePath);
}
async getPenjualan(
id: number
): Promise<BaseApiResponse<ClosingSales> | undefined> {
try {
const getPenjualanPath = `${this.basePath}/${id}/penjualan`;
const getPenjualanRes =
await httpClient<BaseApiResponse<ClosingSales>>(getPenjualanPath);
return getPenjualanRes;
} catch (error) {
if (axios.isAxiosError<BaseApiResponse<ClosingSales>>(error)) {
return error.response?.data;
}
return undefined;
}
}
async getAllIncomingSapronakFetcher(
endpoint: string
): Promise<BaseApiResponse<ClosingIncomingSapronak[]>> {
return await httpClientFetcher<BaseApiResponse<ClosingIncomingSapronak[]>>(
endpoint
);
}
async getAllOutgoingSapronakFetcher(
endpoint: string
): Promise<BaseApiResponse<ClosingOutgoingSapronak[]>> {
return await httpClientFetcher<BaseApiResponse<ClosingOutgoingSapronak[]>>(
endpoint
);
}
async getGeneralInfo(
id: number
): Promise<BaseApiResponse<ClosingGeneralInformation> | undefined> {
try {
const getGeneralInfoPath = `${this.basePath}/${id}`;
const getGeneralInfoRes =
await httpClient<BaseApiResponse<ClosingGeneralInformation>>(
getGeneralInfoPath
);
return getGeneralInfoRes;
} catch (error) {
if (
axios.isAxiosError<BaseApiResponse<ClosingGeneralInformation>>(error)
) {
return error.response?.data;
}
return undefined;
}
}
async getProductionData(
id: number
): Promise<BaseApiResponse<ClosingProductionData> | undefined> {
try {
const getProductionDataPath = `${this.basePath}/${id}/production-data`;
const getProductionDataRes = await httpClient<
BaseApiResponse<ClosingProductionData>
>(getProductionDataPath);
return getProductionDataRes;
} catch (error) {
if (axios.isAxiosError<BaseApiResponse<ClosingProductionData>>(error)) {
return error.response?.data;
}
return undefined;
}
}
async getPerhitunganSapronak(
id: number,
projectKandangId?: number
): Promise<BaseApiResponse<ClosingSapronakCalculation> | undefined> {
try {
const path = `${this.basePath}/${id}${projectKandangId ? `/${projectKandangId}` : ''}/perhitungan_sapronak`;
return await httpClient<BaseApiResponse<ClosingSapronakCalculation>>(
path,
{
method: 'GET',
}
);
} catch (error) {
if (
axios.isAxiosError<BaseApiResponse<ClosingSapronakCalculation>>(error)
) {
return error.response?.data;
}
return undefined;
}
}
async getOverhead(
id: number
): Promise<BaseApiResponse<ClosingOverhead> | undefined> {
try {
const path = `${this.basePath}/${id}/overhead`;
return await httpClient<BaseApiResponse<ClosingOverhead>>(path, {
method: 'GET',
});
} catch (error) {
if (axios.isAxiosError<BaseApiResponse<ClosingOverhead>>(error)) {
return error.response?.data;
}
return undefined;
}
}
async getFinance(
id: number
): Promise<BaseApiResponse<ClosingFinance> | undefined> {
try {
const path = `${this.basePath}/${id}/keuangan`;
return await httpClient<BaseApiResponse<ClosingFinance>>(path, {
method: 'GET',
});
} catch (error) {
if (axios.isAxiosError<BaseApiResponse<ClosingFinance>>(error)) {
return error.response?.data;
}
return undefined;
}
}
async getHppEkspedisi(
id: number
): Promise<BaseApiResponse<ClosingHppExpedition> | undefined> {
try {
const getHppEkspedisiPath = `${this.basePath}/${id}/expedition-hpp`;
const getHppEkspedisiRes =
await httpClient<BaseApiResponse<ClosingHppExpedition>>(
getHppEkspedisiPath
);
return getHppEkspedisiRes;
} catch (error) {
if (axios.isAxiosError<BaseApiResponse<ClosingHppExpedition>>(error)) {
return error.response?.data;
}
return undefined;
}
}
async getHppEkspedisiByKandang(
closingId: number,
kandangId: number
): Promise<BaseApiResponse<ClosingHppExpedition> | undefined> {
try {
const path = `${this.basePath}/${closingId}/${kandangId}/expedition-hpp`;
return await httpClient<BaseApiResponse<ClosingHppExpedition>>(path, {
method: 'GET',
});
} catch (error) {
if (axios.isAxiosError<BaseApiResponse<ClosingHppExpedition>>(error)) {
return error.response?.data;
}
return undefined;
}
}
}
export const ClosingApi = new ClosingApiService('/closings');