코드 검토 및 문서 반영

This commit is contained in:
2026-07-02 22:13:38 +09:00
parent 2d9b8d0624
commit 854a3e2bfb
9 changed files with 115 additions and 97 deletions
@@ -5,6 +5,7 @@ import { useRouter } from "next/navigation";
import { Plus } from "lucide-react";
import { Button } from "@/components/ui/button";
import { PAID_ACCOUNT_TYPE_VALUES } from "@/lib/constants";
import { formatDateTime, getAccountTypeLabel, getRequestStatusLabel } from "@/lib/utils";
import type { MaestroDetail } from "@/lib/maestros";
@@ -26,6 +27,7 @@ export function ExtensionRequestsSection({
const [isCreating, setIsCreating] = useState(false);
const [errorMessage, setErrorMessage] = useState("");
const isPaidAccount = (PAID_ACCOUNT_TYPE_VALUES as readonly number[]).includes(accountType);
const isDisabled = isCreating || isPending;
async function handleCreate() {
@@ -37,11 +39,7 @@ export function ExtensionRequestsSection({
try {
const response = await fetch(
`/api/maestros/${maestroID}/extension-requests`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ accountType }),
}
{ method: "POST" }
);
const body = (await response.json().catch(() => null)) as {
@@ -75,7 +73,7 @@ export function ExtensionRequestsSection({
</div>
<div className="flex flex-col items-end gap-1">
<Button
disabled={isDisabled}
disabled={isDisabled || !isPaidAccount}
onClick={() => void handleCreate()}
size="sm"
type="button"
@@ -1,32 +1,15 @@
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 }) => {
async (_request, { params, t0 }) => {
const { id } = await params;
const maestroID = Number(id);
@@ -34,14 +17,7 @@ export const POST = withApiHandler<{ id: string }>(
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);
const result = await createExtensionRequest(maestroID);
logger.info(CTX, "created", {
maestroID,
@@ -5,23 +5,15 @@ import { createUpgradeRequest } from "@/lib/upgrade-requests";
import { ApiError } from "@/lib/errors";
import { withApiHandler } from "@/lib/api-handler";
import { logger } from "@/lib/logger";
import { ACCOUNT_TYPES } from "@/lib/constants";
import { PAID_ACCOUNT_TYPE_VALUES } from "@/lib/constants";
const CTX = "maestros/[id]/upgrade-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({
requestedAccountType: z.coerce
.number()
.int()
.refine((v) => (paidAccountTypeValues as readonly number[]).includes(v)),
.refine((v) => (PAID_ACCOUNT_TYPE_VALUES as readonly number[]).includes(v)),
});
export const POST = withApiHandler<{ id: string }>(