diff --git a/src/service/slipApi.ts b/src/service/slipApi.ts new file mode 100644 index 0000000..e98e852 --- /dev/null +++ b/src/service/slipApi.ts @@ -0,0 +1,72 @@ +import axios from 'axios' +/** + * 임시전표 저장 + * @param {object} params + * @property {string} params.contNo -계약번호 + * @returns + */ +export async function saveTempSlip(params = {}) { + try { + const result = await axios.post(`/api/slip`, params) + return result.data + } catch (e) { + const serverError = e.response?.data; + + const message = typeof serverError?.body === 'string' + ? serverError.body + : 'Unknown error occurred'; + + const error = new Error(message); // ✅ 반드시 string만 넣기! 아니면 객체가 문자열로 나옴 + error.code = serverError?.code; + error.errTime = serverError?.errTime; + throw error; + } +} + +/** + * 임시전표 삭제 + * @property {string} params.contNo -계약번호 + * @returns + * @param contNo + */ +export async function deleteSlipDetail(contNo: string) { + try { + const result = await axios.delete(`/api/slip/${contNo}`) + return result.data + } catch (e) { + const serverError = e.response?.data; + + const message = typeof serverError?.body === 'string' + ? serverError.body + : 'Unknown error occurred'; + + const error = new Error(message); // ✅ 반드시 string만 넣기! 아니면 객체가 문자열로 나옴 + error.code = serverError?.code; + error.errTime = serverError?.errTime; + throw error; + } +} + +/** + * 전표 상세 조회 + * * @property {string} params.contNo -계약번호 + * * @returns + * * @param contNo + * */ +export async function getSlipDetail(contNo: string) { + try { + const result = await axios.get(`/api/slip/page/${contNo}`) + return result.data + } catch (e) { + const serverError = e.response?.data; + + const message = typeof serverError?.body === 'string' + ? serverError.body + : 'Unknown error occurred'; + + const error = new Error(message); // ✅ 반드시 string만 넣기! 아니면 객체가 문자열로 나옴 + error.code = serverError?.code; + error.errTime = serverError?.errTime; + throw error; + } +} \ No newline at end of file