clean up
This commit is contained in:
1 parent
cfcc6f3fe0
commit
135d45ad45
4 files changed
+21
-53
No files matched your search
@@ -1,21 +0,0 @@
|
|||||||
import { Validator, MedusaError } from "medusa-core-utils"
|
|
||||||
|
|
||||||
export default async (req, res) => {
|
|
||||||
const { id } = req.params
|
|
||||||
|
|
||||||
try {
|
|
||||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
|
||||||
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
|
||||||
|
|
||||||
const draftOrder = await cartService.retrieve(value.cart_id, {
|
|
||||||
select: ["subtotal"],
|
|
||||||
relations: ["region", "items", "items.variant", "items.variant.product"],
|
|
||||||
})
|
|
||||||
|
|
||||||
const options = await shippingProfileService.fetchCartOptions(cart)
|
|
||||||
|
|
||||||
res.status(200).json({ shipping_options: options })
|
|
||||||
} catch (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,6 +15,18 @@ export default async (req, res) => {
|
|||||||
selector.q = req.query.q
|
selector.q = req.query.q
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("payment_status" in req.query) {
|
||||||
|
selector.payment_status = req.query.payment_status
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("status" in req.query) {
|
||||||
|
selector.status = req.query.status
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("fulfillment_status" in req.query) {
|
||||||
|
selector.fulfillment_status = req.query.fulfillment_status
|
||||||
|
}
|
||||||
|
|
||||||
let includeFields = []
|
let includeFields = []
|
||||||
if ("fields" in req.query) {
|
if ("fields" in req.query) {
|
||||||
includeFields = req.query.fields.split(",")
|
includeFields = req.query.fields.split(",")
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ describe("DraftOrderService", () => {
|
|||||||
shipping_address_id: "test-shipping",
|
shipping_address_id: "test-shipping",
|
||||||
billing_address_id: "test-billing",
|
billing_address_id: "test-billing",
|
||||||
customer_id: "test-customer",
|
customer_id: "test-customer",
|
||||||
|
type: "draft_order",
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(shippingOptionService.createShippingMethod).toHaveBeenCalledTimes(
|
expect(shippingOptionService.createShippingMethod).toHaveBeenCalledTimes(
|
||||||
@@ -168,6 +169,7 @@ describe("DraftOrderService", () => {
|
|||||||
shipping_address_id: "test-shipping",
|
shipping_address_id: "test-shipping",
|
||||||
billing_address_id: "test-billing",
|
billing_address_id: "test-billing",
|
||||||
customer_id: "test-customer",
|
customer_id: "test-customer",
|
||||||
|
type: "draft_order",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -328,6 +330,7 @@ describe("DraftOrderService", () => {
|
|||||||
expect(draftOrderRepository.save).toHaveBeenCalledWith({
|
expect(draftOrderRepository.save).toHaveBeenCalledWith({
|
||||||
id: "test-draft-order",
|
id: "test-draft-order",
|
||||||
cart_id: "test-cart",
|
cart_id: "test-cart",
|
||||||
|
order_id: "test-order",
|
||||||
status: "completed",
|
status: "completed",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,15 +18,10 @@ class DraftOrderService extends BaseService {
|
|||||||
paymentRepository,
|
paymentRepository,
|
||||||
orderRepository,
|
orderRepository,
|
||||||
eventBusService,
|
eventBusService,
|
||||||
addressRepository,
|
|
||||||
cartService,
|
cartService,
|
||||||
customerService,
|
|
||||||
totalsService,
|
|
||||||
lineItemService,
|
lineItemService,
|
||||||
paymentProviderService,
|
|
||||||
productVariantService,
|
productVariantService,
|
||||||
shippingOptionService,
|
shippingOptionService,
|
||||||
regionService,
|
|
||||||
}) {
|
}) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@@ -42,27 +37,12 @@ class DraftOrderService extends BaseService {
|
|||||||
/** @private @const {OrderRepository} */
|
/** @private @const {OrderRepository} */
|
||||||
this.orderRepository_ = orderRepository
|
this.orderRepository_ = orderRepository
|
||||||
|
|
||||||
/** @private @const {TotalsService} */
|
|
||||||
this.totalsService_ = totalsService
|
|
||||||
|
|
||||||
/** @private @const {AddressRepository} */
|
|
||||||
this.addressRepository_ = addressRepository
|
|
||||||
|
|
||||||
/** @private @const {LineItemService} */
|
/** @private @const {LineItemService} */
|
||||||
this.lineItemService_ = lineItemService
|
this.lineItemService_ = lineItemService
|
||||||
|
|
||||||
/** @private @const {CartService} */
|
/** @private @const {CartService} */
|
||||||
this.cartService_ = cartService
|
this.cartService_ = cartService
|
||||||
|
|
||||||
/** @private @const {CustomerService} */
|
|
||||||
this.customerService_ = customerService
|
|
||||||
|
|
||||||
/** @private @const {RegionService} */
|
|
||||||
this.regionService_ = regionService
|
|
||||||
|
|
||||||
/** @private @const {PaymentProviderService} */
|
|
||||||
this.paymentProviderService_ = paymentProviderService
|
|
||||||
|
|
||||||
/** @private @const {ProductVariantService} */
|
/** @private @const {ProductVariantService} */
|
||||||
this.productVariantService_ = productVariantService
|
this.productVariantService_ = productVariantService
|
||||||
|
|
||||||
@@ -83,13 +63,8 @@ class DraftOrderService extends BaseService {
|
|||||||
draftOrderRepository: this.draftOrderRepository_,
|
draftOrderRepository: this.draftOrderRepository_,
|
||||||
paymentRepository: this.paymentRepository_,
|
paymentRepository: this.paymentRepository_,
|
||||||
orderRepository: this.orderRepository_,
|
orderRepository: this.orderRepository_,
|
||||||
totalsService: this.totalsService_,
|
|
||||||
addressRepository: this.addressRepository_,
|
|
||||||
lineItemService: this.lineItemService_,
|
lineItemService: this.lineItemService_,
|
||||||
cartService: this.cartService_,
|
cartService: this.cartService_,
|
||||||
customerService: this.customerService_,
|
|
||||||
regionService: this.regionService_,
|
|
||||||
paymentProviderService: this.paymentProviderService_,
|
|
||||||
productVariantService: this.productVariantService_,
|
productVariantService: this.productVariantService_,
|
||||||
shippingOptionService: this.shippingOptionService_,
|
shippingOptionService: this.shippingOptionService_,
|
||||||
eventBusService: this.eventBus_,
|
eventBusService: this.eventBus_,
|
||||||
@@ -103,6 +78,7 @@ class DraftOrderService extends BaseService {
|
|||||||
/**
|
/**
|
||||||
* Retrieves a draft order with the given id.
|
* Retrieves a draft order with the given id.
|
||||||
* @param {string} id - id of the draft order to retrieve
|
* @param {string} id - id of the draft order to retrieve
|
||||||
|
* @param {object} config - query object for findOne
|
||||||
* @return {Promise<DraftOrder>} the draft order
|
* @return {Promise<DraftOrder>} the draft order
|
||||||
*/
|
*/
|
||||||
async retrieve(id, config = {}) {
|
async retrieve(id, config = {}) {
|
||||||
@@ -129,19 +105,17 @@ class DraftOrderService extends BaseService {
|
|||||||
/**
|
/**
|
||||||
* Retrieves a draft order based on its associated cart id
|
* Retrieves a draft order based on its associated cart id
|
||||||
* @param {string} cartId - cart id that the draft orders's cart has
|
* @param {string} cartId - cart id that the draft orders's cart has
|
||||||
|
* * @param {object} config - query object for findOne
|
||||||
* @return {Promise<DraftOrder>} the draft order
|
* @return {Promise<DraftOrder>} the draft order
|
||||||
*/
|
*/
|
||||||
async retrieveByCartId(cartId, relations = []) {
|
async retrieveByCartId(cartId, config = {}) {
|
||||||
const draftOrderRepo = this.manager_.getCustomRepository(
|
const draftOrderRepo = this.manager_.getCustomRepository(
|
||||||
this.draftOrderRepository_
|
this.draftOrderRepository_
|
||||||
)
|
)
|
||||||
|
|
||||||
const draftOrder = await draftOrderRepo.findOne({
|
const query = this.buildQuery_({ cart_id: cartId }, config)
|
||||||
where: {
|
|
||||||
cart_id: cartId,
|
const draftOrder = await draftOrderRepo.findOne(query)
|
||||||
},
|
|
||||||
relations,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!draftOrder) {
|
if (!draftOrder) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
Reference in new issue
Block a user