refactor: move slugSchema into schemas file and rename to idSchema
This commit is contained in:
parent
b369d1f5c7
commit
48c99e442f
3 changed files with 9 additions and 12 deletions
|
|
@ -6,20 +6,16 @@ import path from "path";
|
|||
|
||||
import { auth } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { idSchema } from "@/lib/schemas";
|
||||
|
||||
const uploadsDirectory = path.join(process.cwd(), "public", "mii");
|
||||
|
||||
const slugSchema = z.coerce
|
||||
.number({ message: "Mii ID must be a number" })
|
||||
.int({ message: "Mii ID must be an integer" })
|
||||
.positive({ message: "Mii ID must be valid" });
|
||||
|
||||
export async function DELETE(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const session = await auth();
|
||||
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
|
||||
const { id: slugId } = await params;
|
||||
const parsed = slugSchema.safeParse(slugId);
|
||||
const parsed = idSchema.safeParse(slugId);
|
||||
|
||||
if (!parsed.success) return NextResponse.json({ error: parsed.error.errors[0].message }, { status: 400 });
|
||||
const miiId = parsed.data;
|
||||
|
|
|
|||
|
|
@ -3,18 +3,14 @@ import { z } from "zod";
|
|||
|
||||
import { auth } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
const slugSchema = z.coerce
|
||||
.number({ message: "Mii ID must be a number" })
|
||||
.int({ message: "Mii ID must be an integer" })
|
||||
.positive({ message: "Mii ID must be valid" });
|
||||
import { idSchema } from "@/lib/schemas";
|
||||
|
||||
export async function PATCH(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const session = await auth();
|
||||
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
|
||||
const { id: slugId } = await params;
|
||||
const parsed = slugSchema.safeParse(slugId);
|
||||
const parsed = idSchema.safeParse(slugId);
|
||||
|
||||
if (!parsed.success) return NextResponse.json({ error: parsed.error.errors[0].message }, { status: 400 });
|
||||
const miiId = parsed.data;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ export const tagsSchema = z
|
|||
.min(1, { message: "There must be at least 1 tag" })
|
||||
.max(8, { message: "There cannot be more than 8 tags" });
|
||||
|
||||
export const idSchema = z.coerce
|
||||
.number({ message: "Mii ID must be a number" })
|
||||
.int({ message: "Mii ID must be an integer" })
|
||||
.positive({ message: "Mii ID must be valid" });
|
||||
|
||||
// Account Info
|
||||
export const usernameSchema = z
|
||||
.string()
|
||||
|
|
|
|||
Loading…
Reference in a new issue