mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
fix(FE): revert require auth component
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import axios from 'axios';
|
||||
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
import {
|
||||
Closing,
|
||||
ClosingGeneralInformation,
|
||||
ClosingIncomingSapronak,
|
||||
ClosingOutgoingSapronak,
|
||||
ClosingSapronakCalculation,
|
||||
} from '@/types/api/closing';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import {
|
||||
dummyGetAllFetcher,
|
||||
dummyGetSingle,
|
||||
dummyGetAllIncomingSapronakFetcher,
|
||||
dummyGetAllOutgoingSapronakFetcher,
|
||||
dummyGetGeneralInfo,
|
||||
dummyGetPerhitunganSapronak,
|
||||
} from '@/dummy/closing.dummy';
|
||||
import { httpClient, httpClientFetcher } from '@/services/http/client';
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const ClosingApi = new ClosingApiService('/closings');
|
||||
Reference in New Issue
Block a user