260806_01_ENH: 문자 템플릿 저장 json에서 form 방식으로 교체

This commit is contained in:
2026-08-06 13:53:00 +09:00
parent cc905433d3
commit 0b125185f5
4 changed files with 27 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);
},
});
}