35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import type { Order, OrderLine } from '../generated/prisma/client';
|
|
export function orderStatus(order: Pick<Order, 'status' | 'expiresAt'>) {
|
|
return order.status === 'PENDING_PAYMENT' && order.expiresAt <= new Date()
|
|
? 'EXPIRED'
|
|
: order.status;
|
|
}
|
|
export function orderView(order: Order & { lines: OrderLine[] }) {
|
|
return {
|
|
id: order.id,
|
|
status: orderStatus(order),
|
|
currency: order.currency,
|
|
subtotal: order.subtotal,
|
|
discount: order.discount,
|
|
merchandiseTotal: order.merchandiseTotal,
|
|
pricingStatus: 'UNFINALIZED',
|
|
taxTotal: null,
|
|
shippingTotal: null,
|
|
payableTotal: null,
|
|
paymentAvailable: false,
|
|
address: order.addressSnapshot,
|
|
coupon: order.couponSnapshot,
|
|
createdAt: order.createdAt,
|
|
expiresAt: order.expiresAt,
|
|
lines: order.lines.map((line) => ({
|
|
variantId: line.variantId,
|
|
sku: line.sku,
|
|
productName: line.productName,
|
|
variantName: line.variantName,
|
|
quantity: line.quantity,
|
|
unitPrice: line.unitPrice,
|
|
lineTotal: line.lineTotal,
|
|
})),
|
|
};
|
|
}
|