260826_01_ENH: notihub 수정으로 인한 후속 조치
This commit is contained in:
@@ -4,6 +4,7 @@ import {errorToResponse} from "@/lib/http-util";
|
||||
import {createNotiHubApi} from "@/lib/server-api";
|
||||
import {
|
||||
BulkSendResponse,
|
||||
CreateTemplateRequest,
|
||||
SaveTemplateRequest,
|
||||
SendSmsBulkRequest,
|
||||
Template,
|
||||
@@ -15,14 +16,31 @@ export const GET = async (
|
||||
) => {
|
||||
try {
|
||||
const {slug = []} = await context.params;
|
||||
const [action, templateIdx] = slug;
|
||||
const [action, second, third, fourth] = slug;
|
||||
|
||||
if (action !== "template" || !templateIdx) {
|
||||
if (action !== "template") {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const notiHubApi = await createNotiHubApi();
|
||||
const template = await notiHubApi.get<Template>(`/template/${encodeURIComponent(templateIdx)}`);
|
||||
let path: string;
|
||||
if (second === "list") {
|
||||
if (slug.length !== 4 || !third || !fourth) {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
path = `/template/list/${encodeURIComponent(third)}/${encodeURIComponent(fourth)}`;
|
||||
} else {
|
||||
if (slug.length !== 2 || !second) {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
path = `/template/${encodeURIComponent(second)}`;
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const template = await notiHubApi.get<Template | Template[]>(path);
|
||||
|
||||
return NextResponse.json(template, { status: 200 });
|
||||
} catch (error: unknown) {
|
||||
@@ -30,6 +48,35 @@ export const GET = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const PUT = async (
|
||||
req: NextRequest,
|
||||
context: RouteContext
|
||||
) => {
|
||||
try {
|
||||
const {slug = []} = await context.params;
|
||||
if (slug.length !== 1 || slug[0] !== "template") {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const formData = await req.formData();
|
||||
const templatePart = formData.get("template");
|
||||
const body = templatePart instanceof Blob
|
||||
? JSON.parse(await templatePart.text()) as CreateTemplateRequest
|
||||
: null;
|
||||
if (!body || !body.itrntPrjctCd || body.tmplatTy == null || !body.tmplatNm || !body.tmplatBody || !body.sendTel || !body.sendNm) {
|
||||
return NextResponse.json({ message: "Template request body is invalid." }, { status: 400 });
|
||||
}
|
||||
|
||||
const notiHubApi = await createNotiHubApi();
|
||||
const backendForm = new FormData();
|
||||
backendForm.append("template", new Blob([JSON.stringify(body)], {type: "application/json"}));
|
||||
const created = await notiHubApi.putForm<Template>("/template", backendForm);
|
||||
return NextResponse.json(created, { status: 200 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const PATCH = async (
|
||||
req: NextRequest,
|
||||
context: RouteContext
|
||||
@@ -56,6 +103,7 @@ export const PATCH = async (
|
||||
const next: Template = {
|
||||
...current,
|
||||
tmplatNm: body.tmplatNm,
|
||||
tmplatPurpose: body.tmplatPurpose ?? current.tmplatPurpose ?? 0,
|
||||
tmplatTitle: body.tmplatTitle,
|
||||
tmplatBody: body.tmplatBody,
|
||||
sendTel: body.sendTel,
|
||||
|
||||
Reference in New Issue
Block a user