import { objectType, inputObjectType, mutationField, nonNull, list, queryField, } from "nexus"; const Checkout = { addType(builder) { builder.addType( inputObjectType({ name: "CheckoutItem", definition: (t) => { t.field("quantity", { type: nonNull("Int"), }); t.field("productERPId", { type: nonNull("ID"), }); t.field("option", { type: nonNull("String"), }); }, }) ); builder.addType( objectType({ name: "PriceSummary", definition: (t) => { t.field("subtotal", { type: nonNull("Float"), }); t.field("taxes", { type: "Float", }); t.field("total", { type: nonNull("Float"), }); t.field("fees", { type: "Float", }); t.field("discounts", { type: "Float", }); }, }) ); builder.addType( objectType({ name: "ItemResponse", definition: (t) => { t.field("itemId", { type: nonNull("ID"), }); t.field("quantity", { type: nonNull("Int"), }); t.field("productERPId", { type: nonNull("ID"), }); t.field("valid", { type: nonNull("Boolean"), }); t.field("isDiscounted", { type: nonNull("Boolean"), }); t.field("basePrice", { type: "Float", }); t.field("discounts", { type: "Float", }); t.field("option", { type: "String", }); }, }) ); builder.addType( mutationField("createCheckout", { type: nonNull( objectType({ name: "CheckoutResponse", definition(t) { t.field("redirectUrl", { type: "String" }); t.field("checkoutId", { type: nonNull("ID") }); t.field("priceSummary", { type: nonNull("PriceSummary") }); t.field("items", { type: nonNull(list(nonNull("ItemResponse"))), }); t.field("sequence", { type: "Int" }); }, }) ), args: { orderType: nonNull("OrderType"), pricingType: nonNull("PricingType"), retailerId: nonNull("ID"), items: nonNull(list(nonNull("CheckoutItem"))), sequence: "Int", postCheckoutUrl: "String", }, }) ); builder.addType( queryField("checkout", { type: nonNull("CheckoutResponse"), args: { checkoutId: nonNull("ID"), retailerId: nonNull("ID"), redirectUrl: "String", }, }) ); builder.addType( mutationField("addItemToCheckout", { type: nonNull("CheckoutResponse"), args: { checkoutId: nonNull("ID"), retailerId: nonNull("ID"), item: nonNull("CheckoutItem"), sequence: nonNull("Int"), }, }) ); builder.addType( mutationField("removeItemFromCheckout", { type: nonNull("CheckoutResponse"), args: { checkoutId: nonNull("ID"), retailerId: nonNull("ID"), itemId: nonNull("ID"), sequence: nonNull("Int"), }, }) ); builder.addType( mutationField("updateQuantityFromCheckout", { type: nonNull("CheckoutResponse"), args: { checkoutId: nonNull("ID"), retailerId: nonNull("ID"), itemId: nonNull("ID"), quantity: nonNull("Int"), sequence: nonNull("Int"), }, }) ); builder.addType( objectType({ name: "Discounts", definition: (t) => { t.field("total", { type: "Float", }); }, }) ); builder.addType( objectType({ name: "Fees", definition: (t) => { t.field("total", { type: "Float", }); t.field("delivery", { type: "Float", }); t.field("payment", { type: "Float", }); t.field("tip", { type: "Float", }); }, }) ); builder.addType( objectType({ name: "Order", definition: (t) => { t.field("delivery", { type: nonNull("Boolean"), }); t.field("discounts", { type: "Discounts", }); t.field("fees", { type: "Fees", }); t.field("medical", { type: nonNull("Boolean"), }); t.field("pickup", { type: nonNull("Boolean"), }); t.field("subtotal", { type: nonNull("Float"), }); t.field("tax", { type: nonNull("Float"), }); t.field("total", { type: nonNull("Float"), }); }, }) ); builder.addType( queryField("order", { type: "Order", args: { orderNumber: nonNull("ID"), retailerId: nonNull("ID"), }, }) ); }, extend(config) { config.resolversConfig["Mutation.createCheckout"] = { middlewares: [ async (...[, , args, context]) => { return await strapi .service("plugin::dutchie-plus.checkout") .create(args, context); }, ], auth: false, }; config.resolversConfig["Query.checkout"] = { middlewares: [ async (...[, , args, context]) => { return await strapi .service("plugin::dutchie-plus.checkout") .fetch(args, context); }, ], auth: false, }; config.resolversConfig["Query.order"] = { middlewares: [ async (...[, , args, context]) => { return await strapi .service("plugin::dutchie-plus.checkout") .fetchOrderById(args, context); }, ], auth: false, }; config.resolversConfig["Mutation.addItemToCheckout"] = { middlewares: [ async (...[, , args, context]) => { return await strapi .service("plugin::dutchie-plus.checkout") .addItem(args, context); }, ], auth: false, }; config.resolversConfig["Mutation.removeItemFromCheckout"] = { middlewares: [ async (...[, , args, context]) => { return await strapi .service("plugin::dutchie-plus.checkout") .removeItem(args, context); }, ], auth: false, }; config.resolversConfig["Mutation.updateQuantityFromCheckout"] = { middlewares: [ async (...[, , args, context]) => { return await strapi .service("plugin::dutchie-plus.checkout") .updateQuantity(args, context); }, ], auth: false, }; }, }; export default Checkout;