Merge pull request #293 from medusajs/feat/disabling-of-notification
Feat/disabling of notification
This commit is contained in:
@@ -63,6 +63,9 @@ import { defaultFields, defaultRelations } from "."
|
||||
* customer_id:
|
||||
* description: The id of the customer to add on the draft order
|
||||
* type: string
|
||||
* no_notification_order:
|
||||
* description: An optional flag passed to the resulting order to determine use of notifications.
|
||||
* type: boolean
|
||||
* shipping_methods:
|
||||
* description: The shipping methods for the draft order
|
||||
* type: array
|
||||
@@ -123,6 +126,7 @@ export default async (req, res) => {
|
||||
})
|
||||
.optional(),
|
||||
customer_id: Validator.string().optional(),
|
||||
no_notification_order: Validator.boolean().optional(),
|
||||
shipping_methods: Validator.array()
|
||||
.items({
|
||||
option_id: Validator.string().required(),
|
||||
|
||||
@@ -78,6 +78,7 @@ export const defaultFields = [
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"metadata",
|
||||
"no_notification_order",
|
||||
]
|
||||
|
||||
export const allowedFields = [
|
||||
@@ -89,6 +90,7 @@ export const allowedFields = [
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"metadata",
|
||||
"no_notification_order",
|
||||
]
|
||||
|
||||
export const allowedRelations = ["cart"]
|
||||
|
||||
@@ -35,6 +35,9 @@ import { defaultCartFields, defaultCartRelations, defaultFields } from "."
|
||||
* code:
|
||||
* description: "The code that a Discount is identifed by."
|
||||
* type: string
|
||||
* no_notification_order:
|
||||
* description: "An optional flag passed to the resulting order to determine use of notifications."
|
||||
* type: boolean
|
||||
* customer_id:
|
||||
* description: "The id of the Customer to associate the Draft Order with."
|
||||
* type: string
|
||||
@@ -68,6 +71,7 @@ export default async (req, res) => {
|
||||
})
|
||||
.optional(),
|
||||
customer_id: Validator.string().optional(),
|
||||
no_notification_order: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -88,6 +92,13 @@ export default async (req, res) => {
|
||||
)
|
||||
}
|
||||
|
||||
if ("no_notification_order" in value) {
|
||||
await draftOrderService.update(draftOrder.id, {
|
||||
no_notification_order: value.no_notification_order,
|
||||
})
|
||||
delete value.no_notification_order
|
||||
}
|
||||
|
||||
await cartService.update(draftOrder.cart_id, value)
|
||||
|
||||
draftOrder.cart = await cartService.retrieve(draftOrder.cart_id, {
|
||||
|
||||
@@ -42,7 +42,7 @@ describe("POST /admin/orders/:id/fulfillment", () => {
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
undefined
|
||||
{ metadata: undefined, no_notification: undefined }
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ const defaultFields = [
|
||||
"total",
|
||||
"paid_total",
|
||||
"refundable_amount",
|
||||
"no_notification",
|
||||
]
|
||||
|
||||
describe("GET /admin/orders", () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { orders } from "../../../../../services/__mocks__/order"
|
||||
import { ReturnService } from "../../../../../services/__mocks__/return"
|
||||
import { EventBusServiceMock } from "../../../../../services/__mocks__/event-bus"
|
||||
|
||||
describe("POST /admin/orders/:id/return", () => {
|
||||
describe("successfully returns full order", () => {
|
||||
@@ -21,6 +21,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
},
|
||||
],
|
||||
refund: 10,
|
||||
no_notification: true,
|
||||
},
|
||||
adminSession: {
|
||||
jwt: {
|
||||
@@ -47,6 +48,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
},
|
||||
],
|
||||
refund_amount: 10,
|
||||
no_notification: true,
|
||||
shipping_method: undefined,
|
||||
})
|
||||
})
|
||||
@@ -69,6 +71,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
},
|
||||
],
|
||||
refund: -1,
|
||||
no_notification: true,
|
||||
},
|
||||
adminSession: {
|
||||
jwt: {
|
||||
@@ -95,6 +98,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
},
|
||||
],
|
||||
refund_amount: 0,
|
||||
no_notification: true,
|
||||
shipping_method: undefined,
|
||||
})
|
||||
})
|
||||
@@ -118,6 +122,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
],
|
||||
refund: -1,
|
||||
},
|
||||
no_notification: true,
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
@@ -143,6 +148,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
},
|
||||
],
|
||||
refund_amount: 0,
|
||||
no_notification: true,
|
||||
shipping_method: undefined,
|
||||
})
|
||||
})
|
||||
@@ -165,6 +171,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
},
|
||||
],
|
||||
refund: 100,
|
||||
no_notification: true,
|
||||
return_shipping: {
|
||||
option_id: "opt_1234",
|
||||
price: 12,
|
||||
@@ -195,6 +202,7 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
},
|
||||
],
|
||||
refund_amount: 100,
|
||||
no_notification: true,
|
||||
shipping_method: {
|
||||
option_id: "opt_1234",
|
||||
price: 12,
|
||||
@@ -205,4 +213,82 @@ describe("POST /admin/orders/:id/return", () => {
|
||||
expect(ReturnService.fulfill).toHaveBeenCalledWith("return")
|
||||
})
|
||||
})
|
||||
|
||||
describe("the api call overrides notification settings of order", () => {
|
||||
it("eventBus is called with the proper no notification feature", async () => {
|
||||
jest.clearAllMocks()
|
||||
const subject = await request(
|
||||
"POST",
|
||||
`/admin/orders/${IdMap.getId("test-order")}/return`,
|
||||
{
|
||||
payload: {
|
||||
items: [
|
||||
{
|
||||
item_id: IdMap.getId("existingLine"),
|
||||
quantity: 10,
|
||||
},
|
||||
],
|
||||
refund: 100,
|
||||
return_shipping: {
|
||||
option_id: "opt_1234",
|
||||
price: 12,
|
||||
},
|
||||
no_notification: false,
|
||||
},
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
expect(EventBusServiceMock.emit).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
{
|
||||
id: expect.any(String),
|
||||
no_notification: false,
|
||||
return_id: expect.any(String),
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("the api call inherits notification settings of order", () => {
|
||||
it("eventBus is called with the proper no notification feature", async () => {
|
||||
jest.clearAllMocks()
|
||||
await request(
|
||||
"POST",
|
||||
`/admin/orders/${IdMap.getId("test-order")}/return`,
|
||||
{
|
||||
payload: {
|
||||
items: [
|
||||
{
|
||||
item_id: IdMap.getId("existingLine"),
|
||||
quantity: 10,
|
||||
},
|
||||
],
|
||||
refund: 100,
|
||||
return_shipping: {
|
||||
option_id: "opt_1234",
|
||||
price: 12,
|
||||
},
|
||||
},
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(EventBusServiceMock.emit).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
{
|
||||
id: expect.any(String),
|
||||
no_notification: true,
|
||||
return_id: expect.any(String),
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -91,6 +91,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* refund_amount:
|
||||
* description: The amount to refund the Customer when the Claim type is `refund`.
|
||||
* type: integer
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Claim.
|
||||
* type: boolean
|
||||
* metadata:
|
||||
* description: An optional set of key-value pairs to hold additional information.
|
||||
* type: object
|
||||
@@ -108,7 +111,6 @@ import { defaultRelations, defaultFields } from "./"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
type: Validator.string()
|
||||
.valid("replace", "refund")
|
||||
@@ -155,6 +157,7 @@ export default async (req, res) => {
|
||||
.integer()
|
||||
.optional(),
|
||||
shipping_address: Validator.object().optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
@@ -162,7 +165,6 @@ export default async (req, res) => {
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
const idempotencyKeyService = req.scope.resolve("idempotencyKeyService")
|
||||
|
||||
const headerKey = req.get("Idempotency-Key") || ""
|
||||
@@ -212,6 +214,7 @@ export default async (req, res) => {
|
||||
return_shipping: value.return_shipping,
|
||||
additional_items: value.additional_items,
|
||||
shipping_methods: value.shipping_methods,
|
||||
no_notification: value.no_notification,
|
||||
metadata: value.metadata,
|
||||
})
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* quantity:
|
||||
* description: The quantity of the Line Item to fulfill.
|
||||
* type: integer
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Swap.
|
||||
* type: boolean
|
||||
* metadata:
|
||||
* description: An optional set of key-value pairs to hold additional information.
|
||||
* type: object
|
||||
@@ -49,6 +52,7 @@ export default async (req, res) => {
|
||||
quantity: Validator.number().required(),
|
||||
})
|
||||
.required(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
@@ -60,7 +64,10 @@ export default async (req, res) => {
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.createFulfillment(id, value.items, value.metadata)
|
||||
await orderService.createFulfillment(id, value.items, {
|
||||
metadata: value.metadata,
|
||||
no_notification: value.no_notification,
|
||||
})
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
|
||||
@@ -27,6 +27,7 @@ export default async (req, res) => {
|
||||
items: Validator.array().optional(),
|
||||
})
|
||||
.required(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Shipment.
|
||||
* type: boolean
|
||||
* tags:
|
||||
* - Order
|
||||
* responses:
|
||||
@@ -41,6 +44,7 @@ export default async (req, res) => {
|
||||
tracking_numbers: Validator.array()
|
||||
.items(Validator.string())
|
||||
.optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -54,7 +58,8 @@ export default async (req, res) => {
|
||||
await orderService.createShipment(
|
||||
id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n }))
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n })),
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -22,6 +22,9 @@ import { defaultFields, defaultRelations } from "./"
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Claim.
|
||||
* type: boolean
|
||||
* tags:
|
||||
* - Order
|
||||
* responses:
|
||||
@@ -42,6 +45,7 @@ export default async (req, res) => {
|
||||
tracking_numbers: Validator.array()
|
||||
.items(Validator.string())
|
||||
.optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -56,7 +60,8 @@ export default async (req, res) => {
|
||||
await swapService.createShipment(
|
||||
swap_id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n }))
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n })),
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -45,6 +45,9 @@ import { defaultFields, defaultRelations } from "./"
|
||||
* quantity:
|
||||
* description: The quantity of the Product Variant to ship.
|
||||
* type: integer
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Swap.
|
||||
* type: boolean
|
||||
* tags:
|
||||
* - Order
|
||||
* responses:
|
||||
@@ -79,6 +82,7 @@ export default async (req, res) => {
|
||||
variant_id: Validator.string().required(),
|
||||
quantity: Validator.number().required(),
|
||||
}),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -134,7 +138,10 @@ export default async (req, res) => {
|
||||
value.return_items,
|
||||
value.additional_items,
|
||||
value.return_shipping,
|
||||
{ idempotency_key: idempotencyKey.idempotency_key }
|
||||
{
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
no_notification: value.no_notification,
|
||||
}
|
||||
)
|
||||
|
||||
await swapService.withTransaction(manager).createCart(swap.id)
|
||||
|
||||
@@ -17,6 +17,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* metadata:
|
||||
* description: An optional set of key-value pairs to hold additional information.
|
||||
* type: object
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Claim.
|
||||
* type: boolean
|
||||
* tags:
|
||||
* - Order
|
||||
* responses:
|
||||
@@ -34,6 +37,7 @@ export default async (req, res) => {
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
metadata: Validator.object().optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -47,9 +51,10 @@ export default async (req, res) => {
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await claimService
|
||||
.withTransaction(manager)
|
||||
.createFulfillment(claim_id, value.metadata)
|
||||
await claimService.withTransaction(manager).createFulfillment(claim_id, {
|
||||
metadata: value.metadata,
|
||||
no_notification: value.no_notification,
|
||||
})
|
||||
})
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -17,6 +17,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* metadata:
|
||||
* description: An optional set of key-value pairs to hold additional information.
|
||||
* type: object
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Claim.
|
||||
* type: boolean
|
||||
* tags:
|
||||
* - Order
|
||||
* responses:
|
||||
@@ -34,6 +37,7 @@ export default async (req, res) => {
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
metadata: Validator.object().optional(),
|
||||
no_notification: Validator.boolean().optional,
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -47,9 +51,10 @@ export default async (req, res) => {
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await swapService
|
||||
.withTransaction(manager)
|
||||
.createFulfillment(swap_id, value.metadata)
|
||||
await swapService.withTransaction(manager).createFulfillment(swap_id, {
|
||||
metadata: value.metadata,
|
||||
no_notification: value.no_notification,
|
||||
})
|
||||
|
||||
const order = await orderService.withTransaction(manager).retrieve(id, {
|
||||
select: defaultFields,
|
||||
|
||||
@@ -237,6 +237,7 @@ export const defaultFields = [
|
||||
"total",
|
||||
"paid_total",
|
||||
"refundable_amount",
|
||||
"no_notification",
|
||||
]
|
||||
|
||||
export const allowedFields = [
|
||||
@@ -265,6 +266,7 @@ export const allowedFields = [
|
||||
"total",
|
||||
"paid_total",
|
||||
"refundable_amount",
|
||||
"no_notification",
|
||||
]
|
||||
|
||||
export const allowedRelations = [
|
||||
|
||||
@@ -25,6 +25,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* note:
|
||||
* description: A not with additional details about the Refund.
|
||||
* type: string
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Refund.
|
||||
* type: boolean
|
||||
* tags:
|
||||
* - Order
|
||||
* responses:
|
||||
@@ -47,9 +50,11 @@ export default async (req, res) => {
|
||||
note: Validator.string()
|
||||
.allow("")
|
||||
.optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
@@ -57,7 +62,13 @@ export default async (req, res) => {
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.createRefund(id, value.amount, value.reason, value.note)
|
||||
await orderService.createRefund(
|
||||
id,
|
||||
value.amount,
|
||||
value.reason,
|
||||
value.note,
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
|
||||
@@ -43,6 +43,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* receive_now:
|
||||
* description: A flag to indicate if the Return should be registerd as received immediately.
|
||||
* type: boolean
|
||||
* no_notification:
|
||||
* description: A flag to indicate if no notifications should be emitted related to the requested Return.
|
||||
* type: boolean
|
||||
* refund:
|
||||
* description: The amount to refund.
|
||||
* type: integer
|
||||
@@ -79,6 +82,7 @@ export default async (req, res) => {
|
||||
})
|
||||
.optional(),
|
||||
receive_now: Validator.boolean().default(false),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
refund: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
@@ -141,6 +145,13 @@ export default async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
let order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id)
|
||||
|
||||
const evaluatedNoNotification = value.no_notification !== undefined ? value.no_notification : order.no_notification
|
||||
returnObj.no_notification = evaluatedNoNotification
|
||||
|
||||
const createdReturn = await returnService
|
||||
.withTransaction(manager)
|
||||
.create(returnObj)
|
||||
@@ -150,12 +161,13 @@ export default async (req, res) => {
|
||||
.withTransaction(manager)
|
||||
.fulfill(createdReturn.id)
|
||||
}
|
||||
|
||||
|
||||
await eventBus
|
||||
.withTransaction(manager)
|
||||
.emit("order.return_requested", {
|
||||
id,
|
||||
return_id: createdReturn.id,
|
||||
no_notification: evaluatedNoNotification
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -62,6 +62,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* price:
|
||||
* description: The price to charge for the Shipping Method
|
||||
* type: integer
|
||||
* no_notification:
|
||||
* description: If set to true no notification will be send related to this Swap.
|
||||
* type: boolean
|
||||
* metadata:
|
||||
* description: An optional set of key-value pairs to hold additional information.
|
||||
* type: object
|
||||
@@ -106,6 +109,7 @@ export default async (req, res) => {
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ export default async (req, res) => {
|
||||
data: Validator.object(),
|
||||
items: Validator.array(),
|
||||
}),
|
||||
no_notification: Validator.boolean(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
|
||||
@@ -54,6 +54,7 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user