chore: Make packages/medusa/src/services/shipping-option.js (#540)

This commit is contained in:
Lucifer
2021-10-14 20:55:33 +05:30
committed by GitHub
parent 1791acb044
commit 303eb06b2a
2 changed files with 17 additions and 17 deletions

View File

@@ -19,7 +19,6 @@
/packages/medusa/src/services/query-builder.js
/packages/medusa/src/services/return-reason.js
/packages/medusa/src/services/return.js
/packages/medusa/src/services/shipping-option.js
/packages/medusa/src/services/shipping-profile.js
/packages/medusa/src/services/store.js
/packages/medusa/src/services/swap.js

View File

@@ -1,11 +1,9 @@
import _ from "lodash"
import { MedusaError } from "medusa-core-utils"
import { BaseService } from "medusa-interfaces"
import { In } from "typeorm"
/**
* Provides layer to manipulate profiles.
* @implements BaseService
* @extends BaseService
*/
class ShippingOptionService extends BaseService {
constructor({
@@ -64,6 +62,7 @@ class ShippingOptionService extends BaseService {
/**
* Validates a requirement
* @param {ShippingRequirement} requirement - the requirement to validate
* @param {string} optionId - the id to validate the requirement
* @return {ShippingRequirement} a validated shipping requirement
*/
async validateRequirement_(requirement, optionId) {
@@ -123,6 +122,7 @@ class ShippingOptionService extends BaseService {
/**
* @param {Object} selector - the query object for find
* @param {object} config - config object
* @return {Promise} the result of the find operation
*/
async list(selector, config = { skip: 0, take: 50 }) {
@@ -136,6 +136,7 @@ class ShippingOptionService extends BaseService {
* Gets a profile by id.
* Throws in case of DB Error and if profile was not found.
* @param {string} optionId - the id of the profile to get.
* @param {object} options - the options to get a profile
* @return {Promise<Product>} the profile document.
*/
async retrieve(optionId, options = {}) {
@@ -171,7 +172,7 @@ class ShippingOptionService extends BaseService {
* and its methods should be copied to an order/swap entity.
* @param {string} id - the id of the shipping method to update
* @param {object} update - the values to update the method with
* @returns {Promise<ShippingMethod>} the resulting shipping method
* @return {Promise<ShippingMethod>} the resulting shipping method
*/
async updateShippingMethod(id, update) {
return this.atomicPhase_(async manager => {
@@ -200,7 +201,7 @@ class ShippingOptionService extends BaseService {
/**
* Removes a given shipping method
* @param {string} id - the id of the option to use for the method.
* @param {string} sm - the shipping method to remove
*/
async deleteShippingMethod(sm) {
return this.atomicPhase_(async manager => {
@@ -214,7 +215,7 @@ class ShippingOptionService extends BaseService {
* @param {string} optionId - the id of the option to use for the method.
* @param {object} data - the optional provider data to use.
* @param {object} config - the cart to create the shipping method for.
* @returns {ShippingMethod} the resulting shipping method.
* @return {ShippingMethod} the resulting shipping method.
*/
async createShippingMethod(optionId, data, config) {
return this.atomicPhase_(async manager => {
@@ -286,7 +287,7 @@ class ShippingOptionService extends BaseService {
* Checks if a given option id is a valid option for a cart. If it is the
* option is returned with the correct price. Throws when region_ids do not
* match, or when the shipping option requirements are not satisfied.
* @param {string} optionId - the id of the option to check
* @param {object} option - the option object to check
* @param {Cart} cart - the cart object to check against
* @return {ShippingOption} the validated shipping option
*/
@@ -328,7 +329,7 @@ class ShippingOptionService extends BaseService {
* Creates a new shipping option. Used both for outbound and inbound shipping
* options. The difference is registered by the `is_return` field which
* defaults to false.
* @param {ShippingOption} option - the shipping option to create
* @param {ShippingOption} data - the data to create shipping options
* @return {Promise<ShippingOption>} the result of the create operation
*/
async create(data) {
@@ -408,7 +409,7 @@ class ShippingOptionService extends BaseService {
/**
* Validates a shipping option price
* @param {ShippingOptionPrice} price - the price to validate
* @param {ShippingOptionPrice} priceType - the price to validate
* @param {ShippingOption} option - the option to validate against
* @return {Promise<ShippingOptionPrice>} the validated price
*/
@@ -552,7 +553,7 @@ class ShippingOptionService extends BaseService {
*/
async delete(optionId) {
try {
let option = await this.retrieve(optionId)
const option = await this.retrieve(optionId)
const optionRepo = this.manager_.getCustomRepository(
this.optionRepository_
@@ -624,7 +625,7 @@ class ShippingOptionService extends BaseService {
/**
* Decorates a shipping option.
* @param {ShippingOption} shippingOption - the shipping option to decorate.
* @param {ShippingOption} optionId - the shipping option to decorate using optionId.
* @param {string[]} fields - the fields to include.
* @param {string[]} expandFields - fields to expand.
* @return {ShippingOption} the decorated ShippingOption.
@@ -644,9 +645,8 @@ class ShippingOptionService extends BaseService {
/**
* Dedicated method to set metadata for a shipping option.
* @param {string} optionId - the option to set metadata for.
* @param {string} key - key for metadata field
* @param {string} value - value for metadata field.
* @param {object} option - the option to set metadata for.
* @param {object} metadata - object for metadata field
* @return {Promise} resolves to the updated result.
*/
async setMetadata_(option, metadata) {
@@ -677,9 +677,10 @@ class ShippingOptionService extends BaseService {
* price type "calculated".
* @param {ShippingOption} option - the shipping option to retrieve the price
* for.
* @param {Cart || Order} cart - the context in which the price should be
* @param {ShippingData} data - the shipping data to retrieve the price.
* @param {Cart | Order} cart - the context in which the price should be
* retrieved.
* @returns {Promise<Number>} the price of the shipping option.
* @return {Promise<Number>} the price of the shipping option.
*/
async getPrice_(option, data, cart) {
if (option.price_type === "calculated") {