mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-40): create api service for nonstock
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import axios from 'axios';
|
||||
import { httpClient } from '@/services/http/client';
|
||||
|
||||
import {
|
||||
CreateNonstockPayload,
|
||||
DeleteNonstockResponse,
|
||||
NonstockResponse,
|
||||
UpdateNonstockPayload,
|
||||
} from '@/types/api/master-data/nonstock';
|
||||
|
||||
export const getNonstock = async (nonstockId: number) => {
|
||||
try {
|
||||
const getNonstockRes = await httpClient<NonstockResponse>(
|
||||
`/master-data/nonstocks/${nonstockId}`
|
||||
);
|
||||
|
||||
return getNonstockRes;
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError<NonstockResponse>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const createNonstock = async (payload: CreateNonstockPayload) => {
|
||||
try {
|
||||
const createNonstockRes = await httpClient<NonstockResponse>(
|
||||
'/master-data/nonstocks',
|
||||
{
|
||||
method: 'POST',
|
||||
body: payload,
|
||||
}
|
||||
);
|
||||
|
||||
return createNonstockRes;
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError<NonstockResponse>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateNonstock = async (
|
||||
nonstockId: number,
|
||||
payload: UpdateNonstockPayload
|
||||
) => {
|
||||
try {
|
||||
const updateNonstockRes = await httpClient<NonstockResponse>(
|
||||
`/master-data/nonstocks/${nonstockId}`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
body: payload,
|
||||
}
|
||||
);
|
||||
|
||||
return updateNonstockRes;
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError<NonstockResponse>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteNonstock = async (nonstockId: number) => {
|
||||
try {
|
||||
const deleteNonstockRes = await httpClient<DeleteNonstockResponse>(
|
||||
`/master-data/nonstocks/${nonstockId}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
}
|
||||
);
|
||||
|
||||
return deleteNonstockRes;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError<DeleteNonstockResponse>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user