55 lines
3.2 KiB
TypeScript
55 lines
3.2 KiB
TypeScript
import { Resolver, Authorized, Ctx } from 'type-graphql';
|
|
import { Mutation, Arg } from 'type-graphql';
|
|
import { ApolloContext } from '@seed/interfaces/context';
|
|
|
|
// From Module
|
|
import { OrderEngineSchema } from '../../schemas/order.schema';
|
|
import { CheckoutEngineInput } from '../../schemas/order.schema.input';
|
|
|
|
// From SRC
|
|
import OrderModel from '@src/orders/order.model';
|
|
import { createCheckout, finaliseCheckoutWithOrder } from '../../services/OrderService';
|
|
import { PaymentProvider } from '@services/module-payments/components/components.payments';
|
|
import { CheckoutInput } from '@src/orders/components/checkout.schema';
|
|
|
|
@Resolver(OrderModel)
|
|
export default class CheckoutEngineResolver {
|
|
/*
|
|
██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗
|
|
██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝
|
|
██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝
|
|
██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝
|
|
╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║
|
|
╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
|
|
*/
|
|
|
|
/*
|
|
███╗ ███╗██╗ ██╗████████╗ █████╗ ████████╗ ██████╗ ██████╗ ███████╗
|
|
████╗ ████║██║ ██║╚══██╔══╝██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
|
|
██╔████╔██║██║ ██║ ██║ ███████║ ██║ ██║ ██║██████╔╝███████╗
|
|
██║╚██╔╝██║██║ ██║ ██║ ██╔══██║ ██║ ██║ ██║██╔══██╗╚════██║
|
|
██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║ ██║ ╚██████╔╝██║ ██║███████║
|
|
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
|
|
*/
|
|
|
|
@Mutation(() => OrderEngineSchema)
|
|
@Authorized()
|
|
async finaliseCheckoutWithStripe(@Arg('input') input: CheckoutInput, @Ctx() ctx: ApolloContext): Promise<OrderEngineSchema> {
|
|
try {
|
|
const { billingInfo, contactInfo, ...rest } = input;
|
|
return await finaliseCheckoutWithOrder({
|
|
type: 'default',
|
|
payment: PaymentProvider.stripe,
|
|
contactInfo: {
|
|
billingInfo,
|
|
contactInfo,
|
|
},
|
|
input: rest,
|
|
ctx,
|
|
});
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|