feat(medusa): Middleware to add default SC on query if no SC already exist on it (#3694)

This commit is contained in:
Rares Stefan
2023-04-26 17:23:29 +02:00
committed by GitHub
parent d97a6f3321
commit 3a77e8a88f
7 changed files with 107 additions and 35 deletions

View File

@@ -13,7 +13,7 @@ const {
ShippingProfileType,
} = require("@medusajs/medusa")
module.exports = async (dataSource, data = {}) => {
module.exports = async (dataSource, defaultSalesChannel) => {
const manager = dataSource.manager
const yesterday = ((today) => new Date(today.setDate(today.getDate() - 1)))(
@@ -138,6 +138,7 @@ module.exports = async (dataSource, data = {}) => {
{ id: "tag1", value: "123" },
{ tag: "tag2", value: "456" },
],
sales_channels: defaultSalesChannel ? [defaultSalesChannel] : [],
})
p.images = [image]
@@ -270,6 +271,7 @@ module.exports = async (dataSource, data = {}) => {
{ id: "tag1", value: "123" },
{ tag: "tag2", value: "456" },
],
sales_channels: defaultSalesChannel ? [defaultSalesChannel] : [],
})
await manager.save(p1)
@@ -326,6 +328,7 @@ module.exports = async (dataSource, data = {}) => {
collection_id: "test-collection1",
status: "published",
tags: [{ id: "tag3", value: "123" }],
sales_channels: defaultSalesChannel ? [defaultSalesChannel] : [],
})
await manager.save(product1)
@@ -340,6 +343,7 @@ module.exports = async (dataSource, data = {}) => {
collection_id: "test-collection2",
status: "published",
tags: [{ id: "tag4", value: "1234" }],
sales_channels: defaultSalesChannel ? [defaultSalesChannel] : [],
})
await manager.save(product2)
@@ -354,6 +358,7 @@ module.exports = async (dataSource, data = {}) => {
collection_id: "test-collection1",
status: "draft",
tags: [{ id: "tag4", value: "1234" }],
sales_channels: defaultSalesChannel ? [defaultSalesChannel] : [],
})
await manager.save(product3)
@@ -367,6 +372,7 @@ module.exports = async (dataSource, data = {}) => {
description: "test-product-description",
type: { id: "test-type", value: "test-type" },
status: "published",
sales_channels: defaultSalesChannel ? [defaultSalesChannel] : [],
})
await manager.save(gift_card)