마에스트로 상세 화면에 [연장] 신청 버튼 추가
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user