1- import { NextRequest , NextResponse } from " next/server" ;
1+ import { NextRequest , NextResponse } from ' next/server' ;
22
3- import { MoneyValueError } from " @/db/queries/shop/orders" ;
4- import { resolveLocaleAndCurrency } from " @/lib/shop/request-locale" ;
3+ import { MoneyValueError } from ' @/db/queries/shop/orders' ;
4+ import { resolveLocaleAndCurrency } from ' @/lib/shop/request-locale' ;
55
6- import { rehydrateCartItems } from "@/lib/services/products" ;
7- import { cartRehydratePayloadSchema } from "@/lib/validation/shop" ;
8- import { InvalidPayloadError , PriceConfigError } from "@/lib/services/errors" ;
6+ import { rehydrateCartItems } from '@/lib/services/products' ;
7+ import { cartRehydratePayloadSchema } from '@/lib/validation/shop' ;
8+ import { InvalidPayloadError , PriceConfigError } from '@/lib/services/errors' ;
9+ import { logError } from '@/lib/logging' ;
910
1011function normalizeCartPayload ( body : unknown ) {
11- if ( ! body || typeof body !== " object" ) return body ;
12+ if ( ! body || typeof body !== ' object' ) return body ;
1213 const { items, ...rest } = body as { items ?: unknown } ;
1314
1415 if ( ! Array . isArray ( items ) ) return body ;
1516
1617 return {
1718 ...rest ,
18- items : items . map ( ( item ) => {
19- if ( ! item || typeof item !== " object" ) return item ;
19+ items : items . map ( item => {
20+ if ( ! item || typeof item !== ' object' ) return item ;
2021 const { quantity, ...itemRest } = item as { quantity ?: unknown } ;
2122 const normalizedQuantity =
22- typeof quantity === " string" && quantity . trim ( ) . length > 0
23+ typeof quantity === ' string' && quantity . trim ( ) . length > 0
2324 ? Number ( quantity )
2425 : quantity ;
2526
@@ -35,7 +36,7 @@ export async function POST(request: NextRequest) {
3536 body = await request . json ( ) ;
3637 } catch {
3738 return NextResponse . json (
38- { error : " Unable to process cart data." } ,
39+ { error : ' Unable to process cart data.' } ,
3940 { status : 400 }
4041 ) ;
4142 }
@@ -45,20 +46,19 @@ export async function POST(request: NextRequest) {
4546
4647 if ( ! parsedPayload . success ) {
4748 return NextResponse . json (
48- { error : " Invalid cart payload" , details : parsedPayload . error . format ( ) } ,
49+ { error : ' Invalid cart payload' , details : parsedPayload . error . format ( ) } ,
4950 { status : 400 }
5051 ) ;
5152 }
5253
5354 const { currency } = resolveLocaleAndCurrency ( request ) ;
5455
55-
5656 try {
5757 const { items } = parsedPayload . data ;
5858 const parsedResult = await rehydrateCartItems ( items , currency ) ;
5959 return NextResponse . json ( parsedResult ) ;
6060 } catch ( error ) {
61- console . error ( "Cart rehydrate failed" , error ) ;
61+ logError ( 'cart_rehydrate_failed' , error ) ;
6262
6363 if ( error instanceof PriceConfigError ) {
6464 return NextResponse . json (
@@ -73,8 +73,8 @@ export async function POST(request: NextRequest) {
7373 if ( error instanceof MoneyValueError ) {
7474 return NextResponse . json (
7575 {
76- code : " PRICE_CONFIG_ERROR" ,
77- message : " Invalid price configuration for one or more products." ,
76+ code : ' PRICE_CONFIG_ERROR' ,
77+ message : ' Invalid price configuration for one or more products.' ,
7878 details : {
7979 productId : error . productId ,
8080 field : error . field ,
@@ -93,7 +93,7 @@ export async function POST(request: NextRequest) {
9393 }
9494
9595 return NextResponse . json (
96- { error : " Unable to rehydrate cart." } ,
96+ { error : ' Unable to rehydrate cart.' } ,
9797 { status : 500 }
9898 ) ;
9999 }
0 commit comments