feat(medusa): Continue create product workflow changes (#4473)
This commit is contained in:
1 parent
edf93d972d
commit
d2a8cf0378
103 files changed
+1859
-524
No files matched your search
@@ -67,7 +67,7 @@ export const defaultAdminCollectionsFields = [
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
export const defaultAdminCollectionsRelations = ["products"]
|
||||
export const defaultAdminCollectionsRelations = ["products.profiles"]
|
||||
|
||||
/**
|
||||
* @schema AdminCollectionsListRes
|
||||
|
||||
@@ -48,7 +48,7 @@ describe("POST /admin/discounts/:discount_id/regions/:region_id", () => {
|
||||
"metadata",
|
||||
"valid_duration",
|
||||
],
|
||||
relations: ["rule", "parent_discount", "regions", "rule.conditions"],
|
||||
relations: ["parent_discount", "regions", "rule.conditions"],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -20,12 +20,7 @@ const defaultFields = [
|
||||
"valid_duration",
|
||||
]
|
||||
|
||||
const defaultRelations = [
|
||||
"rule",
|
||||
"parent_discount",
|
||||
"regions",
|
||||
"rule.conditions",
|
||||
]
|
||||
const defaultRelations = ["parent_discount", "regions", "rule.conditions"]
|
||||
|
||||
describe("GET /admin/discounts/:discount_id", () => {
|
||||
describe("successful retrieval", () => {
|
||||
|
||||
@@ -20,12 +20,7 @@ const defaultFields = [
|
||||
"valid_duration",
|
||||
]
|
||||
|
||||
const defaultRelations = [
|
||||
"rule",
|
||||
"parent_discount",
|
||||
"regions",
|
||||
"rule.conditions",
|
||||
]
|
||||
const defaultRelations = ["parent_discount", "regions", "rule.conditions"]
|
||||
|
||||
describe("DELETE /admin/discounts/:discount_id/regions/region_id", () => {
|
||||
describe("successful removal", () => {
|
||||
|
||||
@@ -209,7 +209,6 @@ export const defaultAdminDiscountsFields: (keyof Discount)[] = [
|
||||
]
|
||||
|
||||
export const defaultAdminDiscountsRelations = [
|
||||
"rule",
|
||||
"parent_discount",
|
||||
"regions",
|
||||
"rule.conditions",
|
||||
|
||||
@@ -139,6 +139,7 @@ export type AdminPostDraftOrdersDraftOrderRegisterPaymentRes = {
|
||||
* - cart.items.tax_lines
|
||||
* - cart.items.variant
|
||||
* - cart.items.variant.product
|
||||
* - cart.items.variant.product.profiles
|
||||
* - cart.region
|
||||
* - cart.region.tax_rates
|
||||
* - cart.shipping_address
|
||||
|
||||
@@ -543,6 +543,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
||||
* - items.tax_lines
|
||||
* - items.variant
|
||||
* - items.variant.product
|
||||
* - items.variant.product.profiles
|
||||
* - refunds
|
||||
* - region
|
||||
* - shipping_methods
|
||||
@@ -659,6 +660,7 @@ export type AdminOrdersRes = {
|
||||
* - items.tax_lines
|
||||
* - items.variant
|
||||
* - items.variant.product
|
||||
* - items.variant.product.profiles
|
||||
* - refunds
|
||||
* - region
|
||||
* - shipping_methods
|
||||
|
||||
@@ -40,7 +40,6 @@ describe("GET /admin/products/:id", () => {
|
||||
"is_giftcard",
|
||||
"discountable",
|
||||
"thumbnail",
|
||||
"profile_id",
|
||||
"collection_id",
|
||||
"type_id",
|
||||
"weight",
|
||||
@@ -60,6 +59,7 @@ describe("GET /admin/products/:id", () => {
|
||||
"variants",
|
||||
"variants.prices",
|
||||
"variants.options",
|
||||
"profiles",
|
||||
"images",
|
||||
"options",
|
||||
"tags",
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
createVariantsTransaction,
|
||||
revertVariantTransaction,
|
||||
} from "./transaction/create-product-variant"
|
||||
import { createProductsWorkflow } from "../../../../workflows/admin/create-products"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/products
|
||||
@@ -129,6 +130,19 @@ export default async (req, res) => {
|
||||
)
|
||||
|
||||
const entityManager: EntityManager = req.scope.resolve("manager")
|
||||
const productModuleService = req.scope.resolve("productModuleService")
|
||||
|
||||
if (productModuleService) {
|
||||
const products = await createProductsWorkflow(
|
||||
{
|
||||
container: req.scope,
|
||||
manager: entityManager,
|
||||
},
|
||||
[validated]
|
||||
)
|
||||
|
||||
return res.json({ product: products[0] })
|
||||
}
|
||||
|
||||
const product = await entityManager.transaction(async (manager) => {
|
||||
const { variants } = validated
|
||||
|
||||
@@ -101,6 +101,7 @@ export const defaultAdminProductRelations = [
|
||||
"variants",
|
||||
"variants.prices",
|
||||
"variants.options",
|
||||
"profiles",
|
||||
"images",
|
||||
"options",
|
||||
"tags",
|
||||
@@ -119,7 +120,6 @@ export const defaultAdminProductFields: (keyof Product)[] = [
|
||||
"is_giftcard",
|
||||
"discountable",
|
||||
"thumbnail",
|
||||
"profile_id",
|
||||
"collection_id",
|
||||
"type_id",
|
||||
"weight",
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ const defaultFields = [
|
||||
"metadata",
|
||||
]
|
||||
|
||||
const defaultRelations = ["products", "shipping_options"]
|
||||
const defaultRelations = ["products.profiles", "shipping_options"]
|
||||
|
||||
describe("GET /admin/shipping-profiles/:profile_id", () => {
|
||||
describe("successful retrieval", () => {
|
||||
|
||||
@@ -41,8 +41,10 @@ export const defaultAdminShippingProfilesFields: (keyof ShippingProfile)[] = [
|
||||
"metadata",
|
||||
]
|
||||
|
||||
export const defaultAdminShippingProfilesRelations: (keyof ShippingProfile)[] =
|
||||
["products", "shipping_options"]
|
||||
export const defaultAdminShippingProfilesRelations: string[] = [
|
||||
"products.profiles",
|
||||
"shipping_options",
|
||||
]
|
||||
|
||||
/**
|
||||
* @schema AdminDeleteShippingProfileRes
|
||||
|
||||
@@ -262,6 +262,7 @@ export const defaultStoreCartRelations = [
|
||||
* - items
|
||||
* - items.variant
|
||||
* - items.variant.product
|
||||
* - items.variant.product.profiles
|
||||
* - items.tax_lines
|
||||
* - items.adjustments
|
||||
* - gift_cards
|
||||
|
||||
@@ -181,6 +181,7 @@ export type StoreCustomersResetPasswordRes = {
|
||||
* - items.tax_lines
|
||||
* - items.variant
|
||||
* - items.variant.product
|
||||
* - items.variant.product.profiles
|
||||
* - refunds
|
||||
* - region
|
||||
* - shipping_address
|
||||
|
||||
@@ -168,6 +168,7 @@ export const allowedStoreOrdersFields = [
|
||||
* - items.tax_lines
|
||||
* - items.variant
|
||||
* - items.variant.product
|
||||
* - items.variant.product.profiles
|
||||
* - refunds
|
||||
* - region
|
||||
* - shipping_methods
|
||||
|
||||
@@ -65,6 +65,7 @@ export const defaultStoreProductsRelations = [
|
||||
"tags",
|
||||
"collection",
|
||||
"type",
|
||||
"profiles",
|
||||
]
|
||||
|
||||
export const defaultStoreProductsFields: (keyof Product)[] = [
|
||||
@@ -78,7 +79,6 @@ export const defaultStoreProductsFields: (keyof Product)[] = [
|
||||
"is_giftcard",
|
||||
"discountable",
|
||||
"thumbnail",
|
||||
"profile_id",
|
||||
"collection_id",
|
||||
"type_id",
|
||||
"weight",
|
||||
@@ -97,7 +97,10 @@ export const defaultStoreProductsFields: (keyof Product)[] = [
|
||||
|
||||
export const allowedStoreProductsFields = [
|
||||
...defaultStoreProductsFields,
|
||||
// TODO: order prop validation
|
||||
// profile_id is not a column in the products table, so it should be ignored as it
|
||||
// will be rejected by typeorm as invalid, though, it is an entity property
|
||||
// that we want to return, so it part of the allowedStoreProductsFields
|
||||
"profile_id",
|
||||
"variants.title",
|
||||
"variants.prices.amount",
|
||||
]
|
||||
|
||||
+1
-4
@@ -21,10 +21,7 @@ describe("GET /store/shipping-options", () => {
|
||||
it("calls CartService retrieve", () => {
|
||||
expect(CartServiceMock.retrieveWithTotals).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.retrieveWithTotals).toHaveBeenCalledWith(
|
||||
IdMap.getId("emptyCart"),
|
||||
{
|
||||
relations: ["items.variant", "items.variant.product"],
|
||||
}
|
||||
IdMap.getId("emptyCart")
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -53,12 +53,8 @@ export default async (req, res) => {
|
||||
"shippingProfileService"
|
||||
)
|
||||
|
||||
const cart = await cartService.retrieveWithTotals(cart_id, {
|
||||
relations: ["items.variant", "items.variant.product"],
|
||||
})
|
||||
|
||||
const cart = await cartService.retrieveWithTotals(cart_id)
|
||||
const options = await shippingProfileService.fetchCartOptions(cart)
|
||||
|
||||
const data = await pricingService.setShippingOptionPrices(options, {
|
||||
cart_id,
|
||||
})
|
||||
|
||||
@@ -139,13 +139,9 @@ export default async (req, res) => {
|
||||
.retrieve(swapDto.order_id, {
|
||||
select: ["refunded_total", "total"],
|
||||
relations: [
|
||||
"items",
|
||||
"items.variant",
|
||||
"items.tax_lines",
|
||||
"swaps",
|
||||
"swaps.additional_items",
|
||||
"swaps.additional_items.variant",
|
||||
"swaps.additional_items.variant.product",
|
||||
"swaps.additional_items.variant.product.profiles",
|
||||
"swaps.additional_items.tax_lines",
|
||||
],
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user