feat(MED-48): improvements
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { MontonioOrderToken } from "@/app/home/(user)/_components/cart/types";
|
||||
import { loadCurrentUserAccount } from "@/app/home/(user)/_lib/server/load-user-account";
|
||||
import { placeOrder } from "@lib/data/cart";
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { z } from "zod";
|
||||
import { MontonioOrderToken } from "@/app/home/(user)/_components/cart/types";
|
||||
import { loadCurrentUserAccount } from "@/app/home/(user)/_lib/server/load-user-account";
|
||||
import { listProductTypes } from "@lib/data/products";
|
||||
import { placeOrder } from "@lib/data/cart";
|
||||
import { createI18nServerInstance } from "~/lib/i18n/i18n.server";
|
||||
|
||||
const emailSender = process.env.EMAIL_SENDER;
|
||||
@@ -70,11 +71,13 @@ const handleOrderToken = async (orderToken: string) => {
|
||||
if (!cartId) {
|
||||
throw new Error("Cart ID not found");
|
||||
}
|
||||
const { productTypes } = await listProductTypes();
|
||||
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
|
||||
const { order } = await placeOrder(cartId, { revalidateCacheTags: true });
|
||||
return {
|
||||
email: order.email,
|
||||
partnerLocationName: order.metadata?.partner_location_name as string ?? '',
|
||||
analysisPackageName: order.items?.[0]?.title ?? '',
|
||||
analysisPackageName: order.items?.find(item => item.product_type_id === analysisPackagesType?.id)?.title ?? '',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to place order, message=${error}`);
|
||||
@@ -102,7 +105,7 @@ export async function GET(request: Request) {
|
||||
|
||||
const { email, partnerLocationName, analysisPackageName } = orderResult;
|
||||
const personName = account.name;
|
||||
if (email) {
|
||||
if (email && analysisPackageName && partnerLocationName) {
|
||||
await sendEmail({ email, analysisPackageName, personName, partnerLocationName, language });
|
||||
}
|
||||
return Response.redirect(new URL('/home/order', baseUrl))
|
||||
|
||||
Reference in New Issue
Block a user