260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
38
src/app/api/message/[[...slug]]/route.ts
Normal file
38
src/app/api/message/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {createContactApi} from "@/lib/http-server";
|
||||
import {errorToResponse} from "@kri/common/http";
|
||||
import type {MessageBulkSendResponse} from "@/types/message";
|
||||
|
||||
const isChannel = (value: string): value is "sms" | "email" => value === "sms" || value === "email";
|
||||
|
||||
export const POST = async (req: NextRequest, context: RouteContext) => {
|
||||
try {
|
||||
const {slug = []} = await context.params;
|
||||
const [channel, action, prjctIdx] = slug;
|
||||
const contactApi = await createContactApi();
|
||||
|
||||
if (!isChannel(channel) || !prjctIdx) {
|
||||
return NextResponse.json({message: "Not found"}, {status: 404});
|
||||
}
|
||||
|
||||
const body = await req.json().catch(() => null);
|
||||
if (!body) {
|
||||
return NextResponse.json({message: "요청 바디가 없습니다."}, {status: 400});
|
||||
}
|
||||
|
||||
if (action === "single") {
|
||||
await contactApi.post(`/message/${channel}/single/${prjctIdx}`, body);
|
||||
return new NextResponse(null, {status: 204});
|
||||
}
|
||||
|
||||
if (action === "bulk") {
|
||||
const result = await contactApi.post<MessageBulkSendResponse>(`/message/${channel}/bulk/${prjctIdx}`, body);
|
||||
return NextResponse.json(result, {status: 200});
|
||||
}
|
||||
|
||||
return NextResponse.json({message: "Not found"}, {status: 404});
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user