마에스트로 상세 화면에 [연장] 신청 버튼 추가

This commit is contained in:
2026-07-02 21:50:56 +09:00
parent b2483a1b77
commit 7669e9d0de
4 changed files with 239 additions and 17 deletions
@@ -0,0 +1,54 @@
import { z } from "zod";
import { NextResponse } from "next/server";
import { createExtensionRequest } from "@/lib/extension-requests";
import { ApiError } from "@/lib/errors";
import { withApiHandler } from "@/lib/api-handler";
import { logger } from "@/lib/logger";
import { ACCOUNT_TYPES } from "@/lib/constants";
const CTX = "maestros/[id]/extension-requests";
const paidAccountTypeValues = [
ACCOUNT_TYPES.BASIC_20,
ACCOUNT_TYPES.STANDARD_50,
ACCOUNT_TYPES.PRO_100,
ACCOUNT_TYPES.SCHOOL_500,
ACCOUNT_TYPES.SCHOOL_1000,
] as const;
const postBodySchema = z.object({
accountType: z.coerce
.number()
.int()
.refine((v) => (paidAccountTypeValues as readonly number[]).includes(v)),
});
export const POST = withApiHandler<{ id: string }>(
CTX,
async (request, { params, t0 }) => {
const { id } = await params;
const maestroID = Number(id);
if (!Number.isInteger(maestroID) || maestroID <= 0) {
throw new ApiError("Invalid maestro id", 400);
}
const body = postBodySchema.safeParse(
await request.json().catch(() => ({}))
);
if (!body.success) {
throw new ApiError("Invalid request body", 400);
}
const result = await createExtensionRequest(maestroID, body.data.accountType);
logger.info(CTX, "created", {
maestroID,
maestroExtensionID: result.maestroExtensionID,
duration: Date.now() - t0,
});
return NextResponse.json(result, { status: 201 });
}
);