Compare commits
3 Commits
b2483a1b77
...
854a3e2bfb
| Author | SHA1 | Date | |
|---|---|---|---|
| 854a3e2bfb | |||
| 2d9b8d0624 | |||
| 7669e9d0de |
@@ -36,7 +36,7 @@ Admin panel for the chocomae service (mouse-typing), extracted into a standalone
|
|||||||
| `lib/logger.ts` | Structured logger — `debug/info/warn/error`, level controlled by `LOG_LEVEL` / `APP_ENV` |
|
| `lib/logger.ts` | Structured logger — `debug/info/warn/error`, level controlled by `LOG_LEVEL` / `APP_ENV` |
|
||||||
| `lib/errors.ts` | `ApiError` — unified error class with HTTP status code |
|
| `lib/errors.ts` | `ApiError` — unified error class with HTTP status code |
|
||||||
| `lib/api-handler.ts` | `withApiHandler` — wraps route handlers with auth, timing, and error logging |
|
| `lib/api-handler.ts` | `withApiHandler` — wraps route handlers with auth, timing, and error logging |
|
||||||
| `lib/constants.ts` | Status code constants (`ACTIVATE_STATUS`, `ACCOUNT_TYPE`, `REQUEST_STATUS`) |
|
| `lib/constants.ts` | Status code constants (`ACTIVATE_STATUS`, `ACCOUNT_TYPE`, `REQUEST_STATUS`); `PAID_ACCOUNT_TYPE_VALUES` (유료 계정 유형 배열 — 중복 정의 방지용 공용 상수) |
|
||||||
| `lib/maestros.ts` | Maestro DB queries |
|
| `lib/maestros.ts` | Maestro DB queries |
|
||||||
| `lib/extension-requests.ts` | Extension request queries and approval logic |
|
| `lib/extension-requests.ts` | Extension request queries and approval logic |
|
||||||
| `lib/upgrade-requests.ts` | Upgrade request queries and approval logic |
|
| `lib/upgrade-requests.ts` | Upgrade request queries and approval logic |
|
||||||
@@ -67,11 +67,17 @@ Always record a log entry after a successful DB change. Use these `Type` values:
|
|||||||
|
|
||||||
- Phase 0–8: login, maestro list/detail, extension requests, upgrade requests, Docker setup, transaction safety, auth guards.
|
- Phase 0–8: login, maestro list/detail, extension requests, upgrade requests, Docker setup, transaction safety, auth guards.
|
||||||
- Phase 9 (substantially complete): structured logging (`lib/logger.ts`), `withApiHandler` wrapper (`lib/api-handler.ts`), `ApiError` class (`lib/errors.ts`), Prisma SQL pretty-logging and result table logging (`lib/db.ts`). Remaining: correlation IDs, stage/production log verification.
|
- Phase 9 (substantially complete): structured logging (`lib/logger.ts`), `withApiHandler` wrapper (`lib/api-handler.ts`), `ApiError` class (`lib/errors.ts`), Prisma SQL pretty-logging and result table logging (`lib/db.ts`). Remaining: correlation IDs, stage/production log verification.
|
||||||
|
- Phase 10: Maestro info edit form (`PATCH /api/maestros/[id]`) + student list with server-side pagination (`GET /api/maestros/[id]/students`).
|
||||||
|
- Phase 11: Email auto-send via Nodemailer after extension/upgrade approval (`lib/mail.ts`). Upgrade email edge-case verification (trial→paid, paid→paid) still pending.
|
||||||
|
- Phase 12: Admin-initiated extension/upgrade request registration from maestro detail page.
|
||||||
|
- `POST /api/maestros/[id]/extension-requests` — inserts into `maestro_extension` using maestro's current `AccountType` read server-side; rejects trial account types.
|
||||||
|
- `POST /api/maestros/[id]/upgrade-requests` — inserts into `maestro_upgrade` inside a transaction; validates `requestedAccountType > maestro.AccountType`.
|
||||||
|
- `ExtensionRequestsSection.tsx`, `UpgradeRequestsSection.tsx` — client components with inline action UI; call `router.refresh()` on success.
|
||||||
|
- `PAID_ACCOUNT_TYPE_VALUES` consolidated in `lib/constants.ts` — shared by `lib/maestros.ts`, `lib/extension-requests.ts`, `lib/upgrade-requests.ts`, and both new API routes.
|
||||||
|
|
||||||
## Planned phases (not yet implemented)
|
## Planned phases (not yet implemented)
|
||||||
|
|
||||||
- **Phase 10** — Maestro info edit form + student list with pagination (`PATCH /api/maestros/[id]`, `GET /api/maestros/[id]/students`)
|
이후 작업 후보는 `docs/plan/project-plan.md` Section 10 "MVP 이후 확장 후보" 참조.
|
||||||
- **Phase 11** — Email auto-send via Nodemailer after extension/upgrade approval (`lib/mail.ts`)
|
|
||||||
|
|
||||||
## Packages to know
|
## Packages to know
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useTransition } from "react";
|
||||||
|
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";
|
||||||
|
|
||||||
|
type ExtensionRequestsSectionProps = {
|
||||||
|
maestroID: number;
|
||||||
|
accountType: number;
|
||||||
|
totalCount: number;
|
||||||
|
extensionRequests: MaestroDetail["extensionRequests"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function ExtensionRequestsSection({
|
||||||
|
maestroID,
|
||||||
|
accountType,
|
||||||
|
totalCount,
|
||||||
|
extensionRequests,
|
||||||
|
}: ExtensionRequestsSectionProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
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() {
|
||||||
|
if (!window.confirm("연장 신청을 등록하시겠습니까?")) return;
|
||||||
|
|
||||||
|
setIsCreating(true);
|
||||||
|
setErrorMessage("");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/maestros/${maestroID}/extension-requests`,
|
||||||
|
{ method: "POST" }
|
||||||
|
);
|
||||||
|
|
||||||
|
const body = (await response.json().catch(() => null)) as {
|
||||||
|
message?: string;
|
||||||
|
} | null;
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(body?.message ?? "연장 신청 등록에 실패했습니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
setErrorMessage(
|
||||||
|
error instanceof Error ? error.message : "연장 신청 등록에 실패했습니다."
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setIsCreating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="rounded-lg border bg-background p-5">
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-base font-semibold">연장 신청 이력</h2>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
전체 {totalCount.toLocaleString()}건 중 최근 20건
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col items-end gap-1">
|
||||||
|
<Button
|
||||||
|
disabled={isDisabled || !isPaidAccount}
|
||||||
|
onClick={() => void handleCreate()}
|
||||||
|
size="sm"
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<Plus aria-hidden="true" className="size-4" />
|
||||||
|
연장
|
||||||
|
</Button>
|
||||||
|
{errorMessage ? (
|
||||||
|
<p className="text-xs text-destructive">{errorMessage}</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 overflow-hidden rounded-lg border">
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full min-w-[560px] border-collapse text-sm">
|
||||||
|
<thead className="bg-muted/60">
|
||||||
|
<tr className="border-b">
|
||||||
|
{["신청ID", "계정 유형", "신청일시", "상태"].map((header) => (
|
||||||
|
<th
|
||||||
|
className="h-10 px-3 text-left text-xs font-medium text-muted-foreground"
|
||||||
|
key={header}
|
||||||
|
>
|
||||||
|
{header}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{extensionRequests.length > 0 ? (
|
||||||
|
extensionRequests.map((request) => (
|
||||||
|
<tr
|
||||||
|
className="border-b last:border-b-0"
|
||||||
|
key={request.maestroExtensionID}
|
||||||
|
>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{request.maestroExtensionID}
|
||||||
|
</td>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{getAccountTypeLabel(request.accountType)}
|
||||||
|
</td>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{formatDateTime(request.requestedDateTime)}
|
||||||
|
</td>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{getRequestStatusLabel(request.status)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
className="h-24 px-3 text-center text-sm text-muted-foreground"
|
||||||
|
colSpan={4}
|
||||||
|
>
|
||||||
|
연장 신청 이력이 없습니다.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useTransition } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { ArrowUp } from "lucide-react";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { ACCOUNT_TYPES } from "@/lib/constants";
|
||||||
|
import { formatDateTime, getAccountTypeLabel, getRequestStatusLabel } from "@/lib/utils";
|
||||||
|
import type { MaestroDetail } from "@/lib/maestros";
|
||||||
|
|
||||||
|
type UpgradeRequestsSectionProps = {
|
||||||
|
maestroID: number;
|
||||||
|
accountType: number;
|
||||||
|
totalCount: number;
|
||||||
|
upgradeRequests: MaestroDetail["upgradeRequests"];
|
||||||
|
};
|
||||||
|
|
||||||
|
const upgradeOptions = [
|
||||||
|
{ value: ACCOUNT_TYPES.BASIC_20, label: "1만원 (20명)" },
|
||||||
|
{ value: ACCOUNT_TYPES.STANDARD_50, label: "2만원 (50명)" },
|
||||||
|
{ value: ACCOUNT_TYPES.PRO_100, label: "3만원 (100명)" },
|
||||||
|
{ value: ACCOUNT_TYPES.SCHOOL_500, label: "4만원 (500명)" },
|
||||||
|
{ value: ACCOUNT_TYPES.SCHOOL_1000, label: "5만원 (1,000명)" },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const selectClass =
|
||||||
|
"h-9 rounded-md border bg-background px-3 text-sm outline-none transition-colors focus:border-ring focus:ring-3 focus:ring-ring/30 disabled:opacity-50";
|
||||||
|
|
||||||
|
export function UpgradeRequestsSection({
|
||||||
|
maestroID,
|
||||||
|
accountType,
|
||||||
|
totalCount,
|
||||||
|
upgradeRequests,
|
||||||
|
}: UpgradeRequestsSectionProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
|
const [selectedAccountType, setSelectedAccountType] = useState<number | null>(null);
|
||||||
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
||||||
|
const isUpgradeEnabled =
|
||||||
|
selectedAccountType !== null && selectedAccountType > accountType;
|
||||||
|
const isDisabled = isCreating || isPending;
|
||||||
|
|
||||||
|
async function handleUpgrade() {
|
||||||
|
if (selectedAccountType === null) return;
|
||||||
|
if (!window.confirm("업그레이드 신청을 등록하시겠습니까?")) return;
|
||||||
|
|
||||||
|
setIsCreating(true);
|
||||||
|
setErrorMessage("");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/maestros/${maestroID}/upgrade-requests`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ requestedAccountType: selectedAccountType }),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const body = (await response.json().catch(() => null)) as {
|
||||||
|
message?: string;
|
||||||
|
} | null;
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(body?.message ?? "업그레이드 신청 등록에 실패했습니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedAccountType(null);
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
setErrorMessage(
|
||||||
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "업그레이드 신청 등록에 실패했습니다."
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setIsCreating(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="rounded-lg border bg-background p-5">
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-base font-semibold">업그레이드 신청 이력</h2>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
전체 {totalCount.toLocaleString()}건 중 최근 20건
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col items-end gap-1">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<select
|
||||||
|
className={selectClass}
|
||||||
|
disabled={isDisabled}
|
||||||
|
onChange={(e) =>
|
||||||
|
setSelectedAccountType(
|
||||||
|
e.target.value === "" ? null : Number(e.target.value)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
value={selectedAccountType ?? ""}
|
||||||
|
>
|
||||||
|
<option value="">요금제 선택</option>
|
||||||
|
{upgradeOptions.map((opt) => (
|
||||||
|
<option
|
||||||
|
disabled={opt.value <= accountType}
|
||||||
|
key={opt.value}
|
||||||
|
value={opt.value}
|
||||||
|
>
|
||||||
|
{opt.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<Button
|
||||||
|
disabled={isDisabled || !isUpgradeEnabled}
|
||||||
|
onClick={() => void handleUpgrade()}
|
||||||
|
size="sm"
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<ArrowUp aria-hidden="true" className="size-4" />
|
||||||
|
업그레이드
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{errorMessage ? (
|
||||||
|
<p className="text-xs text-destructive">{errorMessage}</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4 overflow-hidden rounded-lg border">
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full min-w-[560px] border-collapse text-sm">
|
||||||
|
<thead className="bg-muted/60">
|
||||||
|
<tr className="border-b">
|
||||||
|
{["신청ID", "현재", "요청", "신청일시", "상태"].map(
|
||||||
|
(header) => (
|
||||||
|
<th
|
||||||
|
className="h-10 px-3 text-left text-xs font-medium text-muted-foreground"
|
||||||
|
key={header}
|
||||||
|
>
|
||||||
|
{header}
|
||||||
|
</th>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{upgradeRequests.length > 0 ? (
|
||||||
|
upgradeRequests.map((request) => (
|
||||||
|
<tr
|
||||||
|
className="border-b last:border-b-0"
|
||||||
|
key={request.maestroUpgradeID}
|
||||||
|
>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{request.maestroUpgradeID}
|
||||||
|
</td>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{getAccountTypeLabel(request.registeredAccountType)}
|
||||||
|
</td>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{getAccountTypeLabel(request.requestedAccountType)}
|
||||||
|
</td>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{formatDateTime(request.requestedDateTime)}
|
||||||
|
</td>
|
||||||
|
<td className="h-11 px-3 align-middle">
|
||||||
|
{getRequestStatusLabel(request.status)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td
|
||||||
|
className="h-24 px-3 text-center text-sm text-muted-foreground"
|
||||||
|
colSpan={5}
|
||||||
|
>
|
||||||
|
업그레이드 신청 이력이 없습니다.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,10 +9,11 @@ import {
|
|||||||
formatDateTime,
|
formatDateTime,
|
||||||
getAccountTypeLabel,
|
getAccountTypeLabel,
|
||||||
getActivateStatusLabel,
|
getActivateStatusLabel,
|
||||||
getRequestStatusLabel,
|
|
||||||
} from "@/lib/utils";
|
} from "@/lib/utils";
|
||||||
import { MaestroEditForm } from "./MaestroEditForm";
|
import { MaestroEditForm } from "./MaestroEditForm";
|
||||||
import { StudentsSection } from "./StudentsSection";
|
import { StudentsSection } from "./StudentsSection";
|
||||||
|
import { ExtensionRequestsSection } from "./ExtensionRequestsSection";
|
||||||
|
import { UpgradeRequestsSection } from "./UpgradeRequestsSection";
|
||||||
|
|
||||||
type MaestroDetailPageProps = {
|
type MaestroDetailPageProps = {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
@@ -92,41 +93,19 @@ export default async function MaestroDetailPage({
|
|||||||
<StudentsSection maestroID={maestroID} />
|
<StudentsSection maestroID={maestroID} />
|
||||||
|
|
||||||
<div className="grid gap-4 xl:grid-cols-2">
|
<div className="grid gap-4 xl:grid-cols-2">
|
||||||
<section className="rounded-lg border bg-background p-5">
|
<ExtensionRequestsSection
|
||||||
<h2 className="text-base font-semibold">연장 신청 이력</h2>
|
accountType={maestro.accountType}
|
||||||
<p className="mt-1 text-sm text-muted-foreground">
|
extensionRequests={detail.extensionRequests}
|
||||||
전체 {detail.counts.extensionRequests.toLocaleString()}건 중 최근
|
maestroID={maestroID}
|
||||||
20건
|
totalCount={detail.counts.extensionRequests}
|
||||||
</p>
|
|
||||||
<SimpleTable
|
|
||||||
emptyText="연장 신청 이력이 없습니다."
|
|
||||||
headers={["신청ID", "계정 유형", "신청일시", "상태"]}
|
|
||||||
rows={detail.extensionRequests.map((request) => [
|
|
||||||
request.maestroExtensionID,
|
|
||||||
getAccountTypeLabel(request.accountType),
|
|
||||||
formatDateTime(request.requestedDateTime),
|
|
||||||
getRequestStatusLabel(request.status),
|
|
||||||
])}
|
|
||||||
/>
|
/>
|
||||||
</section>
|
|
||||||
|
|
||||||
<section className="rounded-lg border bg-background p-5">
|
<UpgradeRequestsSection
|
||||||
<h2 className="text-base font-semibold">업그레이드 신청 이력</h2>
|
accountType={maestro.accountType}
|
||||||
<p className="mt-1 text-sm text-muted-foreground">
|
maestroID={maestroID}
|
||||||
전체 {detail.counts.upgradeRequests.toLocaleString()}건 중 최근 20건
|
totalCount={detail.counts.upgradeRequests}
|
||||||
</p>
|
upgradeRequests={detail.upgradeRequests}
|
||||||
<SimpleTable
|
|
||||||
emptyText="업그레이드 신청 이력이 없습니다."
|
|
||||||
headers={["신청ID", "현재", "요청", "신청일시", "상태"]}
|
|
||||||
rows={detail.upgradeRequests.map((request) => [
|
|
||||||
request.maestroUpgradeID,
|
|
||||||
getAccountTypeLabel(request.registeredAccountType),
|
|
||||||
getAccountTypeLabel(request.requestedAccountType),
|
|
||||||
formatDateTime(request.requestedDateTime),
|
|
||||||
getRequestStatusLabel(request.status),
|
|
||||||
])}
|
|
||||||
/>
|
/>
|
||||||
</section>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section className="rounded-lg border bg-background p-5">
|
<section className="rounded-lg border bg-background p-5">
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
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";
|
||||||
|
|
||||||
|
const CTX = "maestros/[id]/extension-requests";
|
||||||
|
|
||||||
|
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 result = await createExtensionRequest(maestroID);
|
||||||
|
|
||||||
|
logger.info(CTX, "created", {
|
||||||
|
maestroID,
|
||||||
|
maestroExtensionID: result.maestroExtensionID,
|
||||||
|
duration: Date.now() - t0,
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json(result, { status: 201 });
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
import { createUpgradeRequest } from "@/lib/upgrade-requests";
|
||||||
|
import { ApiError } from "@/lib/errors";
|
||||||
|
import { withApiHandler } from "@/lib/api-handler";
|
||||||
|
import { logger } from "@/lib/logger";
|
||||||
|
import { PAID_ACCOUNT_TYPE_VALUES } from "@/lib/constants";
|
||||||
|
|
||||||
|
const CTX = "maestros/[id]/upgrade-requests";
|
||||||
|
|
||||||
|
const postBodySchema = z.object({
|
||||||
|
requestedAccountType: z.coerce
|
||||||
|
.number()
|
||||||
|
.int()
|
||||||
|
.refine((v) => (PAID_ACCOUNT_TYPE_VALUES 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 createUpgradeRequest(
|
||||||
|
maestroID,
|
||||||
|
body.data.requestedAccountType
|
||||||
|
);
|
||||||
|
|
||||||
|
logger.info(CTX, "created", {
|
||||||
|
maestroID,
|
||||||
|
maestroUpgradeID: result.maestroUpgradeID,
|
||||||
|
requestedAccountType: body.data.requestedAccountType,
|
||||||
|
duration: Date.now() - t0,
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json(result, { status: 201 });
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -162,7 +162,11 @@ chocoadmin/
|
|||||||
│ │ ├── maestros/
|
│ │ ├── maestros/
|
||||||
│ │ │ ├── page.tsx # 마에스트로 전체 목록
|
│ │ │ ├── page.tsx # 마에스트로 전체 목록
|
||||||
│ │ │ └── [maestroId]/
|
│ │ │ └── [maestroId]/
|
||||||
│ │ │ └── page.tsx # 마에스트로 상세 정보
|
│ │ │ ├── page.tsx # 마에스트로 상세 정보 (server)
|
||||||
|
│ │ │ ├── MaestroEditForm.tsx # 기본 정보 수정 폼 (client)
|
||||||
|
│ │ │ ├── StudentsSection.tsx # 학생 목록 + 검색/페이지네이션 (client)
|
||||||
|
│ │ │ ├── ExtensionRequestsSection.tsx # 연장 신청 이력 + [연장] 버튼 (client)
|
||||||
|
│ │ │ └── UpgradeRequestsSection.tsx # 업그레이드 신청 이력 + 신청 UI (client)
|
||||||
│ │ ├── extension-requests/
|
│ │ ├── extension-requests/
|
||||||
│ │ │ └── page.tsx # 연장 신청 목록 + 승인/취소
|
│ │ │ └── page.tsx # 연장 신청 목록 + 승인/취소
|
||||||
│ │ └── upgrade-requests/
|
│ │ └── upgrade-requests/
|
||||||
@@ -173,7 +177,9 @@ chocoadmin/
|
|||||||
│ │ ├── route.ts # GET: 목록
|
│ │ ├── route.ts # GET: 목록
|
||||||
│ │ └── [id]/
|
│ │ └── [id]/
|
||||||
│ │ ├── route.ts # GET: 상세, PATCH: 정보 수정
|
│ │ ├── route.ts # GET: 상세, PATCH: 정보 수정
|
||||||
│ │ └── students/route.ts # GET: 학생 목록
|
│ │ ├── students/route.ts # GET: 학생 목록
|
||||||
|
│ │ ├── extension-requests/route.ts # POST: 연장 신청 등록 (관리자 직접)
|
||||||
|
│ │ └── upgrade-requests/route.ts # POST: 업그레이드 신청 등록 (관리자 직접)
|
||||||
│ ├── extension-requests/
|
│ ├── extension-requests/
|
||||||
│ │ └── [id]/route.ts # PATCH: 승인/취소
|
│ │ └── [id]/route.ts # PATCH: 승인/취소
|
||||||
│ └── upgrade-requests/
|
│ └── upgrade-requests/
|
||||||
@@ -237,8 +243,15 @@ chocoadmin/
|
|||||||
- 플레이어(학생) 전체 목록
|
- 플레이어(학생) 전체 목록
|
||||||
- 서버 사이드 페이지네이션
|
- 서버 사이드 페이지네이션
|
||||||
- 이름 검색
|
- 이름 검색
|
||||||
- 연장 신청 이력
|
- 연장 신청 이력 + [연장] 버튼
|
||||||
- 업그레이드 신청 이력
|
- 유료 요금제 계정에서만 버튼 활성화 (체험 계정 비활성)
|
||||||
|
- 클릭 시 현재 `AccountType`으로 `maestro_extension` INSERT (서버에서 DB 조회)
|
||||||
|
- 등록 후 이력 목록 즉시 갱신 (`router.refresh()`)
|
||||||
|
- 업그레이드 신청 이력 + 요금제 콤보박스 + [업그레이드] 버튼
|
||||||
|
- 콤보박스: 현재 요금제 이하 항목 비활성화, 상위 요금제만 선택 가능
|
||||||
|
- 클릭 시 선택한 `requestedAccountType`으로 `maestro_upgrade` INSERT (트랜잭션 내 서버 조회)
|
||||||
|
- 서버에서 `requestedAccountType > maestro.AccountType` 검증 (다운그레이드 차단)
|
||||||
|
- 등록 후 이력 목록 즉시 갱신 (`router.refresh()`)
|
||||||
- 관리자 처리 로그 (`maestro_log`)
|
- 관리자 처리 로그 (`maestro_log`)
|
||||||
|
|
||||||
### 7-4. 연장 신청 목록 (`/extension-requests`)
|
### 7-4. 연장 신청 목록 (`/extension-requests`)
|
||||||
@@ -498,6 +511,30 @@ chocoadmin/
|
|||||||
- [ ] 업그레이드 승인 후 유료→유료 케이스: `{prev_price}원` 본문 확인
|
- [ ] 업그레이드 승인 후 유료→유료 케이스: `{prev_price}원` 본문 확인
|
||||||
- [x] SMTP 오류 시 승인 API 200 응답 + `error: send failed` 로그 확인
|
- [x] SMTP 오류 시 승인 API 200 응답 + `error: send failed` 로그 확인
|
||||||
|
|
||||||
|
### Phase 12. 관리자 직접 연장/업그레이드 신청 등록
|
||||||
|
|
||||||
|
> 마에스트로 상세 화면에서 관리자가 직접 연장·업그레이드 신청을 DB에 등록할 수 있도록 한다. 메일 발송은 하지 않는다.
|
||||||
|
|
||||||
|
- [x] 연장 신청 등록 API 구현 (`POST /api/maestros/[id]/extension-requests`)
|
||||||
|
- [x] 서버에서 `maestro.AccountType` 직접 조회 — 클라이언트 값 신뢰 안 함
|
||||||
|
- [x] 유료 요금제 계정이 아닌 경우 400 반환 (체험 계정 차단)
|
||||||
|
- [x] `maestro_extension` INSERT (`AccountType`, `RequestedDateTime`, `Status=1`)
|
||||||
|
- [x] 업그레이드 신청 등록 API 구현 (`POST /api/maestros/[id]/upgrade-requests`)
|
||||||
|
- [x] 트랜잭션 내에서 `maestro` SELECT → `maestro_upgrade` INSERT (원자성 보장)
|
||||||
|
- [x] `requestedAccountType > maestro.AccountType` 검증 (다운그레이드 차단, 400 반환)
|
||||||
|
- [x] `RegisteredActivateStatus`, `RegisteredAccountType` 서버 DB 조회값으로 저장
|
||||||
|
- [x] 연장 신청 이력 클라이언트 컴포넌트 (`ExtensionRequestsSection.tsx`)
|
||||||
|
- [x] 섹션 우상단 [연장] 버튼
|
||||||
|
- [x] 체험 계정 (`AccountType` ∉ `PAID_ACCOUNT_TYPE_VALUES`) 시 버튼 비활성화
|
||||||
|
- [x] 등록 성공 후 `router.refresh()`로 이력 테이블 즉시 갱신
|
||||||
|
- [x] 업그레이드 신청 이력 클라이언트 컴포넌트 (`UpgradeRequestsSection.tsx`)
|
||||||
|
- [x] 섹션 우상단 요금제 콤보박스 + [업그레이드] 버튼
|
||||||
|
- [x] 현재 요금제 이하 옵션 `disabled`, 상위 요금제만 선택 가능
|
||||||
|
- [x] 선택 후 등록 성공 시 콤보박스 초기화 + `router.refresh()`
|
||||||
|
- [x] `PAID_ACCOUNT_TYPE_VALUES` 공용 상수로 추출 (`lib/constants.ts`)
|
||||||
|
- [x] 기존 `lib/maestros.ts`의 로컬 정의 제거 및 import로 교체
|
||||||
|
- [x] 두 신규 API route의 로컬 정의 제거 및 import로 교체
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 10. MVP 범위
|
## 10. MVP 범위
|
||||||
|
|||||||
@@ -68,6 +68,14 @@ export const REQUEST_STATUS_LABELS = {
|
|||||||
[REQUEST_STATUSES.APPLIED]: "적용 완료",
|
[REQUEST_STATUSES.APPLIED]: "적용 완료",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const PAID_ACCOUNT_TYPE_VALUES = [
|
||||||
|
ACCOUNT_TYPES.BASIC_20,
|
||||||
|
ACCOUNT_TYPES.STANDARD_50,
|
||||||
|
ACCOUNT_TYPES.PRO_100,
|
||||||
|
ACCOUNT_TYPES.SCHOOL_500,
|
||||||
|
ACCOUNT_TYPES.SCHOOL_1000,
|
||||||
|
] as const;
|
||||||
|
|
||||||
export type AccountType = (typeof ACCOUNT_TYPES)[keyof typeof ACCOUNT_TYPES];
|
export type AccountType = (typeof ACCOUNT_TYPES)[keyof typeof ACCOUNT_TYPES];
|
||||||
export type PaidAccountType =
|
export type PaidAccountType =
|
||||||
| typeof ACCOUNT_TYPES.BASIC_20
|
| typeof ACCOUNT_TYPES.BASIC_20
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { logger } from "@/lib/logger";
|
import { logger } from "@/lib/logger";
|
||||||
import { ApiError } from "@/lib/errors";
|
import { ApiError } from "@/lib/errors";
|
||||||
import { REQUEST_STATUSES } from "@/lib/constants";
|
import { PAID_ACCOUNT_TYPE_VALUES, REQUEST_STATUSES } from "@/lib/constants";
|
||||||
import type { Prisma } from "@/lib/generated/prisma/client";
|
import type { Prisma } from "@/lib/generated/prisma/client";
|
||||||
import {
|
import {
|
||||||
calculateExtendedAvailableDate,
|
calculateExtendedAvailableDate,
|
||||||
@@ -157,6 +157,43 @@ export async function approveExtensionRequest(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createExtensionRequest(
|
||||||
|
maestroID: number
|
||||||
|
): Promise<{ maestroExtensionID: number; requestedDateTime: string; status: number }> {
|
||||||
|
const maestro = await db.maestro.findUnique({
|
||||||
|
where: { MaestroID: maestroID },
|
||||||
|
select: { AccountType: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!maestro) {
|
||||||
|
throw new ApiError("마에스트로를 찾을 수 없습니다.", 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(PAID_ACCOUNT_TYPE_VALUES as readonly number[]).includes(maestro.AccountType)) {
|
||||||
|
throw new ApiError("유료 요금제 계정만 연장 신청이 가능합니다.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = await db.maestro_extension.create({
|
||||||
|
data: {
|
||||||
|
MaestroID: maestroID,
|
||||||
|
AccountType: maestro.AccountType,
|
||||||
|
RequestedDateTime: new Date(),
|
||||||
|
Status: REQUEST_STATUSES.REQUESTED,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
MaestroExtensionID: true,
|
||||||
|
RequestedDateTime: true,
|
||||||
|
Status: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
maestroExtensionID: request.MaestroExtensionID,
|
||||||
|
requestedDateTime: request.RequestedDateTime.toISOString(),
|
||||||
|
status: request.Status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function cancelExtensionRequest(
|
export async function cancelExtensionRequest(
|
||||||
maestroExtensionID: number
|
maestroExtensionID: number
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
|||||||
+2
-10
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { logger } from "@/lib/logger";
|
import { logger } from "@/lib/logger";
|
||||||
import { ApiError } from "@/lib/errors";
|
import { ApiError } from "@/lib/errors";
|
||||||
import { ACTIVATE_STATUSES, ACCOUNT_TYPES } from "@/lib/constants";
|
import { ACTIVATE_STATUSES, PAID_ACCOUNT_TYPE_VALUES } from "@/lib/constants";
|
||||||
import type { Prisma } from "@/lib/generated/prisma/client";
|
import type { Prisma } from "@/lib/generated/prisma/client";
|
||||||
|
|
||||||
const pageSizeOptions = [10, 20, 50, 100] as const;
|
const pageSizeOptions = [10, 20, 50, 100] as const;
|
||||||
@@ -104,14 +104,6 @@ export type MaestroDetail = {
|
|||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
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 activateStatusValues = [
|
const activateStatusValues = [
|
||||||
ACTIVATE_STATUSES.PENDING,
|
ACTIVATE_STATUSES.PENDING,
|
||||||
ACTIVATE_STATUSES.TRIAL,
|
ACTIVATE_STATUSES.TRIAL,
|
||||||
@@ -130,7 +122,7 @@ export const updateMaestroSchema = z.object({
|
|||||||
accountType: z.coerce
|
accountType: z.coerce
|
||||||
.number()
|
.number()
|
||||||
.int()
|
.int()
|
||||||
.refine((v) => (paidAccountTypeValues as readonly number[]).includes(v))
|
.refine((v) => (PAID_ACCOUNT_TYPE_VALUES as readonly number[]).includes(v))
|
||||||
.optional(),
|
.optional(),
|
||||||
availableActivateDateTime: z.string().min(1).optional(),
|
availableActivateDateTime: z.string().min(1).optional(),
|
||||||
allowEditEnterCode: z.coerce.number().int().min(0).max(1).optional(),
|
allowEditEnterCode: z.coerce.number().int().min(0).max(1).optional(),
|
||||||
|
|||||||
+45
-1
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { logger } from "@/lib/logger";
|
import { logger } from "@/lib/logger";
|
||||||
import { ApiError } from "@/lib/errors";
|
import { ApiError } from "@/lib/errors";
|
||||||
import { ACTIVATE_STATUSES, REQUEST_STATUSES } from "@/lib/constants";
|
import { ACTIVATE_STATUSES, PAID_ACCOUNT_TYPE_VALUES, REQUEST_STATUSES } from "@/lib/constants";
|
||||||
import type { Prisma } from "@/lib/generated/prisma/client";
|
import type { Prisma } from "@/lib/generated/prisma/client";
|
||||||
import {
|
import {
|
||||||
calculateUpgradePrice,
|
calculateUpgradePrice,
|
||||||
@@ -167,6 +167,50 @@ export async function approveUpgradeRequest(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createUpgradeRequest(
|
||||||
|
maestroID: number,
|
||||||
|
requestedAccountType: number
|
||||||
|
): Promise<{ maestroUpgradeID: number; registeredAccountType: number; requestedDateTime: string; status: number }> {
|
||||||
|
return db.$transaction(async (tx) => {
|
||||||
|
const maestro = await tx.maestro.findUnique({
|
||||||
|
where: { MaestroID: maestroID },
|
||||||
|
select: { ActivateStatus: true, AccountType: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!maestro) {
|
||||||
|
throw new ApiError("마에스트로를 찾을 수 없습니다.", 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestedAccountType <= maestro.AccountType) {
|
||||||
|
throw new ApiError("현재 요금제보다 높은 요금제로만 업그레이드 신청이 가능합니다.", 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = await tx.maestro_upgrade.create({
|
||||||
|
data: {
|
||||||
|
MaestroID: maestroID,
|
||||||
|
RegisteredActivateStatus: maestro.ActivateStatus,
|
||||||
|
RegisteredAccountType: maestro.AccountType,
|
||||||
|
RequestedAccountType: requestedAccountType,
|
||||||
|
RequestedDateTime: new Date(),
|
||||||
|
Status: REQUEST_STATUSES.REQUESTED,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
MaestroUpgradeID: true,
|
||||||
|
RegisteredAccountType: true,
|
||||||
|
RequestedDateTime: true,
|
||||||
|
Status: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
maestroUpgradeID: request.MaestroUpgradeID,
|
||||||
|
registeredAccountType: request.RegisteredAccountType,
|
||||||
|
requestedDateTime: request.RequestedDateTime.toISOString(),
|
||||||
|
status: request.Status,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function rejectUpgradeRequest(
|
export async function rejectUpgradeRequest(
|
||||||
maestroUpgradeID: number
|
maestroUpgradeID: number
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user