snake_cased noNotification and other minor changes

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