feat: Update the product options model and refactor the product module (#6685)
The changes in this PR are: 1. Change how product options are created and stored. The relationship changed from `options --> option values <-- variants` to `options --> option values --> variant options <-- variants` Now we can enforce non-duplicate option values, easier creation and updates of options, and more. 2. Refactors the product module. The product module did a lot of things in a non-ideal approach, and this is a step towards a more consistent usage of the base repository and methods exposed by a module. There is still work left to improve the module, but a large chunk of the changes are included in this PR Things to do as a follow-up: 1. Remove many-to-many relationships if an empty list is passed in the base repository. 2. Improve the typings of the module 3. Further cleanup and improvements (there are few questions that I need answered before I can improve the API)
This commit is contained in:
@@ -17,7 +17,6 @@ export const GET = async (
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||
|
||||
// TODO: Should we allow fetching a option without knowing the product ID? In such case we'll need to change the route to /admin/products/options/:id
|
||||
const productId = req.params.id
|
||||
const optionId = req.params.option_id
|
||||
|
||||
@@ -37,7 +36,6 @@ export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<UpdateProductOptionDTO>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
// TODO: Should we allow fetching a option without knowing the product ID? In such case we'll need to change the route to /admin/products/options/:id
|
||||
const productId = req.params.id
|
||||
const optionId = req.params.option_id
|
||||
|
||||
@@ -60,7 +58,6 @@ export const DELETE = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
// TODO: Should we allow fetching a option without knowing the product ID? In such case we'll need to change the route to /admin/products/options/:id
|
||||
const productId = req.params.id
|
||||
const optionId = req.params.option_id
|
||||
|
||||
|
||||
@@ -22,7 +22,9 @@ export const defaultAdminProductsVariantFields = [
|
||||
"ean",
|
||||
"upc",
|
||||
"barcode",
|
||||
"options",
|
||||
"options.id",
|
||||
"options.option_value.value",
|
||||
"options.option_value.option.title",
|
||||
]
|
||||
|
||||
export const retrieveVariantConfig = {
|
||||
@@ -57,15 +59,12 @@ export const allowedAdminProductRelations = [
|
||||
"variants",
|
||||
// TODO: Add in next iteration
|
||||
// "variants.prices",
|
||||
// TODO: See how this should be handled
|
||||
// "variants.options",
|
||||
"variants.options",
|
||||
"images",
|
||||
// TODO: What is this?
|
||||
// "profiles",
|
||||
"options",
|
||||
// TODO: See how this should be handled
|
||||
// "options.values",
|
||||
// TODO: Handle in next iteration
|
||||
"options.values",
|
||||
"tags",
|
||||
"type",
|
||||
"collection",
|
||||
@@ -121,6 +120,14 @@ export const defaultAdminProductFields = [
|
||||
"collection.handle",
|
||||
"collection.created_at",
|
||||
"collection.updated_at",
|
||||
"options.id",
|
||||
"options.product_id",
|
||||
"options.title",
|
||||
"options.values.id",
|
||||
"options.values.value",
|
||||
"options.created_at",
|
||||
"options.updated_at",
|
||||
"options.deleted_at",
|
||||
"tags.id",
|
||||
"tags.value",
|
||||
"tags.created_at",
|
||||
|
||||
Reference in New Issue
Block a user