Merge pull request '260806_01_ENH: 문자 템플릿 저장 json에서 form 방식으로 교체' (#13) from develop into master
Reviewed-on: #13
This commit is contained in:
@@ -4,3 +4,4 @@ NEXT_PUBLIC_API_BASE=http://localhost:6104/api
|
|||||||
ENV=local
|
ENV=local
|
||||||
API_BACK_SERVER=http://localhost:6105/api/v1
|
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 });
|
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) {
|
if (!body || !body.tmplatIdx) {
|
||||||
return NextResponse.json({ message: "Template request body is invalid." }, { status: 400 });
|
return NextResponse.json({ message: "Template request body is invalid." }, { status: 400 });
|
||||||
}
|
}
|
||||||
@@ -57,7 +61,13 @@ export const PATCH = async (
|
|||||||
sendTel: body.sendTel,
|
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 });
|
return NextResponse.json(next, { status: 200 });
|
||||||
} catch (error: unknown) {
|
} 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">) =>
|
const putForm = <T = unknown>(path: string, form: FormData, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||||
request<T>(path, { ...o, method: "PUT", 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);
|
export const nextApi = createHttpClient(clientEnv.API_BASE);
|
||||||
|
|||||||
@@ -39,8 +39,15 @@ export function useNotificationTemplatesQuery(templateIdxList: number[], enabled
|
|||||||
|
|
||||||
export function useSaveNotificationTemplateMutation() {
|
export function useSaveNotificationTemplateMutation() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (data: SaveTemplateRequest) =>
|
mutationFn: (data: SaveTemplateRequest) => {
|
||||||
nextApi.patch<Template>("/notification/template", data),
|
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