model Product {
id String @id @default(uuid())
name String
description String
price Float
stockQuantity Int @default(0)
unit String
// Remove the files relation as it will be accessed from the other side
file File?
user User @relation(fields: [userId], references: [id])
userId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model File {
id String @id @default(uuid())
createdAt DateTime @default(now())
// Make this a one-to-one relation
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
productId String @unique // Add unique constraint to ensure one-to-one relationship
name String
type String
key String
uploadUrl String
}export const getProducts: GetProducts<void, Product[]> = async (args, context) => {
if (!context.user) {
throw new HttpError(401)
}
return context.entities.Product.findMany({
where: { user: { id: context.user.id }},
orderBy: { createdAt: 'asc'},
include: {
file: true
}
})
};