Skip to content

Commit

Permalink
Merge pull request #266 from shubhagarwal1/route
Browse files Browse the repository at this point in the history
 Implement Order History View for Customer Dashboard [Backend + Routes]
  • Loading branch information
Vimall03 authored Nov 9, 2024
2 parents f1ca9f9 + 1457e1c commit feee9df
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
21 changes: 21 additions & 0 deletions alimento-nextjs/actions/customer-dash/customerVendorData.tsx
Original file line number Diff line number Diff line change
@@ -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' };
}
}
Original file line number Diff line number Diff line change
@@ -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' };
}
}
12 changes: 12 additions & 0 deletions alimento-nextjs/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit feee9df

Please sign in to comment.