|
@@ -1,6 +1,5 @@
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
import { bagistoFetch } from "@/utils/bagisto";
|
|
import { bagistoFetch } from "@/utils/bagisto";
|
|
|
-import { isBagistoError } from "@/utils/type-guards";
|
|
|
|
|
import { getAuthToken } from "@/utils/helper";
|
|
import { getAuthToken } from "@/utils/helper";
|
|
|
import {
|
|
import {
|
|
|
CREATE_ADD_PRODUCT_IN_CART,
|
|
CREATE_ADD_PRODUCT_IN_CART,
|
|
@@ -62,55 +61,7 @@ function authorizationOperations(body: Record<string, any>,req:NextRequest): Fet
|
|
|
const guestToken = getAuthToken(req);
|
|
const guestToken = getAuthToken(req);
|
|
|
const query = ALLOWED_OPERATIONS[operationName];
|
|
const query = ALLOWED_OPERATIONS[operationName];
|
|
|
const finalVariables = variables;
|
|
const finalVariables = variables;
|
|
|
-
|
|
|
|
|
- /*if (operationName === 'CheckoutPaymentMethods' || operationName === 'CheckoutShippingRates') {
|
|
|
|
|
- finalVariables = { ...variables };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (operationName === 'CreateCheckoutPaymentMethod') {
|
|
|
|
|
- finalVariables = {
|
|
|
|
|
- ...variables,
|
|
|
|
|
- successUrl: variables?.successUrl ?? `payment/success`,
|
|
|
|
|
- failureUrl: variables?.failureUrl ?? `payment/failure`,
|
|
|
|
|
- cancelUrl: variables?.cancelUrl ?? `payment/cancel`
|
|
|
|
|
- };
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
- /*if (operationName === 'createCheckoutAddress' && body.billingFirstName) {
|
|
|
|
|
- finalVariables = {
|
|
|
|
|
- billingFirstName: body.billingFirstName,
|
|
|
|
|
- billingLastName: body.billingLastName,
|
|
|
|
|
- billingEmail: body.billingEmail,
|
|
|
|
|
- billingAddress: body.billingAddress,
|
|
|
|
|
- billingCity: body.billingCity,
|
|
|
|
|
- billingCountry: body.billingCountry,
|
|
|
|
|
- billingState: body.billingState,
|
|
|
|
|
- billingPostcode: body.billingPostcode,
|
|
|
|
|
- billingPhoneNumber: body.billingPhoneNumber,
|
|
|
|
|
- billingCompanyName: body.billingCompanyName,
|
|
|
|
|
- useForShipping: body.useForShipping,
|
|
|
|
|
- ...(!body.useForShipping && {
|
|
|
|
|
- shippingFirstName: body.shippingFirstName,
|
|
|
|
|
- shippingLastName: body.shippingLastName,
|
|
|
|
|
- shippingEmail: body.billingEmail,
|
|
|
|
|
- shippingAddress: body.shippingAddress,
|
|
|
|
|
- shippingCity: body.shippingCity,
|
|
|
|
|
- shippingCountry: body.shippingCountry,
|
|
|
|
|
- shippingState: body.shippingState,
|
|
|
|
|
- shippingPostcode: body.shippingPostcode,
|
|
|
|
|
- shippingPhoneNumber: body.shippingPhoneNumber,
|
|
|
|
|
- shippingCompanyName: body.shippingCompanyName,
|
|
|
|
|
- })
|
|
|
|
|
- };
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
- /*if (operationName === 'createAddProductInCart' && body.productId) {
|
|
|
|
|
- finalVariables = {
|
|
|
|
|
- cartId: body.cartId ?? null,
|
|
|
|
|
- productId: body.productId,
|
|
|
|
|
- quantity: body.quantity,
|
|
|
|
|
- };
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
query,
|
|
query,
|
|
|
variables: finalVariables,
|
|
variables: finalVariables,
|
|
@@ -151,27 +102,22 @@ export async function POST(req: NextRequest) {
|
|
|
|
|
|
|
|
|
|
|
|
|
const response = await bagistoFetch<any>(fetchOption);
|
|
const response = await bagistoFetch<any>(fetchOption);
|
|
|
- // console.log('response ------ ', response);
|
|
|
|
|
- return NextResponse.json({
|
|
|
|
|
- data: response.body.data,
|
|
|
|
|
|
|
+ console.log('bagistoFetch response ------ ', response);
|
|
|
|
|
+ return NextResponse.json(response.body,{
|
|
|
|
|
+ status: response.status
|
|
|
});
|
|
});
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- if (isBagistoError(error)) {
|
|
|
|
|
- return NextResponse.json(
|
|
|
|
|
- {
|
|
|
|
|
- data: null,
|
|
|
|
|
- error: error.cause ?? error,
|
|
|
|
|
- },
|
|
|
|
|
- { status: 200 }
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ console.log('bagistoFetch ERROR ------ ', error);
|
|
|
return NextResponse.json(
|
|
return NextResponse.json(
|
|
|
{
|
|
{
|
|
|
- message: "Network error",
|
|
|
|
|
- error: error instanceof Error ? error.message : error,
|
|
|
|
|
|
|
+ errors:[
|
|
|
|
|
+ {
|
|
|
|
|
+ message: error instanceof Error ? error.message : "Network error"
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
|
|
+ data:null
|
|
|
},
|
|
},
|
|
|
- { status: 500 }
|
|
|
|
|
|
|
+ { status:500 }
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|