diff --git a/.env.local b/.env.local index bc738a6..fc56c08 100644 --- a/.env.local +++ b/.env.local @@ -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 \ No newline at end of file +NOTI_HUB_SERVER=https://noti-hub.kric.com/api/v1 +#NOTI_HUB_SERVER=http://localhost:4011/api/v1 \ No newline at end of file diff --git a/src/app/api/notification/[[...slug]]/route.ts b/src/app/api/notification/[[...slug]]/route.ts index 2ec0891..3837f36 100644 --- a/src/app/api/notification/[[...slug]]/route.ts +++ b/src/app/api/notification/[[...slug]]/route.ts @@ -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("/template", next); + const backendForm = new FormData(); + backendForm.append( + "template", + new Blob([JSON.stringify(next)], {type: "application/json"}) + ); + + await notiHubApi.patchForm("/template", backendForm); return NextResponse.json(next, { status: 200 }); } catch (error: unknown) { diff --git a/src/lib/http-client.ts b/src/lib/http-client.ts index 60e9382..979d040 100644 --- a/src/lib/http-client.ts +++ b/src/lib/http-client.ts @@ -305,7 +305,10 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {}) const putForm = (path: string, form: FormData, o?: Omit) => request(path, { ...o, method: "PUT", form }); - return { request, get, post, put, patch, del, postForm, putForm }; + const patchForm = (path: string, form: FormData, o?: Omit) => + request(path, { ...o, method: "PATCH", form }); + + return { request, get, post, put, patch, del, postForm, putForm, patchForm }; }; export const nextApi = createHttpClient(clientEnv.API_BASE); diff --git a/src/query/notification.ts b/src/query/notification.ts index fd5af79..621ed27 100644 --- a/src/query/notification.ts +++ b/src/query/notification.ts @@ -39,8 +39,15 @@ export function useNotificationTemplatesQuery(templateIdxList: number[], enabled export function useSaveNotificationTemplateMutation() { return useMutation({ - mutationFn: (data: SaveTemplateRequest) => - nextApi.patch