|
| 1 | +import { createPagination } from '@clab-platforms/utils'; |
| 2 | + |
| 3 | +import { END_POINT } from '@constants/api'; |
| 4 | + |
| 5 | +import type { |
| 6 | + BaseResponse, |
| 7 | + ResponsePagination, |
| 8 | + WithPaginationParams, |
| 9 | +} from '@type/api'; |
| 10 | +import type { |
| 11 | + Support, |
| 12 | + SupportAnswerRequest, |
| 13 | + SupportDetail, |
| 14 | + SupportWriteRequest, |
| 15 | +} from '@type/support'; |
| 16 | + |
| 17 | +import { server } from './server'; |
| 18 | +import { |
| 19 | + postFilesSupportImages, |
| 20 | + postUploadedFileBoard, |
| 21 | + uploadFiles, |
| 22 | +} from './uploadedFile'; |
| 23 | + |
| 24 | +export interface PostSupportsWriteParams extends SupportWriteRequest { |
| 25 | + file?: File; |
| 26 | +} |
| 27 | +export interface PatchSupportsParams extends SupportWriteRequest { |
| 28 | + id: number; |
| 29 | + file?: File; |
| 30 | +} |
| 31 | +export interface PostAnswersParams extends SupportAnswerRequest { |
| 32 | + id: number; |
| 33 | +} |
| 34 | +export interface PatchAnswersParams extends SupportAnswerRequest { |
| 35 | + id: number; |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * 내가 작성한 문의 조회 |
| 40 | + */ |
| 41 | +export async function getMySupports({ page, size }: WithPaginationParams) { |
| 42 | + const { data } = await server.get<ResponsePagination<Support>>({ |
| 43 | + url: createPagination(END_POINT.MY_SUPPORTS, { page, size }), |
| 44 | + }); |
| 45 | + |
| 46 | + return data; |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * 문의 목록 조회 |
| 51 | + */ |
| 52 | +export async function getSupportList({ page, size }: WithPaginationParams) { |
| 53 | + const { data } = await server.get<ResponsePagination<Support>>({ |
| 54 | + url: createPagination(END_POINT.SUPPORTS, { page, size }), |
| 55 | + }); |
| 56 | + return data; |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * 문의 작성 |
| 61 | + */ |
| 62 | +export async function postSupportsWrite(data: PostSupportsWriteParams) { |
| 63 | + if (data.file) { |
| 64 | + const files = await uploadFiles([data.file], postUploadedFileBoard); |
| 65 | + if (!files?.[0]?.fileUrl) { |
| 66 | + throw new Error('파일 업로드에 실패했습니다.'); |
| 67 | + } |
| 68 | + data.imageUrl = files[0].fileUrl; |
| 69 | + } |
| 70 | + |
| 71 | + return server.post<SupportWriteRequest, BaseResponse<number>>({ |
| 72 | + url: END_POINT.SUPPORTS, |
| 73 | + body: data, |
| 74 | + }); |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * 문의 상세 조회 |
| 79 | + */ |
| 80 | +export function getSupportsDetail(id: number) { |
| 81 | + return server.get<BaseResponse<SupportDetail>>({ |
| 82 | + url: END_POINT.SUPPORTS_ITEM(id), |
| 83 | + }); |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * 문의 수정 |
| 88 | + */ |
| 89 | +export async function patchSupports({ |
| 90 | + id, |
| 91 | + file, |
| 92 | + ...data |
| 93 | +}: PatchSupportsParams) { |
| 94 | + if (file) { |
| 95 | + const uploadedFile = await uploadFiles([file], postFilesSupportImages); |
| 96 | + if (!uploadedFile?.[0]?.fileUrl) { |
| 97 | + throw new Error('파일 업로드에 실패했습니다.'); |
| 98 | + } |
| 99 | + data.imageUrl = uploadedFile[0].fileUrl; |
| 100 | + } |
| 101 | + |
| 102 | + return server.patch<SupportWriteRequest, BaseResponse<number>>({ |
| 103 | + url: END_POINT.SUPPORTS_ITEM(id), |
| 104 | + body: data, |
| 105 | + }); |
| 106 | +} |
| 107 | + |
| 108 | +/** |
| 109 | + * 문의 삭제 |
| 110 | + */ |
| 111 | +export function deleteSupports(id: number) { |
| 112 | + return server.del<never, BaseResponse<number>>({ |
| 113 | + url: END_POINT.SUPPORTS_ITEM(id), |
| 114 | + }); |
| 115 | +} |
| 116 | + |
| 117 | +/** |
| 118 | + * 답변 작성 |
| 119 | + */ |
| 120 | +export async function postAnswersWrite({ id, ...data }: PostAnswersParams) { |
| 121 | + return server.post<SupportAnswerRequest, BaseResponse<number>>({ |
| 122 | + url: END_POINT.ANSWERS_ITEM(id), |
| 123 | + body: data, |
| 124 | + }); |
| 125 | +} |
| 126 | + |
| 127 | +/** |
| 128 | + * 답변 수정 |
| 129 | + */ |
| 130 | +export async function patchAnswers({ id, ...data }: PatchAnswersParams) { |
| 131 | + return server.patch<SupportAnswerRequest, BaseResponse<number>>({ |
| 132 | + url: END_POINT.ANSWERS_ITEM(id), |
| 133 | + body: data, |
| 134 | + }); |
| 135 | +} |
0 commit comments