feat(core-flows,medusa,types): add automatic-taxes to region + generate tax lines endpoint (#6667)

what:

- endpoint to generate tax lines
- update workflows to force calculate tax lines with a flag
- added automatic_taxes to region
This commit is contained in:
Riqwan Thamir
2024-03-12 14:36:22 +00:00
committed by GitHub
parent 87e63c024e
commit c3c4f49fc2
14 changed files with 296 additions and 12 deletions
@@ -0,0 +1,43 @@
import { updateTaxLinesWorkflow } from "@medusajs/core-flows"
import { Modules } from "@medusajs/modules-sdk"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
import { defaultStoreCartFields } from "../../query-config"
import { StorePostCartsCartTaxesReq } from "../../validators"
export const POST = async (
req: MedusaRequest<StorePostCartsCartTaxesReq>,
res: MedusaResponse
) => {
const workflow = updateTaxLinesWorkflow(req.scope)
const { errors } = await workflow.run({
input: {
cart_or_cart_id: req.params.id,
force_tax_calculation: true,
},
throwOnError: false,
})
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const query = remoteQueryObjectFromString({
entryPoint: Modules.CART,
fields: defaultStoreCartFields,
})
const [cart] = await remoteQuery(query, {
cart: { id: req.params.id },
})
// TODO: wrap result with totals when totals calculation is ready
res.status(200).json({ cart })
}
@@ -66,6 +66,7 @@ export const defaultStoreCartFields = [
"region.id",
"region.name",
"region.currency_code",
"region.automatic_taxes",
"sales_channel_id",
// TODO: To be updated when payment sessions are introduces in the Rest API
@@ -114,3 +114,5 @@ export class StorePostCartsCartReq {
// @Type(() => Discount)
// discounts?: Discount[]
}
export class StorePostCartsCartTaxesReq {}