mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
199 lines
5.7 KiB
TypeScript
199 lines
5.7 KiB
TypeScript
import axios from 'axios';
|
|
|
|
import { BaseApiService } from '@/services/api/base';
|
|
import {
|
|
Closing,
|
|
ClosingGeneralInformation,
|
|
ClosingIncomingSapronak,
|
|
ClosingOutgoingSapronak,
|
|
ClosingOverhead,
|
|
ClosingSapronakCalculation,
|
|
} from '@/types/api/closing';
|
|
import { BaseApiResponse } from '@/types/api/api-general';
|
|
import {
|
|
dummyGetAllFetcher,
|
|
dummyGetSingle,
|
|
dummyGetAllIncomingSapronakFetcher,
|
|
dummyGetAllOutgoingSapronakFetcher,
|
|
dummyGetGeneralInfo,
|
|
dummyGetPerhitunganSapronak,
|
|
dummyGetOverhead,
|
|
} from '@/dummy/closing.dummy';
|
|
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 getAllFetcher(endpoint: string): Promise<BaseApiResponse<Closing[]>> {
|
|
// TODO: Remove this block when backend is ready
|
|
// return await dummyGetAllFetcher();
|
|
|
|
// Uncomment this when backend is ready
|
|
return await httpClientFetcher<BaseApiResponse<Closing[]>>(endpoint);
|
|
}
|
|
|
|
async getSingle(id: number): Promise<BaseApiResponse<Closing> | undefined> {
|
|
// TODO: Remove this block when backend is ready
|
|
// try {
|
|
// return await dummyGetSingle(id);
|
|
// } catch (error) {
|
|
// if (axios.isAxiosError<BaseApiResponse<Closing>>(error)) {
|
|
// return error.response?.data;
|
|
// }
|
|
// return undefined;
|
|
// }
|
|
|
|
// Uncomment this when backend is ready
|
|
try {
|
|
const getSinglePath = `${this.basePath}/${id}`;
|
|
const getSingleRes =
|
|
await httpClient<BaseApiResponse<Closing>>(getSinglePath);
|
|
return getSingleRes;
|
|
} catch (error) {
|
|
if (axios.isAxiosError<BaseApiResponse<Closing>>(error)) {
|
|
}
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
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[]>> {
|
|
// TODO: Remove this block when backend is ready
|
|
// return await dummyGetAllIncomingSapronakFetcher();
|
|
|
|
// Uncomment this when backend is ready
|
|
return await httpClientFetcher<BaseApiResponse<ClosingIncomingSapronak[]>>(
|
|
endpoint
|
|
);
|
|
}
|
|
|
|
async getAllOutgoingSapronakFetcher(
|
|
endpoint: string
|
|
): Promise<BaseApiResponse<ClosingOutgoingSapronak[]>> {
|
|
// TODO: Remove this block when backend is ready
|
|
return await dummyGetAllOutgoingSapronakFetcher();
|
|
|
|
// Uncomment this when backend is ready
|
|
// return await httpClientFetcher<BaseApiResponse<ClosingOutgoingSapronak[]>>(
|
|
// endpoint
|
|
// );
|
|
}
|
|
|
|
async getGeneralInfo(
|
|
id: number
|
|
): Promise<BaseApiResponse<ClosingGeneralInformation> | undefined> {
|
|
// TODO: Remove this block when backend is ready
|
|
// try {
|
|
// return await dummyGetGeneralInfo(id);
|
|
// } catch (error) {
|
|
// if (
|
|
// axios.isAxiosError<BaseApiResponse<ClosingGeneralInformation>>(error)
|
|
// ) {
|
|
// return error.response?.data;
|
|
// }
|
|
// return undefined;
|
|
// }
|
|
|
|
// Uncomment this when backend is ready
|
|
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 getPerhitunganSapronak(
|
|
id: number
|
|
): Promise<BaseApiResponse<ClosingSapronakCalculation> | undefined> {
|
|
// TODO: Remove this block when backend is ready
|
|
// try {
|
|
// return await dummyGetPerhitunganSapronak(id);
|
|
// } catch (error) {
|
|
// if (
|
|
// axios.isAxiosError<BaseApiResponse<ClosingSapronakCalculation>>(error)
|
|
// ) {
|
|
// return error.response?.data;
|
|
// }
|
|
// return undefined;
|
|
// }
|
|
|
|
// Uncomment this when backend is ready
|
|
try {
|
|
const path = `${this.basePath}/${id}/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> {
|
|
// TODO: Remove this block when backend is ready
|
|
// try {
|
|
// return await dummyGetOverhead(id);
|
|
// } catch (error) {
|
|
// if (axios.isAxiosError<BaseApiResponse<ClosingOverhead>>(error)) {
|
|
// return error.response?.data;
|
|
// }
|
|
// return undefined;
|
|
// }
|
|
|
|
// Uncomment this when backend is ready
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
export const ClosingApi = new ClosingApiService('/closings');
|