Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TypedAxios 모듈 생성 #674

Merged
merged 8 commits into from
Apr 28, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
feat: 코드리뷰 반영
Tekiter committed Apr 28, 2023
commit 0a7f7a517ecc2c924e6eeed22dcf416ef0be0486
2 changes: 1 addition & 1 deletion api/endpoint/makers/index.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ export const getMakersProfile = createEndpoint({
method: 'GET',
url: `makers/profile`,
},
serverResponse: z.array(
serverResponseScheme: z.array(
z.object({
id: z.number(),
name: z.string(),
3 changes: 1 addition & 2 deletions api/endpoint/members/index.ts
Original file line number Diff line number Diff line change
@@ -7,15 +7,14 @@ export const getMembersSearchByName = createEndpoint({
method: 'GET',
url: `api/v1/members/search?name=${encodeURIComponent(name)}`,
}),
serverResponse: z.array(
serverResponseScheme: z.array(
z.object({
id: z.number(),
name: z.string(),
generation: z.number(),
hasProfile: z.boolean(),
profileImage: z
.string()
.optional()
.nullable()
.transform((str) => str ?? ''),
}),
4 changes: 2 additions & 2 deletions api/typedAxios.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ export function createEndpoint<
Transformed = z.infer<Validator>,
>(config: {
request: AxiosRequestConfig | ((...params: Param) => AxiosRequestConfig);
serverResponse: Validator;
serverResponseScheme: Validator;
transformer?: (original: z.infer<Validator>) => Transformed;
}): Endpoint<Transformed, Param> {
return {
@@ -29,7 +29,7 @@ export function createEndpoint<

const { data } = await axiosInstance.request<unknown>(axiosConfig);

const res = config.serverResponse.safeParse(data);
const res = config.serverResponseScheme.safeParse(data);

if (!res.success) {
const zodError = String(res.error).slice(0, 1000) + '\n...';