-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2026fc
commit 32cc7dd
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
alimento-nextjs/actions/customer-order/ GetOrderStatusandETA.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use server'; | ||
|
||
import prismadb from '@/lib/prismadb'; | ||
|
||
export async function getOrderStatusAndETA({ | ||
orderId, | ||
}: { | ||
orderId: string; | ||
}): Promise<{ success: boolean; data?: any; error?: string }> { | ||
try { | ||
const order = await prismadb.order.findUnique({ | ||
where: { id: orderId }, | ||
include: { | ||
dish: true, // Include dish details | ||
}, | ||
}); | ||
|
||
if (!order) { | ||
return { success: false, error: 'Order not found' }; | ||
} | ||
|
||
return { success: true, data: { status: order.status, eta: order.estimatedTimeOfArrival } }; | ||
} catch (error) { | ||
console.error('[GET_ORDER_STATUS_ETA_ERROR]', error); | ||
return { success: false, error: 'Error fetching order status and ETA' }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use server'; | ||
|
||
import prismadb from '@/lib/prismadb'; | ||
|
||
export async function createOrder({ | ||
customerId, | ||
dishId, | ||
estimatedTimeOfArrival, | ||
}: { | ||
customerId: string; | ||
dishId: string; | ||
estimatedTimeOfArrival: Date; | ||
}): Promise<{ success: boolean; error?: string }> { | ||
try { | ||
await prismadb.order.create({ | ||
data: { | ||
customerId, | ||
dishId, | ||
estimatedTimeOfArrival, | ||
}, | ||
}); | ||
|
||
return { success: true }; | ||
} catch (error) { | ||
console.error('[CREATE_ORDER_ERROR]', error); | ||
return { success: false, error: 'Error creating order' }; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use server'; | ||
|
||
import prismadb from '@/lib/prismadb'; | ||
|
||
export async function getCustomerCurrentOrder({ | ||
customerId, | ||
}: { | ||
customerId: string; | ||
}): Promise<{ success: boolean; data?: any; error?: string }> { | ||
try { | ||
const order = await prismadb.order.findFirst({ | ||
where: { | ||
customerId, | ||
status: { | ||
in: ['PENDING', 'IN_PROGRESS'], // Fetch only active orders (pending or in progress) | ||
}, | ||
}, | ||
include: { | ||
dish: true, // Include details of the ordered dish | ||
customer: true, // Include customer details | ||
}, | ||
}); | ||
|
||
return { success: true, data: order }; | ||
} catch (error) { | ||
console.error('[GET_CUSTOMER_CURRENT_ORDER_ERROR]', error); | ||
return { success: false, error: 'Error fetching current order' }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use server'; | ||
|
||
import prismadb from '@/lib/prismadb'; | ||
|
||
export async function updateOrderStatus({ | ||
orderId, | ||
status, | ||
}: { | ||
orderId: string; | ||
status: 'PENDING' | 'IN_PROGRESS' | 'COMPLETED' | 'CANCELLED'; | ||
}): Promise<{ success: boolean; error?: string }> { | ||
try { | ||
await prismadb.order.update({ | ||
where: { id: orderId }, | ||
data: { status }, | ||
}); | ||
|
||
return { success: true }; | ||
} catch (error) { | ||
console.error('[UPDATE_ORDER_STATUS_ERROR]', error); | ||
return { success: false, error: 'Error updating order status' }; | ||
} | ||
} |