Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 10 additions & 34 deletions src/lib/api/moverEstimateRequests.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type {
MoverEstimateRequestQuery,
MoverEstimateRequestResponse,
MoverEstimateRequestListResult,
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
Expand All @@ -34,45 +34,27 @@ export async function getMoverEstimateRequests(query: MoverEstimateRequestQuery)
//이사 유형 필터
query.moveType?.forEach((moveType) => params.append("moveType", moveType));

const response = await axiosInstance.get<MoverEstimateRequestResponse>(
return fetchInstance.get<MoverEstimateRequestListResult>(
`${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<SendEstimateResponse>(
return fetchInstance.post<SentEstimate, SendEstimateRequest>(
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<RejectEstimateResponse>(
return fetchInstance.post<RejectedEstimate, RejectEstimateRequest>(
API_ROUTES.ESTIMATES.REJECT(estimateRequestId),
input,
);

if (!response.data.success) {
throw new Error(response.data.error.message);
}

return response.data.data;
}

//기사님 반려 내역 조회
Expand All @@ -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<RejectedEstimateRequestListResponse>(
return fetchInstance.get<RejectedEstimateRequestListResult>(
`${API_ROUTES.ESTIMATES.REJECTIONS}?${params.toString()}`,
);

if (!response.data.success) {
throw new Error(response.data.error.message);
}

return response.data.data;
}
79 changes: 15 additions & 64 deletions src/types/moverEstimateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 MoverEstimateRequestListResult = {
items: MoverEstimateRequest[];
pagination: {
nextCursor: string | null;
hasNextPage: boolean;
totalCount: number;
};
};

// 기사 견적 전송 요청 Body
export type SendEstimateRequest = {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
};
};