diff --git a/alimento-nextjs/actions/customer-dash/customerVendorData.tsx b/alimento-nextjs/actions/customer-dash/customerVendorData.tsx new file mode 100644 index 0000000..f61b5e4 --- /dev/null +++ b/alimento-nextjs/actions/customer-dash/customerVendorData.tsx @@ -0,0 +1,21 @@ +'use server'; + +import prismadb from '@/lib/prismadb'; + +export async function getCustomerVendorData() { + try { + const customers = await prismadb.customer.findMany(); + const vendors = await prismadb.vendor.findMany(); + + return { + success: true, + data: { + customers, + vendors, + }, + }; + } catch (error) { + console.error('[GET_CUSTOMER_VENDOR_ERROR]', error); + return { success: false, error: 'Error fetching data' }; + } +} diff --git a/alimento-nextjs/actions/customer-dash/customerVendorOrderHistory.tsx b/alimento-nextjs/actions/customer-dash/customerVendorOrderHistory.tsx new file mode 100644 index 0000000..0228e10 --- /dev/null +++ b/alimento-nextjs/actions/customer-dash/customerVendorOrderHistory.tsx @@ -0,0 +1,32 @@ +'use server'; + +import prismadb from '@/lib/prismadb'; + +export async function getOrderHistory({ + customerId, + vendorId, +}: { + customerId?: string; + vendorId?: string; +}) { + try { + const orders = await prismadb.order.findMany({ + where: { + ...(customerId ? { customerId } : {}), + ...(vendorId ? { vendorId } : {}), + }, + include: { + customer: true, + vendor: true, + }, + }); + + return { + success: true, + data: orders, + }; + } catch (error) { + console.error('[GET_ORDER_HISTORY_ERROR]', error); + return { success: false, error: 'Error fetching order history' }; + } +} diff --git a/alimento-nextjs/prisma/schema.prisma b/alimento-nextjs/prisma/schema.prisma index 30e75cf..ef2c3e7 100644 --- a/alimento-nextjs/prisma/schema.prisma +++ b/alimento-nextjs/prisma/schema.prisma @@ -114,3 +114,15 @@ model Answer { questionId String question Question @relation("QuestionAnswers", fields: [questionId], references: [id], onDelete: Cascade) // Moved onDelete: Cascade to this side } + +model Order { + id String @id @default(uuid()) @map("_id") + customerId String + customer Customer @relation(fields: [customerId], references: [id]) + vendorId String + vendor Vendor @relation(fields: [vendorId], references: [id]) + totalAmount Float + status String // e.g., "PENDING", "COMPLETED", "CANCELLED" + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +}