fix: make packages/medusa/src/services/claim.js pass eslint (#551)

This commit is contained in:
Vladyslav
2021-10-14 09:52:18 +02:00
committed by GitHub
parent d9608e15e8
commit ddeaf57f59
2 changed files with 22 additions and 27 deletions
-1
View File
@@ -2,7 +2,6 @@
/packages/medusa/src/services/cart.js /packages/medusa/src/services/cart.js
/packages/medusa/src/services/claim-item.js /packages/medusa/src/services/claim-item.js
/packages/medusa/src/services/claim.js
/packages/medusa/src/services/customer.js /packages/medusa/src/services/customer.js
/packages/medusa/src/services/discount.js /packages/medusa/src/services/discount.js
/packages/medusa/src/services/draft-order.js /packages/medusa/src/services/draft-order.js
+22 -26
View File
@@ -1,7 +1,5 @@
import _ from "lodash" import { MedusaError } from "medusa-core-utils"
import { Validator, MedusaError } from "medusa-core-utils"
import { BaseService } from "medusa-interfaces" import { BaseService } from "medusa-interfaces"
import { Brackets } from "typeorm"
class ClaimService extends BaseService { class ClaimService extends BaseService {
static Events = { static Events = {
@@ -102,7 +100,7 @@ class ClaimService extends BaseService {
} }
update(id, data) { update(id, data) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const claimRepo = manager.getCustomRepository(this.claimRepository_) const claimRepo = manager.getCustomRepository(this.claimRepository_)
const claim = await this.retrieve(id, { relations: ["shipping_methods"] }) const claim = await this.retrieve(id, { relations: ["shipping_methods"] })
@@ -113,13 +111,7 @@ class ClaimService extends BaseService {
) )
} }
const { const { claim_items, shipping_methods, metadata, no_notification } = data
claim_items,
shipping_methods,
metadata,
fulfillment_status,
no_notification,
} = data
if (metadata) { if (metadata) {
claim.metadata = this.setMetadata_(claim, metadata) claim.metadata = this.setMetadata_(claim, metadata)
@@ -183,9 +175,11 @@ class ClaimService extends BaseService {
* Creates a Claim on an Order. Claims consists of items that are claimed and * Creates a Claim on an Order. Claims consists of items that are claimed and
* optionally items to be sent as replacement for the claimed items. The * optionally items to be sent as replacement for the claimed items. The
* shipping address that the new items will be shipped to * shipping address that the new items will be shipped to
* @param {Object} data - the object containing all data required to create a claim
* @return {Object} created claim
*/ */
create(data) { create(data) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const claimRepo = manager.getCustomRepository(this.claimRepository_) const claimRepo = manager.getCustomRepository(this.claimRepository_)
const { const {
@@ -257,8 +251,8 @@ class ClaimService extends BaseService {
let toRefund = refund_amount let toRefund = refund_amount
if (type === "refund" && typeof refund_amount === "undefined") { if (type === "refund" && typeof refund_amount === "undefined") {
const lines = claim_items.map(ci => { const lines = claim_items.map((ci) => {
const orderItem = order.items.find(oi => oi.id === ci.item_id) const orderItem = order.items.find((oi) => oi.id === ci.item_id)
return { return {
...orderItem, ...orderItem,
quantity: ci.quantity, quantity: ci.quantity,
@@ -274,7 +268,7 @@ class ClaimService extends BaseService {
} }
const newItems = await Promise.all( const newItems = await Promise.all(
additional_items.map(i => additional_items.map((i) =>
this.lineItemService_ this.lineItemService_
.withTransaction(manager) .withTransaction(manager)
.generate(i.variant_id, order.region_id, i.quantity) .generate(i.variant_id, order.region_id, i.quantity)
@@ -332,7 +326,7 @@ class ClaimService extends BaseService {
await this.returnService_.withTransaction(manager).create({ await this.returnService_.withTransaction(manager).create({
order_id: order.id, order_id: order.id,
claim_order_id: result.id, claim_order_id: result.id,
items: claim_items.map(ci => ({ items: claim_items.map((ci) => ({
item_id: ci.item_id, item_id: ci.item_id,
quantity: ci.quantity, quantity: ci.quantity,
metadata: ci.metadata, metadata: ci.metadata,
@@ -362,7 +356,7 @@ class ClaimService extends BaseService {
) { ) {
const { metadata, no_notification } = 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, {
relations: [ relations: [
"additional_items", "additional_items",
@@ -429,7 +423,7 @@ class ClaimService extends BaseService {
is_claim: true, is_claim: true,
no_notification: evaluatedNoNotification, no_notification: evaluatedNoNotification,
}, },
claim.additional_items.map(i => ({ claim.additional_items.map((i) => ({
item_id: i.id, item_id: i.id,
quantity: i.quantity, quantity: i.quantity,
})), })),
@@ -445,7 +439,7 @@ class ClaimService extends BaseService {
for (const item of claim.additional_items) { for (const item of claim.additional_items) {
const fulfillmentItem = successfullyFulfilled.find( const fulfillmentItem = successfullyFulfilled.find(
f => item.id === f.item_id (f) => item.id === f.item_id
) )
if (fulfillmentItem) { if (fulfillmentItem) {
@@ -485,7 +479,7 @@ class ClaimService extends BaseService {
} }
async cancelFulfillment(fulfillmentId) { async cancelFulfillment(fulfillmentId) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const canceled = await this.fulfillmentService_ const canceled = await this.fulfillmentService_
.withTransaction(manager) .withTransaction(manager)
.cancelFulfillment(fulfillmentId) .cancelFulfillment(fulfillmentId)
@@ -508,7 +502,7 @@ class ClaimService extends BaseService {
} }
async processRefund(id) { async processRefund(id) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const claim = await this.retrieve(id, { const claim = await this.retrieve(id, {
relations: ["order", "order.payments"], relations: ["order", "order.payments"],
}) })
@@ -560,7 +554,7 @@ class ClaimService extends BaseService {
) { ) {
const { metadata, no_notification } = 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, {
relations: ["additional_items"], relations: ["additional_items"],
}) })
@@ -584,7 +578,7 @@ class ClaimService extends BaseService {
claim.fulfillment_status = "shipped" claim.fulfillment_status = "shipped"
for (const i of claim.additional_items) { for (const i of claim.additional_items) {
const shipped = shipment.items.find(si => si.item_id === i.id) const shipped = shipment.items.find((si) => si.item_id === i.id)
if (shipped) { if (shipped) {
const shippedQty = (i.shipped_quantity || 0) + shipped.quantity const shippedQty = (i.shipped_quantity || 0) + shipped.quantity
await this.lineItemService_.withTransaction(manager).update(i.id, { await this.lineItemService_.withTransaction(manager).update(i.id, {
@@ -617,7 +611,7 @@ class ClaimService extends BaseService {
} }
async cancel(id) { async cancel(id) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const claim = await this.retrieve(id, { const claim = await this.retrieve(id, {
relations: ["return_order", "fulfillments", "order", "order.refunds"], relations: ["return_order", "fulfillments", "order", "order.refunds"],
}) })
@@ -665,6 +659,7 @@ class ClaimService extends BaseService {
/** /**
* @param {Object} selector - the query object for find * @param {Object} selector - the query object for find
* @param {Object} config - the config object containing query settings
* @return {Promise} the result of the find operation * @return {Promise} the result of the find operation
*/ */
async list( async list(
@@ -678,7 +673,8 @@ class ClaimService extends BaseService {
/** /**
* Gets an order by id. * Gets an order by id.
* @param {string} orderId - id of order to retrieve * @param {string} claimId - id of order to retrieve
* @param {Object} config - the config object containing query settings
* @return {Promise<Order>} the order document * @return {Promise<Order>} the order document
*/ */
async retrieve(claimId, config = {}) { async retrieve(claimId, config = {}) {
@@ -717,7 +713,7 @@ class ClaimService extends BaseService {
const keyPath = `metadata.${key}` const keyPath = `metadata.${key}`
return this.orderModel_ return this.orderModel_
.updateOne({ _id: validatedId }, { $unset: { [keyPath]: "" } }) .updateOne({ _id: validatedId }, { $unset: { [keyPath]: "" } })
.catch(err => { .catch((err) => {
throw new MedusaError(MedusaError.Types.DB_ERROR, err.message) throw new MedusaError(MedusaError.Types.DB_ERROR, err.message)
}) })
} }