Merge pull request '260806_01_ENH: 문자 템플릿 저장 json에서 form 방식으로 교체' (#13) from develop into master
Reviewed-on: #13
This commit is contained in:
@@ -3,4 +3,5 @@ NEXT_PUBLIC_API_BASE=http://localhost:6104/api
|
||||
|
||||
ENV=local
|
||||
API_BACK_SERVER=http://localhost:6105/api/v1
|
||||
NOTI_HUB_SERVER=https://noti-hub.kric.com/api/v1
|
||||
NOTI_HUB_SERVER=https://noti-hub.kric.com/api/v1
|
||||
#NOTI_HUB_SERVER=http://localhost:4011/api/v1
|
||||
@@ -42,7 +42,11 @@ export const PATCH = async (
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const body = await req.json().catch(() => null) as SaveTemplateRequest | null;
|
||||
const formData = await req.formData();
|
||||
const templatePart = formData.get("template");
|
||||
const body = templatePart instanceof Blob
|
||||
? JSON.parse(await templatePart.text()) as SaveTemplateRequest
|
||||
: null;
|
||||
if (!body || !body.tmplatIdx) {
|
||||
return NextResponse.json({ message: "Template request body is invalid." }, { status: 400 });
|
||||
}
|
||||
@@ -57,7 +61,13 @@ export const PATCH = async (
|
||||
sendTel: body.sendTel,
|
||||
};
|
||||
|
||||
await notiHubApi.patch<void>("/template", next);
|
||||
const backendForm = new FormData();
|
||||
backendForm.append(
|
||||
"template",
|
||||
new Blob([JSON.stringify(next)], {type: "application/json"})
|
||||
);
|
||||
|
||||
await notiHubApi.patchForm<void>("/template", backendForm);
|
||||
|
||||
return NextResponse.json(next, { status: 200 });
|
||||
} catch (error: unknown) {
|
||||
|
||||
@@ -305,7 +305,10 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
|
||||
const putForm = <T = unknown>(path: string, form: FormData, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "PUT", form });
|
||||
|
||||
return { request, get, post, put, patch, del, postForm, putForm };
|
||||
const patchForm = <T = unknown>(path: string, form: FormData, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "PATCH", form });
|
||||
|
||||
return { request, get, post, put, patch, del, postForm, putForm, patchForm };
|
||||
};
|
||||
|
||||
export const nextApi = createHttpClient(clientEnv.API_BASE);
|
||||
|
||||
@@ -39,8 +39,15 @@ export function useNotificationTemplatesQuery(templateIdxList: number[], enabled
|
||||
|
||||
export function useSaveNotificationTemplateMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (data: SaveTemplateRequest) =>
|
||||
nextApi.patch<Template>("/notification/template", data),
|
||||
mutationFn: (data: SaveTemplateRequest) => {
|
||||
const formData = new FormData();
|
||||
formData.append(
|
||||
"template",
|
||||
new Blob([JSON.stringify(data)], {type: "application/json"})
|
||||
);
|
||||
|
||||
return nextApi.patchForm<Template>("/notification/template", formData);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user