corrected formatting based on walkthrough of pr
This commit is contained in:
1 parent
92710eb1de
commit
7cecc021f4
4 files changed
+57
-39
No files matched your search
@@ -59,7 +59,6 @@ export default async (req, res) => {
|
|||||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const returnService = req.scope.resolve("returnService")
|
const returnService = req.scope.resolve("returnService")
|
||||||
const orderService = req.scope.resolve("orderService")
|
const orderService = req.scope.resolve("orderService")
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ import { Product } from "./product"
|
|||||||
import { MoneyAmount } from "./money-amount"
|
import { MoneyAmount } from "./money-amount"
|
||||||
import { ProductOptionValue } from "./product-option-value"
|
import { ProductOptionValue } from "./product-option-value"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class ProductVariant {
|
export class ProductVariant {
|
||||||
@PrimaryColumn()
|
@PrimaryColumn()
|
||||||
|
|||||||
@@ -249,8 +249,13 @@ class DraftOrderService extends BaseService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { items, shipping_methods, discounts, no_notification_order=undefined, ...rest } = data
|
const {
|
||||||
|
items,
|
||||||
|
shipping_methods,
|
||||||
|
discounts,
|
||||||
|
no_notification_order = undefined,
|
||||||
|
...rest
|
||||||
|
} = data
|
||||||
|
|
||||||
if (discounts) {
|
if (discounts) {
|
||||||
for (const { code } of discounts) {
|
for (const { code } of discounts) {
|
||||||
@@ -265,7 +270,10 @@ class DraftOrderService extends BaseService {
|
|||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.create({ type: "draft_order", ...rest })
|
.create({ type: "draft_order", ...rest })
|
||||||
|
|
||||||
const draftOrder = draftOrderRepo.create({ cart_id: createdCart.id, no_notification_order})
|
const draftOrder = draftOrderRepo.create({
|
||||||
|
cart_id: createdCart.id,
|
||||||
|
no_notification_order,
|
||||||
|
})
|
||||||
const result = await draftOrderRepo.save(draftOrder)
|
const result = await draftOrderRepo.save(draftOrder)
|
||||||
|
|
||||||
await this.eventBus_
|
await this.eventBus_
|
||||||
@@ -343,31 +351,31 @@ class DraftOrderService extends BaseService {
|
|||||||
* @param {DraftOrder} data - values to update the order with
|
* @param {DraftOrder} data - values to update the order with
|
||||||
* @returns {Promise<DraftOrder>} the updated draft order
|
* @returns {Promise<DraftOrder>} the updated draft order
|
||||||
*/
|
*/
|
||||||
async update(doId, data){
|
async update(doId, data) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
const doRepo = manager.getCustomRepository(this.draftOrderRepository_)
|
const doRepo = manager.getCustomRepository(this.draftOrderRepository_)
|
||||||
const draftOrder = await this.retrieve(doId)
|
const draftOrder = await this.retrieve(doId)
|
||||||
let touched = false
|
let touched = false
|
||||||
|
|
||||||
if(draftOrder.status === "completed"){
|
if (draftOrder.status === "completed") {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_ALLOWED,
|
MedusaError.Types.NOT_ALLOWED,
|
||||||
"Can't update a draft order which is complete"
|
"Can't update a draft order which is complete"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.no_notification_order !== undefined){
|
if (data.no_notification_order !== undefined) {
|
||||||
touched = true
|
touched = true
|
||||||
draftOrder.no_notification_order = data.no_notification_order
|
draftOrder.no_notification_order = data.no_notification_order
|
||||||
}
|
}
|
||||||
|
|
||||||
if(touched){
|
if (touched) {
|
||||||
doRepo.save(draftOrder)
|
doRepo.save(draftOrder)
|
||||||
|
|
||||||
await this.eventBus_
|
await this.eventBus_
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.emit(DraftOrderService.Events.UPDATED, {
|
.emit(DraftOrderService.Events.UPDATED, {
|
||||||
id: draftOrder.id
|
id: draftOrder.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,10 +216,10 @@ class SwapService extends BaseService {
|
|||||||
additionalItems,
|
additionalItems,
|
||||||
returnShipping,
|
returnShipping,
|
||||||
custom = {
|
custom = {
|
||||||
noNotification: undefined
|
noNotification: undefined,
|
||||||
}
|
}
|
||||||
){
|
) {
|
||||||
const { noNotification, ...rest } = custom
|
const { noNotification, ...rest } = custom
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
if (
|
if (
|
||||||
order.fulfillment_status === "not_fulfilled" ||
|
order.fulfillment_status === "not_fulfilled" ||
|
||||||
@@ -241,16 +241,17 @@ class SwapService extends BaseService {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : order.no_notification
|
const evaluatedNoNotification =
|
||||||
|
noNotification !== undefined ? noNotification : order.no_notification
|
||||||
|
|
||||||
const swapRepo = manager.getCustomRepository(this.swapRepository_)
|
const swapRepo = manager.getCustomRepository(this.swapRepository_)
|
||||||
const created = swapRepo.create({
|
const created = swapRepo.create({
|
||||||
...rest ,
|
...rest,
|
||||||
fulfillment_status: "not_fulfilled",
|
fulfillment_status: "not_fulfilled",
|
||||||
payment_status: "not_paid",
|
payment_status: "not_paid",
|
||||||
order_id: order.id,
|
order_id: order.id,
|
||||||
additional_items: newItems,
|
additional_items: newItems,
|
||||||
no_notification: evaluatedNoNotification
|
no_notification: evaluatedNoNotification,
|
||||||
})
|
})
|
||||||
|
|
||||||
const result = await swapRepo.save(created)
|
const result = await swapRepo.save(created)
|
||||||
@@ -387,15 +388,15 @@ class SwapService extends BaseService {
|
|||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
const swap = await this.retrieve(swapId)
|
const swap = await this.retrieve(swapId)
|
||||||
|
|
||||||
if ( "metadata" in update ) {
|
if ("metadata" in update) {
|
||||||
swap.metadata = this.setMetadata_(swap, update.metadata)
|
swap.metadata = this.setMetadata_(swap, update.metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
if( "no_notification" in update ){
|
if ("no_notification" in update) {
|
||||||
swap.no_notification = update.no_notification
|
swap.no_notification = update.no_notification
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( "shipping_address" in update ) {
|
if ("shipping_address" in update) {
|
||||||
await this.updateShippingAddress_(swap, update.shipping_address)
|
await this.updateShippingAddress_(swap, update.shipping_address)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,7 +597,7 @@ class SwapService extends BaseService {
|
|||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.emit(SwapService.Events.PAYMENT_COMPLETED, {
|
.emit(SwapService.Events.PAYMENT_COMPLETED, {
|
||||||
id: swap.id,
|
id: swap.id,
|
||||||
no_notification: swap.no_notification
|
no_notification: swap.no_notification,
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -644,13 +645,16 @@ 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} metadata - optional metadata to attach to the fulfillment.
|
* @param {object} config - optional configurations, includes optional metadata to attach to the shipment, and a noNotification 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(swapId, config = {
|
async createFulfillment(
|
||||||
|
swapId,
|
||||||
|
config = {
|
||||||
metadata: {},
|
metadata: {},
|
||||||
noNotification: undefined
|
noNotification: undefined,
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
const { metadata, noNotification } = config
|
const { metadata, noNotification } = config
|
||||||
|
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
@@ -682,7 +686,8 @@ class SwapService extends BaseService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : swap.no_notification
|
const evaluatedNoNotification =
|
||||||
|
noNotification !== undefined ? noNotification : swap.no_notification
|
||||||
|
|
||||||
swap.fulfillments = await this.fulfillmentService_
|
swap.fulfillments = await this.fulfillmentService_
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
@@ -744,15 +749,15 @@ class SwapService extends BaseService {
|
|||||||
const swapRepo = manager.getCustomRepository(this.swapRepository_)
|
const swapRepo = manager.getCustomRepository(this.swapRepository_)
|
||||||
const result = await swapRepo.save(swap)
|
const result = await swapRepo.save(swap)
|
||||||
|
|
||||||
await this.eventBus_
|
await this.eventBus_.withTransaction(manager).emit(
|
||||||
.withTransaction(manager)
|
SwapService.Events.FULFILLMENT_CREATED,
|
||||||
.emit(SwapService.Events.FULFILLMENT_CREATED,
|
|
||||||
|
|
||||||
{
|
{
|
||||||
id: swapId,
|
id: swapId,
|
||||||
fulfillment_id: result.id,
|
fulfillment_id: result.id,
|
||||||
no_notification: evaluatedNoNotification
|
no_notification: evaluatedNoNotification,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
@@ -765,13 +770,18 @@ class SwapService extends BaseService {
|
|||||||
* has been shipped
|
* has been shipped
|
||||||
* @param {TrackingLink[]} trackingLinks - the tracking numbers associated
|
* @param {TrackingLink[]} trackingLinks - the tracking numbers associated
|
||||||
* with the shipment
|
* with the shipment
|
||||||
* @param {object} metadata - optional metadata to attach to the shipment.
|
* @param {object} config - optional configurations, includes optional metadata to attach to the shipment, and a noNotification flag.
|
||||||
* @returns {Promise<Swap>} the updated swap with new fulfillments and status.
|
* @returns {Promise<Swap>} the updated swap with new fulfillments and status.
|
||||||
*/
|
*/
|
||||||
async createShipment(swapId, fulfillmentId, trackingLinks, config = {
|
async createShipment(
|
||||||
|
swapId,
|
||||||
|
fulfillmentId,
|
||||||
|
trackingLinks,
|
||||||
|
config = {
|
||||||
metadata: {},
|
metadata: {},
|
||||||
noNotification: undefined,
|
noNotification: undefined,
|
||||||
} ) {
|
}
|
||||||
|
) {
|
||||||
const { metadata, noNotification } = config
|
const { metadata, noNotification } = config
|
||||||
|
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
@@ -779,12 +789,16 @@ class SwapService extends BaseService {
|
|||||||
relations: ["additional_items"],
|
relations: ["additional_items"],
|
||||||
})
|
})
|
||||||
|
|
||||||
const evaluatedNoNotification = noNotification !== undefined ? noNotification : swap.no_notification
|
const evaluatedNoNotification =
|
||||||
|
noNotification !== undefined ? noNotification : 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, {metadata, noNotification: evaluatedNoNotification})
|
.createShipment(fulfillmentId, trackingLinks, {
|
||||||
|
metadata,
|
||||||
|
noNotification: evaluatedNoNotification,
|
||||||
|
})
|
||||||
|
|
||||||
swap.fulfillment_status = "shipped"
|
swap.fulfillment_status = "shipped"
|
||||||
|
|
||||||
@@ -814,7 +828,7 @@ class SwapService extends BaseService {
|
|||||||
.emit(SwapService.Events.SHIPMENT_CREATED, {
|
.emit(SwapService.Events.SHIPMENT_CREATED, {
|
||||||
id: swapId,
|
id: swapId,
|
||||||
fulfillment_id: shipment.id,
|
fulfillment_id: shipment.id,
|
||||||
no_notification: swap.no_notification
|
no_notification: swap.no_notification,
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
@@ -871,7 +885,7 @@ class SwapService extends BaseService {
|
|||||||
.emit(SwapService.Events.RECEIVED, {
|
.emit(SwapService.Events.RECEIVED, {
|
||||||
id: id,
|
id: id,
|
||||||
order_id: result.order_id,
|
order_id: result.order_id,
|
||||||
no_notification: swap.no_notification
|
no_notification: swap.no_notification,
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in new issue
Block a user