Skip to content

Commit

Permalink
♻️ postServer 함수 개선 (#274)
Browse files Browse the repository at this point in the history
필요없는 제너릭 삭제, apiResponse 타입 사용
  • Loading branch information
yyeonzu committed Jan 26, 2025
1 parent 9a1f7ef commit 865d186
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/apis/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,25 @@ import { ApiErrorResponse } from '@src/types/apis/apiResponse';
const SERVER_BASE_URL = '/servers';
const buildServerUrl = (path: string = '') => `${SERVER_BASE_URL}${path}`;

export const postServer = async <
Res = { serverId: number },
Req extends {
name: string;
description: string;
serverImg: File | null;
} = Pick<Server, 'name' | 'description'> & {
serverImg: File | null;
},
>(
body: Req,
export const postServer = async (
body: PostServerReq,
headers?: Record<string, string>,
): Promise<Res> => {
): Promise<ApiSuccessResponse<{ serverId: number }>> => {
const formData = new FormData();
formData.append('name', body.name);
formData.append('description', body.description);
if (body.serverImg) {
formData.append('serverImg', body.serverImg);
}

const response = await authClient.post<Res, AxiosResponse<Res>>(
buildServerUrl(),
formData,
{ headers: { 'Content-Type': 'multipart/form-data', ...headers } },
);
const response = await authClient.post<
ApiResponse<{ serverId: number }>,
AxiosResponse<ApiSuccessResponse<{ serverId: number }>>
>(buildServerUrl(), formData, {
headers: {
'Content-Type': 'multipart/form-data',
...headers,
},
});
return response.data;
};

Expand Down

0 comments on commit 865d186

Please sign in to comment.