diff --git a/packages/medusa/src/api/routes/admin/orders/request-return.js b/packages/medusa/src/api/routes/admin/orders/request-return.js index 1d3e0c0da0..d9038668f0 100644 --- a/packages/medusa/src/api/routes/admin/orders/request-return.js +++ b/packages/medusa/src/api/routes/admin/orders/request-return.js @@ -149,7 +149,7 @@ export default async (req, res) => { .withTransaction(manager) .retrieve(id) - const evaluatedNoNotification = value.no_notification !== undefined ? value.no_notification : order.no_notification + const evaluatedNoNotification = value.no_notification !== undefined && value.no_notification !== null ? value.no_notification : order.no_notification returnObj.no_notification = evaluatedNoNotification const createdReturn = await returnService diff --git a/packages/medusa/src/services/__tests__/claim.js b/packages/medusa/src/services/__tests__/claim.js index ceebac20ed..648b3ecb3b 100644 --- a/packages/medusa/src/services/__tests__/claim.js +++ b/packages/medusa/src/services/__tests__/claim.js @@ -215,9 +215,10 @@ describe("ClaimService", () => { it.each( [ [false, false], - [undefined, true] - ], - "passes correct no_notification status to event bus", async (input, expected) => { + [undefined, true], + [null, true], + ]) + ("passes correct no_notification status to event bus, with '%s'", async (input, expected) => { await claimService.create({ ...testClaim, no_notification: input, @@ -227,7 +228,6 @@ describe("ClaimService", () => { id: expect.any(String), no_notification: expected }) - }) }) diff --git a/packages/medusa/src/services/__tests__/order.js b/packages/medusa/src/services/__tests__/order.js index a9526a8245..a028318954 100644 --- a/packages/medusa/src/services/__tests__/order.js +++ b/packages/medusa/src/services/__tests__/order.js @@ -1134,7 +1134,8 @@ describe("OrderService", () => { it.each([ [false, false], [undefined, true], - ],"emits correct no_notification option", async (input, expected) => { + [null, true], + ])("emits correct no_notification option with '%s'", async (input, expected) => { await orderService.createRefund( IdMap.getId("order_123"), 100, diff --git a/packages/medusa/src/services/__tests__/swap.js b/packages/medusa/src/services/__tests__/swap.js index 4adb462748..3752bb2e64 100644 --- a/packages/medusa/src/services/__tests__/swap.js +++ b/packages/medusa/src/services/__tests__/swap.js @@ -345,7 +345,8 @@ describe("SwapService", () => { [true, true], [false, false], [undefined, true], - ])( "passes correct no_notification to eventBus with %s", async (input, expected) => { + [null, true], + ])( "passes correct no_notification to eventBus with '%s'", async (input, expected) => { await swapService.create( testOrder, diff --git a/packages/medusa/src/services/claim.js b/packages/medusa/src/services/claim.js index 7b13d6c561..88d119ac5e 100644 --- a/packages/medusa/src/services/claim.js +++ b/packages/medusa/src/services/claim.js @@ -101,7 +101,7 @@ class ClaimService extends BaseService { const claimRepo = manager.getCustomRepository(this.claimRepository_) const claim = await this.retrieve(id, { relations: ["shipping_methods"] }) - const { claim_items, shipping_methods, metadata } = data + const { claim_items, shipping_methods, metadata, no_notification } = data if (metadata) { claim.metadata = this.setMetadata_(claim, metadata) @@ -135,6 +135,11 @@ class ClaimService extends BaseService { } } + if(no_notification !== undefined || no_notification !== null){ + claim.no_notification = no_notification + await claimRepo.save(claim) + } + if (claim_items) { for (const i of claim_items) { if (i.id) { @@ -145,6 +150,7 @@ class ClaimService extends BaseService { } } + await this.eventBus_ .withTransaction(manager) .emit(ClaimService.Events.UPDATED, { @@ -235,7 +241,7 @@ class ClaimService extends BaseService { ) ) - const evaluatedNoNotification = no_notification !== undefined ? no_notification : order.no_notification + const evaluatedNoNotification = no_notification !== undefined && no_notification !== null ? no_notification : order.no_notification const created = claimRepo.create({ shipping_address_id: addressId, diff --git a/packages/medusa/src/services/notification.js b/packages/medusa/src/services/notification.js index e0165ef952..982f172e7b 100644 --- a/packages/medusa/src/services/notification.js +++ b/packages/medusa/src/services/notification.js @@ -164,6 +164,7 @@ class NotificationService extends BaseService { if (!subs) { return } + if(data['no_notification'] === true) { return } diff --git a/packages/medusa/src/services/order.js b/packages/medusa/src/services/order.js index b834bb634f..3b2192abc1 100644 --- a/packages/medusa/src/services/order.js +++ b/packages/medusa/src/services/order.js @@ -308,9 +308,12 @@ class OrderService extends BaseService { * @return {Promise} the order document */ async retrieve(orderId, config = {}) { + + const orderRepo = this.manager_.getCustomRepository(this.orderRepository_) const validatedId = this.validateId_(orderId) + const { select, relations, totalsToSelect } = this.transformQueryForTotals_( config ) @@ -330,7 +333,6 @@ class OrderService extends BaseService { const rels = query.relations delete query.relations const raw = await orderRepo.findOneWithRelations(rels, query) - if (!raw) { throw new MedusaError( MedusaError.Types.NOT_FOUND, @@ -983,7 +985,6 @@ class OrderService extends BaseService { "tax_total", "gift_card_total", "total", - "no_notification" ], relations: [ "discounts", @@ -1132,7 +1133,7 @@ class OrderService extends BaseService { const result = await this.retrieve(orderId) - const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification + const evaluatedNoNotification = noNotification !== undefined && noNotification !== null ? noNotification : order.no_notification this.eventBus_.emit(OrderService.Events.REFUND_CREATED, { id: result.id, diff --git a/packages/medusa/src/services/swap.js b/packages/medusa/src/services/swap.js index 5eb222ec82..8a33421d9f 100644 --- a/packages/medusa/src/services/swap.js +++ b/packages/medusa/src/services/swap.js @@ -238,7 +238,7 @@ class SwapService extends BaseService { }) ) - const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification + const evaluatedNoNotification = noNotification !== undefined && noNotification !== null ? noNotification : order.no_notification const swapRepo = manager.getCustomRepository(this.swapRepository_) const created = swapRepo.create({ @@ -363,6 +363,10 @@ class SwapService extends BaseService { swap.metadata = this.setMetadata_(swap, update.metadata) } + if("no_notification" in update){ + swap.no_notification = update.no_notification + } + if ("shipping_address" in update) { await this.updateShippingAddress_(swap, update.shipping_address) }