261022_03_ENH: 예약 취소 추가

This commit is contained in:
2026-10-22 15:49:14 +09:00
parent 061ef782bc
commit f65dacdec1
9 changed files with 234 additions and 19 deletions

View File

@@ -28,6 +28,7 @@ type SummaryRow = {
successCount: number;
failCount: number;
standByCount: number;
canceledCount: number;
};
const sum = (list: SendResultSummaryResponse[], field: keyof SendResultSummaryResponse) =>
@@ -44,6 +45,7 @@ const buildRows = (data: SendResultSummaryResponse[]): SummaryRow[] =>
successCount: sum(matched, "successCount"),
failCount: sum(matched, "failCount"),
standByCount: sum(matched, "standByCount"),
canceledCount: sum(matched, "canceledCount"),
};
});
@@ -80,6 +82,7 @@ const MessageProgressPage = () => {
successCount: rows.reduce((acc, row) => acc + row.successCount, 0),
failCount: rows.reduce((acc, row) => acc + row.failCount, 0),
standByCount: rows.reduce((acc, row) => acc + row.standByCount, 0),
canceledCount: rows.reduce((acc, row) => acc + row.canceledCount, 0),
}),
[rows],
);
@@ -103,6 +106,7 @@ const MessageProgressPage = () => {
<th className="h-10 px-3 text-center font-semibold border-b">성공</th>
<th className="h-10 px-3 text-center font-semibold border-b">실패</th>
<th className="h-10 px-3 text-center font-semibold border-b">발송중</th>
<th className="h-10 px-3 text-center font-semibold border-b">취소</th>
</tr>
</thead>
<tbody>
@@ -115,6 +119,7 @@ const MessageProgressPage = () => {
<td className="h-10 px-3 text-center">{caseUnit(row.successCount)}</td>
<td className="h-10 px-3 text-center">{caseUnit(row.failCount)}</td>
<td className="h-10 px-3 text-center">{caseUnit(row.standByCount)}</td>
<td className="h-10 px-3 text-center">{caseUnit(row.canceledCount)}</td>
</tr>
))}
<tr className="bg-gray-50 font-semibold">
@@ -124,6 +129,7 @@ const MessageProgressPage = () => {
<td className="h-10 px-3 text-center">{caseUnit(total.successCount)}</td>
<td className="h-10 px-3 text-center">{caseUnit(total.failCount)}</td>
<td className="h-10 px-3 text-center">{caseUnit(total.standByCount)}</td>
<td className="h-10 px-3 text-center">{caseUnit(total.canceledCount)}</td>
</tr>
</tbody>
</table>

View File

@@ -2,17 +2,48 @@ 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 {SendCancelResponse} from "@kri/common/noti-hub";
import type {MessageSendChannel, SendSingleResponse} from "@/types/message";
const isChannel = (value: string): value is MessageSendChannel =>
value === "sms" || value === "email" || value === "kko";
const BULK_SEND_KEY_MAX_LENGTH = 32;
const readCancelBody = (body: unknown, target: string): Record<string, number | string> | null => {
if (!body || typeof body !== "object") return null;
if (target === "single") {
const sendIdx = (body as {sendIdx?: unknown}).sendIdx;
return typeof sendIdx === "number" && Number.isSafeInteger(sendIdx) && sendIdx > 0 ? {sendIdx} : null;
}
if (target === "bulk") {
const bulkSendKey = (body as {bulkSendKey?: unknown}).bulkSendKey;
return typeof bulkSendKey === "string" && bulkSendKey.trim() !== "" && bulkSendKey.length <= BULK_SEND_KEY_MAX_LENGTH
? {bulkSendKey}
: null;
}
return null;
};
export const POST = async (req: NextRequest, context: RouteContext) => {
try {
const {slug = []} = await context.params;
const [channel, action, prjctIdx] = slug;
const contactApi = await createContactApi();
// 예약 취소 (POST /message-send/cancel/{single|bulk}). 채널 구분 없이 공통 API를 사용한다.
if (channel === "cancel") {
if (action !== "single" && action !== "bulk") {
return NextResponse.json({message: "Not found"}, {status: 404});
}
const cancelBody = readCancelBody(await req.json().catch(() => null), action);
if (!cancelBody) {
return NextResponse.json({message: "취소 요청 값이 올바르지 않습니다."}, {status: 400});
}
const result = await contactApi.post<SendCancelResponse>(`/message-send/cancel/${action}`, cancelBody);
return NextResponse.json(result, {status: 200});
}
if (!isChannel(channel) || !prjctIdx) {
return NextResponse.json({message: "Not found"}, {status: 404});
}