fix: make medusa/src/services/fulfillment.js pass eslint (#557)

* fix: make /packages/medusa/src/services/gift-card.js pass eslint

* fix: make medusa/src/services/fulfillment.js pass eslint

* chore: restore eslintignore change

* chore: clean up diffs
This commit is contained in:
Rachel authored and GitHub committed 2021-10-14 10:31:23 +02:00
1 parent ddeaf57f59
commit fe599c709e
2 files changed
+16 -16

No files matched your search

-1
View File
@@ -7,7 +7,6 @@
/packages/medusa/src/services/draft-order.js /packages/medusa/src/services/draft-order.js
/packages/medusa/src/services/event-bus.js /packages/medusa/src/services/event-bus.js
/packages/medusa/src/services/fulfillment-provider.js /packages/medusa/src/services/fulfillment-provider.js
/packages/medusa/src/services/fulfillment.js
/packages/medusa/src/services/idempotency-key.js /packages/medusa/src/services/idempotency-key.js
/packages/medusa/src/services/inventory.js /packages/medusa/src/services/inventory.js
/packages/medusa/src/services/line-item.js /packages/medusa/src/services/line-item.js
+16 -15
View File
@@ -1,10 +1,9 @@
import _ from "lodash"
import { BaseService } from "medusa-interfaces" import { BaseService } from "medusa-interfaces"
import { MedusaError } from "medusa-core-utils" import { MedusaError } from "medusa-core-utils"
/** /**
* Handles Fulfillments * Handles Fulfillments
* @implements BaseService * @extends BaseService
*/ */
class FulfillmentService extends BaseService { class FulfillmentService extends BaseService {
constructor({ constructor({
@@ -61,7 +60,7 @@ class FulfillmentService extends BaseService {
} }
partitionItems_(shippingMethods, items) { partitionItems_(shippingMethods, items) {
let partitioned = [] const partitioned = []
// partition order items to their dedicated shipping method // partition order items to their dedicated shipping method
for (const method of shippingMethods) { for (const method of shippingMethods) {
const temp = { shipping_method: method } const temp = { shipping_method: method }
@@ -95,12 +94,12 @@ class FulfillmentService extends BaseService {
async getFulfillmentItems_(order, items, transformer) { async getFulfillmentItems_(order, items, transformer) {
const toReturn = await Promise.all( const toReturn = await Promise.all(
items.map(async ({ item_id, quantity }) => { items.map(async ({ item_id, quantity }) => {
const item = order.items.find(i => i.id === item_id) const item = order.items.find((i) => i.id === item_id)
return transformer(item, quantity) return transformer(item, quantity)
}) })
) )
return toReturn.filter(i => !!i) return toReturn.filter((i) => !!i)
} }
/** /**
@@ -137,6 +136,7 @@ class FulfillmentService extends BaseService {
/** /**
* Retrieves a fulfillment by its id. * Retrieves a fulfillment by its id.
* @param {string} id - the id of the fulfillment to retrieve * @param {string} id - the id of the fulfillment to retrieve
* @param {object} config - optional values to include with fulfillmentRepository query
* @return {Fulfillment} the fulfillment * @return {Fulfillment} the fulfillment
*/ */
async retrieve(id, config = {}) { async retrieve(id, config = {}) {
@@ -165,11 +165,11 @@ class FulfillmentService extends BaseService {
* those partitions. * those partitions.
* @param {Order} order - order to create fulfillment for * @param {Order} order - order to create fulfillment for
* @param {{ item_id: string, quantity: number}[]} itemsToFulfill - the items in the order to fulfill * @param {{ item_id: string, quantity: number}[]} itemsToFulfill - the items in the order to fulfill
* @param {object} metadata - potential metadata to add * @param {object} custom - potential custom values to add
* @return {Fulfillment[]} the created fulfillments * @return {Fulfillment[]} the created fulfillments
*/ */
async createFulfillment(order, itemsToFulfill, custom = {}) { async createFulfillment(order, itemsToFulfill, custom = {}) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const fulfillmentRepository = manager.getCustomRepository( const fulfillmentRepository = manager.getCustomRepository(
this.fulfillmentRepository_ this.fulfillmentRepository_
) )
@@ -190,13 +190,14 @@ class FulfillmentService extends BaseService {
const ful = fulfillmentRepository.create({ const ful = fulfillmentRepository.create({
...custom, ...custom,
provider_id: shipping_method.shipping_option.provider_id, provider_id: shipping_method.shipping_option.provider_id,
items: items.map(i => ({ item_id: i.id, quantity: i.quantity })), items: items.map((i) => ({ item_id: i.id, quantity: i.quantity })),
data: {}, data: {},
}) })
let result = await fulfillmentRepository.save(ful) const result = await fulfillmentRepository.save(ful)
result.data = await this.fulfillmentProviderService_.createFulfillment( result.data =
await this.fulfillmentProviderService_.createFulfillment(
shipping_method, shipping_method,
items, items,
{ ...order }, { ...order },
@@ -220,7 +221,7 @@ class FulfillmentService extends BaseService {
* *
*/ */
cancelFulfillment(fulfillmentOrId) { cancelFulfillment(fulfillmentOrId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
let id = fulfillmentOrId let id = fulfillmentOrId
if (typeof fulfillmentOrId === "object") { if (typeof fulfillmentOrId === "object") {
id = fulfillmentOrId.id id = fulfillmentOrId.id
@@ -260,9 +261,9 @@ class FulfillmentService extends BaseService {
/** /**
* Creates a shipment by marking a fulfillment as shipped. Adds * Creates a shipment by marking a fulfillment as shipped. Adds
* tracking numbers and potentially more metadata. * tracking links and potentially more metadata.
* @param {Order} fulfillmentId - the fulfillment to ship * @param {Order} fulfillmentId - the fulfillment to ship
* @param {TrackingLink[]} trackingNumbers - tracking numbers for the shipment * @param {TrackingLink[]} trackingLinks - tracking links for the shipment
* @param {object} config - potential configuration settings, such as no_notification and metadata * @param {object} config - potential configuration settings, such as no_notification and metadata
* @return {Fulfillment} the shipped fulfillment * @return {Fulfillment} the shipped fulfillment
*/ */
@@ -276,7 +277,7 @@ class FulfillmentService extends BaseService {
) { ) {
const { metadata, no_notification } = config const { metadata, no_notification } = config
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const fulfillmentRepository = manager.getCustomRepository( const fulfillmentRepository = manager.getCustomRepository(
this.fulfillmentRepository_ this.fulfillmentRepository_
) )
@@ -298,7 +299,7 @@ class FulfillmentService extends BaseService {
const now = new Date() const now = new Date()
fulfillment.shipped_at = now fulfillment.shipped_at = now
fulfillment.tracking_links = trackingLinks.map(tl => fulfillment.tracking_links = trackingLinks.map((tl) =>
trackingLinkRepo.create(tl) trackingLinkRepo.create(tl)
) )