snake_cased noNotification and other minor changes
This commit is contained in:
@@ -155,7 +155,7 @@ export default async (req, res) => {
|
||||
draftOrder = await draftOrderService.retrieve(draftOrder.id, {
|
||||
relations: defaultRelations,
|
||||
select: defaultFields,
|
||||
}) //
|
||||
})
|
||||
|
||||
res.status(200).json({ draft_order: draftOrder })
|
||||
} catch (err) {
|
||||
|
||||
@@ -92,7 +92,12 @@ export default async (req, res) => {
|
||||
)
|
||||
}
|
||||
|
||||
await draftOrderService.update(draftOrder.id, value)
|
||||
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)
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ export default (app, container, config) => {
|
||||
returnRoutes(route)
|
||||
variantRoutes(route)
|
||||
draftOrderRoutes(route)
|
||||
collectionRoutes(route)
|
||||
collectionRoutes(route)
|
||||
notificationRoutes(route)
|
||||
returnReasonRoutes(route)
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("POST /admin/orders/:id/fulfillment", () => {
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
{"metadata": undefined, "noNotification": undefined}
|
||||
{ metadata: undefined, no_notification: undefined }
|
||||
)
|
||||
})
|
||||
|
||||
@@ -52,6 +52,5 @@ describe("POST /admin/orders/:id/fulfillment", () => {
|
||||
expect(subject.body.order.id).toEqual(IdMap.getId("test-order"))
|
||||
expect(subject.body.order.fulfillment_status).toEqual("fulfilled")
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
@@ -110,8 +110,7 @@ import { defaultRelations, defaultFields } from "./"
|
||||
* $ref: "#/components/schemas/order"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const { id } = req.params
|
||||
const schema = Validator.object().keys({
|
||||
type: Validator.string()
|
||||
.valid("replace", "refund")
|
||||
@@ -165,8 +164,7 @@ export default async (req, res) => {
|
||||
const { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
}
|
||||
const idempotencyKeyService = req.scope.resolve("idempotencyKeyService")
|
||||
|
||||
const headerKey = req.get("Idempotency-Key") || ""
|
||||
|
||||
@@ -65,8 +65,8 @@ export default async (req, res) => {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.createFulfillment(id, value.items, {
|
||||
metadata: value.metadata,
|
||||
noNotification: value.no_notification
|
||||
metadata: value.metadata,
|
||||
no_notification: value.no_notification,
|
||||
})
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -59,7 +59,7 @@ export default async (req, res) => {
|
||||
id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n })),
|
||||
{ noNotification: value.no_notification }
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -61,7 +61,7 @@ export default async (req, res) => {
|
||||
swap_id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n })),
|
||||
{noNotification: value.no_notification},
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -68,7 +68,7 @@ export default async (req, res) => {
|
||||
.items({
|
||||
item_id: Validator.string().required(),
|
||||
quantity: Validator.number().required(),
|
||||
})
|
||||
})
|
||||
.required(),
|
||||
return_shipping: Validator.object()
|
||||
.keys({
|
||||
@@ -82,7 +82,7 @@ export default async (req, res) => {
|
||||
variant_id: Validator.string().required(),
|
||||
quantity: Validator.number().required(),
|
||||
}),
|
||||
no_notification: Validator.boolean().optional()
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -138,7 +138,10 @@ export default async (req, res) => {
|
||||
value.return_items,
|
||||
value.additional_items,
|
||||
value.return_shipping,
|
||||
{ idempotency_key: idempotencyKey.idempotency_key, noNotification: value.no_notification }
|
||||
{
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
no_notification: value.no_notification,
|
||||
}
|
||||
)
|
||||
|
||||
await swapService.withTransaction(manager).createCart(swap.id)
|
||||
|
||||
@@ -51,12 +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, {
|
||||
metadata: value.metadata,
|
||||
noNotification: value.no_notification,
|
||||
})
|
||||
await claimService.withTransaction(manager).createFulfillment(claim_id, {
|
||||
metadata: value.metadata,
|
||||
no_notification: value.no_notification,
|
||||
})
|
||||
})
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -51,12 +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, {
|
||||
metadata: value.metadata,
|
||||
noNotification: value.no_notification,
|
||||
})
|
||||
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,
|
||||
|
||||
@@ -67,7 +67,7 @@ export default async (req, res) => {
|
||||
value.amount,
|
||||
value.reason,
|
||||
value.note,
|
||||
{ noNotification: value.no_notification }
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
|
||||
@@ -31,7 +31,6 @@ import { MedusaError, Validator } from "medusa-core-utils"
|
||||
* option_id:
|
||||
* type: string
|
||||
* description: The id of the Shipping Option to create the Shipping Method from.
|
||||
*
|
||||
* tags:
|
||||
* - Return
|
||||
* responses:
|
||||
@@ -59,7 +58,7 @@ export default async (req, res) => {
|
||||
.keys({
|
||||
option_id: Validator.string().optional(),
|
||||
})
|
||||
.optional()
|
||||
.optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -132,7 +131,7 @@ export default async (req, res) => {
|
||||
.withTransaction(manager)
|
||||
.emit("order.return_requested", {
|
||||
id: value.order_id,
|
||||
return_id: createdReturn.id
|
||||
return_id: createdReturn.id,
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -442,7 +442,7 @@ describe("ClaimService", () => {
|
||||
metadata: {
|
||||
meta: "data",
|
||||
},
|
||||
noNotification: false,
|
||||
no_notification: false,
|
||||
})
|
||||
|
||||
expect(withTransactionMock).toHaveBeenCalledTimes(3)
|
||||
@@ -458,7 +458,7 @@ describe("ClaimService", () => {
|
||||
metadata: {
|
||||
meta: "data",
|
||||
},
|
||||
noNotification: false,
|
||||
no_notification: false,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -877,7 +877,7 @@ describe("OrderService", () => {
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
{ noNotification: input }
|
||||
{ no_notification: input }
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String), {
|
||||
@@ -1073,7 +1073,7 @@ describe("OrderService", () => {
|
||||
).toHaveBeenCalledWith(
|
||||
IdMap.getId("fulfillment"),
|
||||
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||
{ metadata: undefined, noNotification: true }
|
||||
{ metadata: undefined, no_notification: true }
|
||||
)
|
||||
|
||||
expect(orderRepo.save).toHaveBeenCalledTimes(1)
|
||||
@@ -1094,7 +1094,7 @@ describe("OrderService", () => {
|
||||
IdMap.getId("test"),
|
||||
IdMap.getId("fulfillment"),
|
||||
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||
{ noNotification: input }
|
||||
{ no_notification: input }
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String), {
|
||||
@@ -1197,7 +1197,7 @@ describe("OrderService", () => {
|
||||
100,
|
||||
"discount",
|
||||
"note",
|
||||
{ noNotification: input }
|
||||
{ no_notification: input }
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(expect.any(String), {
|
||||
|
||||
@@ -340,30 +340,33 @@ describe("SwapService", () => {
|
||||
|
||||
expect(returnService.create).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
|
||||
it.each([
|
||||
[true, true],
|
||||
[false, false],
|
||||
[undefined, true],
|
||||
])( "passes correct no_notification to eventBus with %s", async (input, expected) => {
|
||||
])(
|
||||
"passes correct no_notification to eventBus with %s",
|
||||
async (input, expected) => {
|
||||
await swapService.create(
|
||||
testOrder,
|
||||
[{ item_id: IdMap.getId("line"), quantity: 1 }],
|
||||
[{ variant_id: IdMap.getId("new-variant"), quantity: 1 }],
|
||||
{
|
||||
id: IdMap.getId("return-shipping"),
|
||||
price: 20,
|
||||
},
|
||||
{ no_notification: input }
|
||||
)
|
||||
|
||||
await swapService.create(
|
||||
testOrder,
|
||||
[{ item_id: IdMap.getId("line"), quantity: 1 }],
|
||||
[{ variant_id: IdMap.getId("new-variant"), quantity: 1 }],
|
||||
{
|
||||
id: IdMap.getId("return-shipping"),
|
||||
price: 20,
|
||||
},
|
||||
{noNotification: input}
|
||||
)
|
||||
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
{"id": undefined, "no_notification": expected})
|
||||
})
|
||||
})
|
||||
expect(eventBusService.emit).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
{ id: undefined, no_notification: expected }
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("receiveReturn", () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -311,10 +311,10 @@ class ClaimService extends BaseService {
|
||||
id,
|
||||
config = {
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
const { metadata, no_notification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
const claim = await this.retrieve(id, {
|
||||
@@ -353,7 +353,7 @@ class ClaimService extends BaseService {
|
||||
}
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : claim.no_notification
|
||||
no_notification !== undefined ? no_notification : claim.no_notification
|
||||
|
||||
const fulfillments = await this.fulfillmentService_
|
||||
.withTransaction(manager)
|
||||
@@ -469,10 +469,10 @@ class ClaimService extends BaseService {
|
||||
trackingLinks,
|
||||
config = {
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
const { metadata, no_notification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
const claim = await this.retrieve(id, {
|
||||
@@ -480,13 +480,13 @@ class ClaimService extends BaseService {
|
||||
})
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : claim.no_notification
|
||||
no_notification !== undefined ? no_notification : claim.no_notification
|
||||
|
||||
const shipment = await this.fulfillmentService_
|
||||
.withTransaction(manager)
|
||||
.createShipment(fulfillmentId, trackingLinks, {
|
||||
metadata,
|
||||
noNotification: evaluatedNoNotification,
|
||||
no_notification: evaluatedNoNotification,
|
||||
})
|
||||
|
||||
claim.fulfillment_status = "shipped"
|
||||
|
||||
@@ -253,7 +253,7 @@ class DraftOrderService extends BaseService {
|
||||
items,
|
||||
shipping_methods,
|
||||
discounts,
|
||||
no_notification_order = undefined,
|
||||
no_notification_order,
|
||||
...rest
|
||||
} = data
|
||||
|
||||
@@ -345,6 +345,7 @@ class DraftOrderService extends BaseService {
|
||||
await draftOrderRepo.save(draftOrder)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a draft order with the given data
|
||||
* @param {String} doId - id of the draft order
|
||||
|
||||
@@ -180,9 +180,10 @@ class FulfillmentService extends BaseService {
|
||||
this.validateFulfillmentLineItem_
|
||||
)
|
||||
|
||||
const { noNotification, ...rest} = custom
|
||||
const { no_notification, ...rest } = custom
|
||||
|
||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification
|
||||
const evaluatedNoNotification =
|
||||
no_notification !== undefined ? no_notification : order.no_notification
|
||||
|
||||
const { shipping_methods } = order
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class NotificationService extends BaseService {
|
||||
this.notificationProviderRepository_ = notificationProviderRepository
|
||||
|
||||
this.subscribers_ = {}
|
||||
this.attachmentGenerator_ = null
|
||||
this.attachmentGenerator_ = null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +164,7 @@ class NotificationService extends BaseService {
|
||||
if (!subs) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
if(data['no_notification'] === true) {
|
||||
if (data["no_notification"] === true) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -579,10 +579,10 @@ class OrderService extends BaseService {
|
||||
trackingLinks,
|
||||
config = {
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
const { metadata, no_notification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
const order = await this.retrieve(orderId, { relations: ["items"] })
|
||||
@@ -596,13 +596,15 @@ class OrderService extends BaseService {
|
||||
}
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : shipment.no_notification
|
||||
no_notification !== undefined
|
||||
? no_notification
|
||||
: shipment.no_notification
|
||||
|
||||
const shipmentRes = await this.fulfillmentService_
|
||||
.withTransaction(manager)
|
||||
.createShipment(fulfillmentId, trackingLinks, {
|
||||
metadata,
|
||||
noNotification: evaluatedNoNotification,
|
||||
no_notification: evaluatedNoNotification,
|
||||
})
|
||||
|
||||
order.fulfillment_status = "shipped"
|
||||
@@ -1002,11 +1004,11 @@ class OrderService extends BaseService {
|
||||
orderId,
|
||||
itemsToFulfill,
|
||||
config = {
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
metadata: {},
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
const { metadata, no_notification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
const order = await this.retrieve(orderId, {
|
||||
@@ -1046,7 +1048,7 @@ class OrderService extends BaseService {
|
||||
.withTransaction(manager)
|
||||
.createFulfillment(order, itemsToFulfill, {
|
||||
metadata,
|
||||
noNotification: noNotification,
|
||||
no_notification: no_notification,
|
||||
order_id: orderId,
|
||||
})
|
||||
let successfullyFulfilled = []
|
||||
@@ -1087,7 +1089,7 @@ class OrderService extends BaseService {
|
||||
const result = await orderRepo.save(order)
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : order.no_notification
|
||||
no_notification !== undefined ? no_notification : order.no_notification
|
||||
|
||||
for (const fulfillment of fulfillments) {
|
||||
await this.eventBus_
|
||||
@@ -1157,10 +1159,10 @@ class OrderService extends BaseService {
|
||||
reason,
|
||||
note,
|
||||
config = {
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
}
|
||||
) {
|
||||
const { noNotification } = config
|
||||
const { no_notification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
const order = await this.retrieve(orderId, {
|
||||
@@ -1182,7 +1184,7 @@ class OrderService extends BaseService {
|
||||
const result = await this.retrieve(orderId)
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : order.no_notification
|
||||
no_notification !== undefined ? no_notification : order.no_notification
|
||||
|
||||
this.eventBus_.emit(OrderService.Events.REFUND_CREATED, {
|
||||
id: result.id,
|
||||
|
||||
@@ -205,9 +205,9 @@ class SwapService extends BaseService {
|
||||
* the customer.
|
||||
* @param {ReturnShipping?} returnShipping - an optional shipping method for
|
||||
* returning the returnItems.
|
||||
* @param {boolean?} noNotification - an optional flag to disable sending
|
||||
* notification when creating swap. If set, it overrules the attribute inherited
|
||||
* from the order.
|
||||
* @param {Object} custom - contains relevant custom information. This object may
|
||||
* include no_notification which will disable sending notification when creating
|
||||
* swap. If set, it overrules the attribute inherited from the order.
|
||||
* @returns {Promise<Swap>} the newly created swap.
|
||||
*/
|
||||
async create(
|
||||
@@ -216,10 +216,10 @@ class SwapService extends BaseService {
|
||||
additionalItems,
|
||||
returnShipping,
|
||||
custom = {
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
}
|
||||
) {
|
||||
const { noNotification, ...rest } = custom
|
||||
const { no_notification, ...rest } = custom
|
||||
return this.atomicPhase_(async manager => {
|
||||
if (
|
||||
order.fulfillment_status === "not_fulfilled" ||
|
||||
@@ -242,7 +242,7 @@ class SwapService extends BaseService {
|
||||
)
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : order.no_notification
|
||||
no_notification !== undefined ? no_notification : order.no_notification
|
||||
|
||||
const swapRepo = manager.getCustomRepository(this.swapRepository_)
|
||||
const created = swapRepo.create({
|
||||
@@ -645,17 +645,17 @@ class SwapService extends BaseService {
|
||||
* Fulfills the addtional items associated with the swap. Will call the
|
||||
* fulfillment providers associated with the shipping methods.
|
||||
* @param {string} swapId - the id of the swap to fulfill,
|
||||
* @param {object} config - optional configurations, includes optional metadata to attach to the shipment, and a noNotification flag.
|
||||
* @param {object} config - optional configurations, includes optional metadata to attach to the shipment, and a no_notification flag.
|
||||
* @returns {Promise<Swap>} the updated swap with new status and fulfillments.
|
||||
*/
|
||||
async createFulfillment(
|
||||
swapId,
|
||||
config = {
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
const { metadata, no_notification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
const swap = await this.retrieve(swapId, {
|
||||
@@ -687,7 +687,7 @@ class SwapService extends BaseService {
|
||||
}
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : swap.no_notification
|
||||
no_notification !== undefined ? no_notification : swap.no_notification
|
||||
|
||||
swap.fulfillments = await this.fulfillmentService_
|
||||
.withTransaction(manager)
|
||||
@@ -779,10 +779,10 @@ class SwapService extends BaseService {
|
||||
trackingLinks,
|
||||
config = {
|
||||
metadata: {},
|
||||
noNotification: undefined,
|
||||
no_notification: undefined,
|
||||
}
|
||||
) {
|
||||
const { metadata, noNotification } = config
|
||||
const { metadata, no_notification } = config
|
||||
|
||||
return this.atomicPhase_(async manager => {
|
||||
const swap = await this.retrieve(swapId, {
|
||||
@@ -790,14 +790,14 @@ class SwapService extends BaseService {
|
||||
})
|
||||
|
||||
const evaluatedNoNotification =
|
||||
noNotification !== undefined ? noNotification : swap.no_notification
|
||||
no_notification !== undefined ? no_notification : swap.no_notification
|
||||
|
||||
// Update the fulfillment to register
|
||||
const shipment = await this.fulfillmentService_
|
||||
.withTransaction(manager)
|
||||
.createShipment(fulfillmentId, trackingLinks, {
|
||||
metadata,
|
||||
noNotification: evaluatedNoNotification,
|
||||
no_notification: evaluatedNoNotification,
|
||||
})
|
||||
|
||||
swap.fulfillment_status = "shipped"
|
||||
|
||||
Reference in New Issue
Block a user