웹 로그, DB 쿼리문과 결과 로그 출력
This commit is contained in:
@@ -1,67 +1,51 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import {
|
||||
approveExtensionRequest,
|
||||
cancelExtensionRequest,
|
||||
ExtensionRequestActionError,
|
||||
} from "@/lib/extension-requests";
|
||||
import { ApiError } from "@/lib/errors";
|
||||
import { withApiHandler } from "@/lib/api-handler";
|
||||
import { logger } from "@/lib/logger";
|
||||
|
||||
const CTX = "extension-requests/[id]";
|
||||
|
||||
const patchBodySchema = z.object({
|
||||
action: z.enum(["approve", "cancel"]),
|
||||
});
|
||||
|
||||
type ExtensionRequestRouteContext = {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
}>;
|
||||
};
|
||||
export const PATCH = withApiHandler<{ id: string }>(
|
||||
CTX,
|
||||
async (request, { params, t0 }) => {
|
||||
const { id } = await params;
|
||||
const maestroExtensionID = Number(id);
|
||||
|
||||
export async function PATCH(
|
||||
request: Request,
|
||||
{ params }: ExtensionRequestRouteContext
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!Number.isInteger(maestroExtensionID) || maestroExtensionID <= 0) {
|
||||
throw new ApiError("Invalid extension request id", 400);
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const maestroExtensionID = Number(id);
|
||||
|
||||
if (!Number.isInteger(maestroExtensionID) || maestroExtensionID <= 0) {
|
||||
return NextResponse.json(
|
||||
{ message: "Invalid extension request id" },
|
||||
{ status: 400 }
|
||||
const body = patchBodySchema.safeParse(
|
||||
await request.json().catch(() => ({}))
|
||||
);
|
||||
}
|
||||
if (!body.success) {
|
||||
throw new ApiError("Invalid action", 400);
|
||||
}
|
||||
|
||||
const body = patchBodySchema.safeParse(
|
||||
await request.json().catch(() => ({}))
|
||||
);
|
||||
|
||||
if (!body.success) {
|
||||
return NextResponse.json({ message: "Invalid action" }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
if (body.data.action === "approve") {
|
||||
const result = await approveExtensionRequest(maestroExtensionID);
|
||||
logger.info(CTX, "approved", {
|
||||
id: maestroExtensionID,
|
||||
duration: Date.now() - t0,
|
||||
});
|
||||
return NextResponse.json({ ok: true, ...result });
|
||||
}
|
||||
|
||||
await cancelExtensionRequest(maestroExtensionID);
|
||||
logger.info(CTX, "cancelled", {
|
||||
id: maestroExtensionID,
|
||||
duration: Date.now() - t0,
|
||||
});
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
if (error instanceof ExtensionRequestActionError) {
|
||||
return NextResponse.json(
|
||||
{ message: error.message },
|
||||
{ status: error.statusCode }
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import { getExtensionRequests } from "@/lib/extension-requests";
|
||||
import { withApiHandler } from "@/lib/api-handler";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
export const GET = withApiHandler("extension-requests", async (request) => {
|
||||
const url = new URL(request.url);
|
||||
const result = await getExtensionRequests(url.searchParams);
|
||||
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,39 +1,25 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import { getMaestroDetail } from "@/lib/maestros";
|
||||
import { ApiError } from "@/lib/errors";
|
||||
import { withApiHandler } from "@/lib/api-handler";
|
||||
|
||||
type MaestroDetailRouteContext = {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
}>;
|
||||
};
|
||||
export const GET = withApiHandler<{ id: string }>(
|
||||
"maestros/[id]",
|
||||
async (_request, { params }) => {
|
||||
const { id } = await params;
|
||||
const maestroID = Number(id);
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: MaestroDetailRouteContext
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!Number.isInteger(maestroID) || maestroID <= 0) {
|
||||
throw new ApiError("Invalid maestro id", 400);
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
||||
const result = await getMaestroDetail(maestroID);
|
||||
|
||||
if (!result) {
|
||||
throw new ApiError("Not found", 404);
|
||||
}
|
||||
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const maestroID = Number(id);
|
||||
|
||||
if (!Number.isInteger(maestroID) || maestroID <= 0) {
|
||||
return NextResponse.json(
|
||||
{ message: "Invalid maestro id" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await getMaestroDetail(maestroID);
|
||||
|
||||
if (!result) {
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import { getMaestros } from "@/lib/maestros";
|
||||
import { withApiHandler } from "@/lib/api-handler";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
export const GET = withApiHandler("maestros", async (request) => {
|
||||
const url = new URL(request.url);
|
||||
const result = await getMaestros(url.searchParams);
|
||||
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,67 +1,51 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import {
|
||||
approveUpgradeRequest,
|
||||
rejectUpgradeRequest,
|
||||
UpgradeRequestActionError,
|
||||
} from "@/lib/upgrade-requests";
|
||||
import { ApiError } from "@/lib/errors";
|
||||
import { withApiHandler } from "@/lib/api-handler";
|
||||
import { logger } from "@/lib/logger";
|
||||
|
||||
const CTX = "upgrade-requests/[id]";
|
||||
|
||||
const patchBodySchema = z.object({
|
||||
action: z.enum(["approve", "reject"]),
|
||||
});
|
||||
|
||||
type UpgradeRequestRouteContext = {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
}>;
|
||||
};
|
||||
export const PATCH = withApiHandler<{ id: string }>(
|
||||
CTX,
|
||||
async (request, { params, t0 }) => {
|
||||
const { id } = await params;
|
||||
const maestroUpgradeID = Number(id);
|
||||
|
||||
export async function PATCH(
|
||||
request: Request,
|
||||
{ params }: UpgradeRequestRouteContext
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!Number.isInteger(maestroUpgradeID) || maestroUpgradeID <= 0) {
|
||||
throw new ApiError("Invalid upgrade request id", 400);
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const maestroUpgradeID = Number(id);
|
||||
|
||||
if (!Number.isInteger(maestroUpgradeID) || maestroUpgradeID <= 0) {
|
||||
return NextResponse.json(
|
||||
{ message: "Invalid upgrade request id" },
|
||||
{ status: 400 }
|
||||
const body = patchBodySchema.safeParse(
|
||||
await request.json().catch(() => ({}))
|
||||
);
|
||||
}
|
||||
if (!body.success) {
|
||||
throw new ApiError("Invalid action", 400);
|
||||
}
|
||||
|
||||
const body = patchBodySchema.safeParse(
|
||||
await request.json().catch(() => ({}))
|
||||
);
|
||||
|
||||
if (!body.success) {
|
||||
return NextResponse.json({ message: "Invalid action" }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
if (body.data.action === "approve") {
|
||||
const result = await approveUpgradeRequest(maestroUpgradeID);
|
||||
logger.info(CTX, "approved", {
|
||||
id: maestroUpgradeID,
|
||||
duration: Date.now() - t0,
|
||||
});
|
||||
return NextResponse.json({ ok: true, ...result });
|
||||
}
|
||||
|
||||
await rejectUpgradeRequest(maestroUpgradeID);
|
||||
logger.info(CTX, "rejected", {
|
||||
id: maestroUpgradeID,
|
||||
duration: Date.now() - t0,
|
||||
});
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
if (error instanceof UpgradeRequestActionError) {
|
||||
return NextResponse.json(
|
||||
{ message: error.message },
|
||||
{ status: error.statusCode }
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import { getUpgradeRequests } from "@/lib/upgrade-requests";
|
||||
import { withApiHandler } from "@/lib/api-handler";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
export const GET = withApiHandler("upgrade-requests", async (request) => {
|
||||
const url = new URL(request.url);
|
||||
const result = await getUpgradeRequests(url.searchParams);
|
||||
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user