+
getMoverEstimateRequests({ ...query, cursor: pageParam }),
initialPageParam: undefined as string | undefined,
@@ -24,7 +26,7 @@ export function useMoverEstimateRequests(query: MoverEstimateRequestQuery) {
//견적 반려 조회
export function useRejectedEstimateRequests() {
- return useInfiniteQuery({
+ return useApiInfiniteQuery({
queryKey: QUERY_KEYS.ESTIMATES.REJECTED,
queryFn: ({ pageParam }) => getRejectedEstimateRequests(pageParam),
initialPageParam: undefined as string | undefined,
@@ -41,7 +43,7 @@ type SendMoverEstimateVariables = {
export function useSendMoverEstimate() {
const queryClient = useQueryClient();
- return useMutation({
+ return useApiMutation({
mutationFn: ({ estimateRequestId, input }: SendMoverEstimateVariables) =>
sendMoverEstimate(estimateRequestId, input),
@@ -61,7 +63,7 @@ type RejectMoverEstimateVariables = {
export function useRejectMoverEstimate() {
const queryClient = useQueryClient();
- return useMutation({
+ return useApiMutation({
mutationFn: ({ estimateRequestId, input }: RejectMoverEstimateVariables) =>
rejectMoverEstimate(estimateRequestId, input),
onSuccess: async () => {
diff --git a/src/lib/api/moverEstimateRequests.ts b/src/lib/api/moverEstimateRequests.ts
index d608588b..454ec9d3 100644
--- a/src/lib/api/moverEstimateRequests.ts
+++ b/src/lib/api/moverEstimateRequests.ts
@@ -1,15 +1,15 @@
import type {
MoverEstimateRequestQuery,
- MoverEstimateRequestResponse,
+ MoverEstimateRequestResult,
RejectEstimateRequest,
- RejectEstimateResponse,
- RejectedEstimateRequestListResponse,
+ RejectedEstimate,
+ RejectedEstimateRequestListResult,
SendEstimateRequest,
- SendEstimateResponse,
+ SentEstimate,
} from "@/types/moverEstimateRequest";
-import { API_ROUTES } from "../constants/apiRoutes";
-import axiosInstance from "./axiosInstance";
+import fetchInstance from "@/lib/api/fetchInstance";
+import { API_ROUTES } from "@/lib/constants/apiRoutes";
// 기사 견적 요청 목록 조회
// GET /api/estimates/requests
@@ -34,45 +34,27 @@ export async function getMoverEstimateRequests(query: MoverEstimateRequestQuery)
//이사 유형 필터
query.moveType?.forEach((moveType) => params.append("moveType", moveType));
- const response = await axiosInstance.get(
+ return fetchInstance.get(
`${API_ROUTES.ESTIMATES.REQUESTS}?${params.toString()}`,
);
-
- if (!response.data.success) {
- throw new Error(response.data.error.code);
- }
-
- return response.data.data;
}
// 기사가 고객의 견적 요청에 견적 전송
// POST /api/estimates/requests/:estimateRequestId
-export async function sendMoverEstimate(estimateRequestId: number, input: SendEstimateRequest) {
- const response = await axiosInstance.post(
+export function sendMoverEstimate(estimateRequestId: number, input: SendEstimateRequest) {
+ return fetchInstance.post(
API_ROUTES.ESTIMATES.SEND(estimateRequestId),
input,
);
-
- if (!response.data.success) {
- throw new Error(response.data.error.message);
- }
-
- return response.data.data;
}
// 기사 견적 반려
// POST /api/estimates/requests/:id/reject
-export async function rejectMoverEstimate(estimateRequestId: number, input: RejectEstimateRequest) {
- const response = await axiosInstance.post(
+export function rejectMoverEstimate(estimateRequestId: number, input: RejectEstimateRequest) {
+ return fetchInstance.post(
API_ROUTES.ESTIMATES.REJECT(estimateRequestId),
input,
);
-
- if (!response.data.success) {
- throw new Error(response.data.error.message);
- }
-
- return response.data.data;
}
//기사님 반려 내역 조회
@@ -81,13 +63,7 @@ export async function getRejectedEstimateRequests(cursor?: string, limit = 10) {
const params = new URLSearchParams({ limit: String(limit) });
if (cursor) params.set("cursor", cursor);
- const response = await axiosInstance.get(
+ return fetchInstance.get(
`${API_ROUTES.ESTIMATES.REJECTIONS}?${params.toString()}`,
);
-
- if (!response.data.success) {
- throw new Error(response.data.error.message);
- }
-
- return response.data.data;
}
diff --git a/src/types/moverEstimateRequest.ts b/src/types/moverEstimateRequest.ts
index cdf82f4f..86c69dd3 100644
--- a/src/types/moverEstimateRequest.ts
+++ b/src/types/moverEstimateRequest.ts
@@ -28,25 +28,14 @@ export type MoverEstimateRequestQuery = {
limit: number;
};
-export type MoverEstimateRequestResponse =
- | {
- success: true;
- data: {
- items: MoverEstimateRequest[];
- pagination: {
- nextCursor: string | null;
- hasNextPage: boolean;
- totalCount: number;
- };
- };
- }
- | {
- success: false;
- error: {
- code: string;
- message: string;
- };
- };
+export type MoverEstimateRequestResult = {
+ items: MoverEstimateRequest[];
+ pagination: {
+ nextCursor: string | null;
+ hasNextPage: boolean;
+ totalCount: number;
+ };
+};
// 기사 견적 전송 요청 Body
export type SendEstimateRequest = {
@@ -70,20 +59,6 @@ export type SentEstimate = {
createdAt: string;
};
-// 기사 견적 전송 API 응답
-export type SendEstimateResponse =
- | {
- success: true;
- data: SentEstimate;
- }
- | {
- success: false;
- error: {
- code: string;
- message: string;
- };
- };
-
export type RejectedEstimate = {
id: number;
estimateRequestId: number;
@@ -92,19 +67,6 @@ export type RejectedEstimate = {
createdAt: string;
};
-export type RejectEstimateResponse =
- | {
- success: true;
- data: RejectedEstimate;
- }
- | {
- success: false;
- error: {
- code: string;
- message: string;
- };
- };
-
//기사 견적 반려 조회
export type RejectedEstimateRequestItem = {
id: number;
@@ -126,21 +88,10 @@ export type RejectedEstimateRequestItem = {
};
};
-export type RejectedEstimateRequestListResponse =
- | {
- success: true;
- data: {
- items: RejectedEstimateRequestItem[];
- pagination: {
- nextCursor: string | null;
- hasNextPage: boolean;
- };
- };
- }
- | {
- success: false;
- error: {
- code: string;
- message: string;
- };
- };
+export type RejectedEstimateRequestListResult = {
+ items: RejectedEstimateRequestItem[];
+ pagination: {
+ nextCursor: string | null;
+ hasNextPage: boolean;
+ };
+};