diff --git a/app/api/photos/route.ts b/app/api/photos/route.ts index 4ed5205..edcb0ca 100644 --- a/app/api/photos/route.ts +++ b/app/api/photos/route.ts @@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server" import { auth } from "@/lib/auth" import { prisma } from "@/lib/prisma" import { sendNewPhotoEmail } from "@/lib/email" +import type { Prisma } from "@prisma/client" // Legacy endpoint for URL-based uploads (kept for backward compatibility) export async function POST(req: NextRequest) { @@ -46,7 +47,7 @@ export async function POST(req: NextRequest) { answerName: answerName.trim(), points: pointsValue, maxAttempts: maxAttemptsValue, - } as any, + } as Prisma.PhotoUncheckedCreateInput, include: { uploader: { select: { diff --git a/app/api/photos/upload-multiple/route.ts b/app/api/photos/upload-multiple/route.ts index a37de9c..a61c942 100644 --- a/app/api/photos/upload-multiple/route.ts +++ b/app/api/photos/upload-multiple/route.ts @@ -6,7 +6,7 @@ import { writeFile } from "fs/promises" import { join } from "path" import { existsSync, mkdirSync } from "fs" import { createHash } from "crypto" -import type { Photo } from "@prisma/client" +import type { Prisma } from "@prisma/client" export async function POST(req: NextRequest) { try { @@ -44,9 +44,9 @@ export async function POST(req: NextRequest) { mkdirSync(uploadsDir, { recursive: true }) } - type PhotoWithUploader = Photo & { - uploader: { name: string } - } + type PhotoWithUploader = Prisma.PhotoGetPayload<{ + include: { uploader: { select: { name: true } } } + }> const createdPhotos: PhotoWithUploader[] = [] @@ -106,7 +106,7 @@ export async function POST(req: NextRequest) { // Check for duplicate file const existingPhoto = await prisma.photo.findFirst({ - where: { fileHash } as any, + where: { fileHash } as Prisma.PhotoWhereInput, }) if (existingPhoto) { @@ -158,7 +158,7 @@ export async function POST(req: NextRequest) { penaltyEnabled: penaltyEnabled, penaltyPoints: penaltyPointsValue, maxAttempts: maxAttemptsValue, - } as any, + } as Prisma.PhotoUncheckedCreateInput, include: { uploader: { select: { @@ -168,7 +168,7 @@ export async function POST(req: NextRequest) { }, }) - createdPhotos.push(photo as PhotoWithUploader) + createdPhotos.push(photo) } // Send emails to all other users for all photos diff --git a/app/api/photos/upload/route.ts b/app/api/photos/upload/route.ts index c883f05..368e4ce 100644 --- a/app/api/photos/upload/route.ts +++ b/app/api/photos/upload/route.ts @@ -6,6 +6,7 @@ import { writeFile } from "fs/promises" import { join } from "path" import { existsSync, mkdirSync } from "fs" import { createHash } from "crypto" +import type { Prisma } from "@prisma/client" export async function POST(req: NextRequest) { try { @@ -62,7 +63,7 @@ export async function POST(req: NextRequest) { // Check for duplicate file const existingPhoto = await prisma.photo.findFirst({ - where: { fileHash } as any, + where: { fileHash } as Prisma.PhotoWhereInput, }) if (existingPhoto) { @@ -122,7 +123,7 @@ export async function POST(req: NextRequest) { answerName: answerName.trim(), points: pointsValue, maxAttempts: maxAttemptsValue, - } as any, + } as Prisma.PhotoUncheckedCreateInput, include: { uploader: { select: { diff --git a/app/photos/[id]/page.tsx b/app/photos/[id]/page.tsx index 7240bf2..9c74940 100644 --- a/app/photos/[id]/page.tsx +++ b/app/photos/[id]/page.tsx @@ -49,10 +49,17 @@ export default async function PhotoPage({ params }: { params: Promise<{ id: stri const hasCorrectGuess = userGuess?.correct || false const isOwner = photo.uploaderId === session.user.id + // Type assertion for new fields (penaltyEnabled, penaltyPoints, maxAttempts) + type PhotoWithNewFields = typeof photo & { + penaltyEnabled: boolean + penaltyPoints: number + maxAttempts: number | null + } + const photoWithFields = photo as PhotoWithNewFields + // Calculate remaining attempts - const photoWithMaxAttempts = photo as typeof photo & { maxAttempts: number | null | undefined } const userGuessCount = photo.guesses.length - const maxAttempts = photoWithMaxAttempts.maxAttempts ?? null + const maxAttempts = photoWithFields.maxAttempts ?? null const remainingAttempts = maxAttempts !== null && maxAttempts > 0 ? Math.max(0, maxAttempts - userGuessCount) : null @@ -77,9 +84,9 @@ export default async function PhotoPage({ params }: { params: Promise<{ id: stri +{photo.points} {photo.points === 1 ? "point" : "points"} if correct - {(photo as any).penaltyEnabled && (photo as any).penaltyPoints > 0 && ( + {photoWithFields.penaltyEnabled && photoWithFields.penaltyPoints > 0 && ( - -{(photo as any).penaltyPoints} {(photo as any).penaltyPoints === 1 ? "point" : "points"} if wrong + -{photoWithFields.penaltyPoints} {photoWithFields.penaltyPoints === 1 ? "point" : "points"} if wrong )} {maxAttempts !== null && maxAttempts > 0 && ( @@ -117,9 +124,9 @@ export default async function PhotoPage({ params }: { params: Promise<{ id: stri
Your last guess: {userGuess.guessText}
- {(photo as any).penaltyEnabled && (photo as any).penaltyPoints > 0 && ( + {photoWithFields.penaltyEnabled && photoWithFields.penaltyPoints > 0 && (- You lost {(photo as any).penaltyPoints} {(photo as any).penaltyPoints === 1 ? "point" : "points"} for this wrong guess. + You lost {photoWithFields.penaltyPoints} {photoWithFields.penaltyPoints === 1 ? "point" : "points"} for this wrong guess.
)}