261007_01_ENH: 메시지 API contact-back 경유 전환, 발송 경로 변경 및 발신 이메일 형식 검증 추가
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {createNotihubApi} from "@/lib/http-server";
|
||||
import {createContactApi} from "@/lib/http-server";
|
||||
import {errorToResponse} from "@kri/common/http";
|
||||
import type { Template, TemplateSummary } from "@kri/common/noti-hub";
|
||||
|
||||
@@ -9,7 +9,7 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const {slug = []} = await context.params;
|
||||
const [action] = slug;
|
||||
const notihubApi = await createNotihubApi();
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(slug.length === 2 && slug[1] === "attachment"){
|
||||
const fileName = searchParams.get("fileName");
|
||||
@@ -17,23 +17,23 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
return NextResponse.json({ message: "fileName은 필수입니다." }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await notihubApi.get<ArrayBuffer>(
|
||||
`/template/${slug[0]}/attachment?fileName=${encodeURIComponent(fileName)}`,
|
||||
const result = await contactApi.get<ArrayBuffer>(
|
||||
`/message-template/${slug[0]}/attachment?fileName=${encodeURIComponent(fileName)}`,
|
||||
{ expectBinary: true },
|
||||
);
|
||||
return new NextResponse(result, { status: 200, headers: { "Content-Type": "application/octet-stream" } });
|
||||
}
|
||||
|
||||
if(slug.length === 1){
|
||||
const result = await notihubApi.get<Template>(
|
||||
`/template/${slug[0]}`,
|
||||
const result = await contactApi.get<Template>(
|
||||
`/message-template/${slug[0]}`,
|
||||
);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if(action === "list" && slug.length === 3){
|
||||
const result = await notihubApi.get<TemplateSummary[]>(
|
||||
`/template/list/${slug[1]}/${slug[2]}`,
|
||||
const result = await contactApi.get<TemplateSummary[]>(
|
||||
`/message-template/list/${slug[1]}/${slug[2]}`,
|
||||
);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
@@ -49,7 +49,7 @@ export const PUT = async (req: NextRequest, context: RouteContext) => {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const {slug = []} = await context.params;
|
||||
const [action] = slug;
|
||||
const notihubApi = await createNotihubApi();
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(action === "body-image" && slug.length === 2){
|
||||
const itrntPrjctCd = slug[1];
|
||||
@@ -64,8 +64,8 @@ export const PUT = async (req: NextRequest, context: RouteContext) => {
|
||||
);
|
||||
}
|
||||
|
||||
const result = await notihubApi.putForm<string>(
|
||||
`/template/body-image/${itrntPrjctCd}`,
|
||||
const result = await contactApi.putForm<string>(
|
||||
`/message-template/body-image/${itrntPrjctCd}`,
|
||||
formData
|
||||
);
|
||||
|
||||
@@ -81,7 +81,7 @@ export const PUT = async (req: NextRequest, context: RouteContext) => {
|
||||
);
|
||||
}
|
||||
|
||||
const result = await notihubApi.putForm<Template>(`/template`, formData);
|
||||
const result = await contactApi.putForm<Template>(`/message-template`, formData);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ export const PATCH = async (req: NextRequest, context: RouteContext) => {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const {slug = []} = await context.params;
|
||||
const [action] = slug;
|
||||
const notihubApi = await createNotihubApi();
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if(!action){
|
||||
const formData = await req.formData().catch(() => null);
|
||||
@@ -107,7 +107,7 @@ export const PATCH = async (req: NextRequest, context: RouteContext) => {
|
||||
);
|
||||
}
|
||||
|
||||
const result = await notihubApi.request<Template>(`/template`, { method: "PATCH", form: formData });
|
||||
const result = await contactApi.request<Template>(`/message-template`, { method: "PATCH", form: formData });
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user