From b91a1ca5b804e66cf5bfc51403f4367a935e6349 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Fri, 9 Feb 2024 14:40:09 +0100 Subject: [PATCH] chore: cleanup inspection (#6358) --- .changeset/calm-countries-exercise.md | 6 ++++ packages/auth/src/initialize/index.ts | 4 +-- packages/auth/src/models/auth-user.ts | 3 -- packages/auth/src/providers/google.ts | 1 - packages/auth/src/services/auth-module.ts | 14 ++++----- packages/cart/src/initialize/index.ts | 2 +- packages/cart/src/services/cart-module.ts | 19 ++++++------ packages/customer/src/initialize/index.ts | 2 +- packages/customer/src/models/customer.ts | 4 +-- .../customer/src/services/customer-module.ts | 10 +++---- .../src/models/price-set-money-amount.ts | 9 ++++-- .../pricing/src/services/pricing-module.ts | 30 +++++++++---------- .../src/types/repositories/price-rule.ts | 1 - .../pricing/src/types/services/price-rule.ts | 2 +- packages/product/src/initialize/index.ts | 2 +- .../src/services/promotion-module.ts | 12 ++++---- .../src/utils/compute-actions/buy-get.ts | 2 +- .../utils/validations/application-method.ts | 9 ++---- .../src/utils/validations/promotion-rule.ts | 6 ++-- 19 files changed, 66 insertions(+), 72 deletions(-) create mode 100644 .changeset/calm-countries-exercise.md diff --git a/.changeset/calm-countries-exercise.md b/.changeset/calm-countries-exercise.md new file mode 100644 index 0000000000..469702a11f --- /dev/null +++ b/.changeset/calm-countries-exercise.md @@ -0,0 +1,6 @@ +--- +"@medusajs/pricing": patch +"@medusajs/product": patch +--- + +chore: cleanup inspection diff --git a/packages/auth/src/initialize/index.ts b/packages/auth/src/initialize/index.ts index 4eb49c33a3..4fbe09f762 100644 --- a/packages/auth/src/initialize/index.ts +++ b/packages/auth/src/initialize/index.ts @@ -1,13 +1,13 @@ import { ExternalModuleDeclaration, InternalModuleDeclaration, - MODULE_PACKAGE_NAMES, MedusaModule, + MODULE_PACKAGE_NAMES, Modules, } from "@medusajs/modules-sdk" import { IAuthModuleService, ModulesSdkTypes } from "@medusajs/types" -import { InitializeModuleInjectableDependencies } from "../types" +import { InitializeModuleInjectableDependencies } from "@types" import { moduleDefinition } from "../module-definition" export const initialize = async ( diff --git a/packages/auth/src/models/auth-user.ts b/packages/auth/src/models/auth-user.ts index 10e4e3b9ff..c05c59478b 100644 --- a/packages/auth/src/models/auth-user.ts +++ b/packages/auth/src/models/auth-user.ts @@ -1,9 +1,6 @@ import { BeforeCreate, - Cascade, Entity, - Index, - ManyToOne, OnInit, OptionalProps, PrimaryKey, diff --git a/packages/auth/src/providers/google.ts b/packages/auth/src/providers/google.ts index a6b2ffff1a..557daa36cc 100644 --- a/packages/auth/src/providers/google.ts +++ b/packages/auth/src/providers/google.ts @@ -1,6 +1,5 @@ import { AbstractAuthModuleProvider, MedusaError } from "@medusajs/utils" import { - AuthProviderScope, AuthenticationInput, AuthenticationResponse, ModulesSdkTypes, diff --git a/packages/auth/src/services/auth-module.ts b/packages/auth/src/services/auth-module.ts index 83940d1e25..49414a5a33 100644 --- a/packages/auth/src/services/auth-module.ts +++ b/packages/auth/src/services/auth-module.ts @@ -19,7 +19,6 @@ import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" import { AbstractAuthModuleProvider, InjectManager, - InjectTransactionManager, MedusaContext, MedusaError, ModulesSdkUtils, @@ -74,13 +73,12 @@ export default class AuthModuleService ): Promise { const authUsers = await this.authUserService_.create(data, sharedContext) - const serializedUsers = await this.baseRepository_.serialize< - AuthTypes.AuthUserDTO[] - >(authUsers, { - populate: true, - }) - - return serializedUsers + return await this.baseRepository_.serialize( + authUsers, + { + populate: true, + } + ) } update( diff --git a/packages/cart/src/initialize/index.ts b/packages/cart/src/initialize/index.ts index 4774d6c207..759135d399 100644 --- a/packages/cart/src/initialize/index.ts +++ b/packages/cart/src/initialize/index.ts @@ -7,7 +7,7 @@ import { } from "@medusajs/modules-sdk" import { ICartModuleService, ModulesSdkTypes } from "@medusajs/types" import { moduleDefinition } from "../module-definition" -import { InitializeModuleInjectableDependencies } from "../types" +import { InitializeModuleInjectableDependencies } from "@types" export const initialize = async ( options?: diff --git a/packages/cart/src/services/cart-module.ts b/packages/cart/src/services/cart-module.ts index 5d404950cb..deffd092d6 100644 --- a/packages/cart/src/services/cart-module.ts +++ b/packages/cart/src/services/cart-module.ts @@ -403,7 +403,8 @@ export default class CartModuleService< itemIdsOrSelector: string | string[] | Partial, @MedusaContext() sharedContext: Context = {} ): Promise { - let toDelete: string[] = [] + let toDelete: string[] + if (isObject(itemIdsOrSelector)) { const items = await this.listLineItems( { ...itemIdsOrSelector } as Partial, @@ -518,7 +519,7 @@ export default class CartModuleService< ): Promise< CartTypes.CartShippingMethodDTO[] | CartTypes.CartShippingMethodDTO > { - let methods: ShippingMethod[] = [] + let methods: ShippingMethod[] if (isString(cartIdOrData)) { methods = await this.addShippingMethods_( cartIdOrData, @@ -588,7 +589,7 @@ export default class CartModuleService< | Partial, @MedusaContext() sharedContext: Context = {} ): Promise { - let toDelete: string[] = [] + let toDelete: string[] if (isObject(methodIdsOrSelector)) { const methods = await this.listShippingMethods( { @@ -742,7 +743,7 @@ export default class CartModuleService< | Partial, @MedusaContext() sharedContext: Context = {} ): Promise { - let ids: string[] = [] + let ids: string[] if (isObject(adjustmentIdsOrSelector)) { const adjustments = await this.listLineItemAdjustments( { @@ -911,7 +912,7 @@ export default class CartModuleService< | Partial, @MedusaContext() sharedContext: Context = {} ): Promise { - let ids: string[] = [] + let ids: string[] if (isObject(adjustmentIdsOrSelector)) { const adjustments = await this.listShippingMethodAdjustments( { @@ -956,7 +957,7 @@ export default class CartModuleService< | CartTypes.CreateLineItemTaxLineDTO, @MedusaContext() sharedContext: Context = {} ): Promise { - let addedTaxLines: LineItemTaxLine[] = [] + let addedTaxLines: LineItemTaxLine[] if (isString(cartIdOrData)) { // existence check await this.retrieve(cartIdOrData, { select: ["id"] }, sharedContext) @@ -1065,7 +1066,7 @@ export default class CartModuleService< | CartTypes.FilterableShippingMethodTaxLineProps, @MedusaContext() sharedContext: Context = {} ): Promise { - let ids: string[] = [] + let ids: string[] if (isObject(taxLineIdsOrSelector)) { const taxLines = await this.listLineItemTaxLines( { @@ -1112,7 +1113,7 @@ export default class CartModuleService< ): Promise< CartTypes.ShippingMethodTaxLineDTO[] | CartTypes.ShippingMethodTaxLineDTO > { - let addedTaxLines: ShippingMethodTaxLine[] = [] + let addedTaxLines: ShippingMethodTaxLine[] if (isString(cartIdOrData)) { // existence check await this.retrieve(cartIdOrData, { select: ["id"] }, sharedContext) @@ -1222,7 +1223,7 @@ export default class CartModuleService< | CartTypes.FilterableShippingMethodTaxLineProps, @MedusaContext() sharedContext: Context = {} ): Promise { - let ids: string[] = [] + let ids: string[] if (isObject(taxLineIdsOrSelector)) { const taxLines = await this.listShippingMethodTaxLines( { diff --git a/packages/customer/src/initialize/index.ts b/packages/customer/src/initialize/index.ts index ad262c0587..8272f17cc5 100644 --- a/packages/customer/src/initialize/index.ts +++ b/packages/customer/src/initialize/index.ts @@ -7,7 +7,7 @@ import { } from "@medusajs/modules-sdk" import { ICustomerModuleService, ModulesSdkTypes } from "@medusajs/types" import { moduleDefinition } from "../module-definition" -import { InitializeModuleInjectableDependencies } from "../types" +import { InitializeModuleInjectableDependencies } from "@types" export const initialize = async ( options?: diff --git a/packages/customer/src/models/customer.ts b/packages/customer/src/models/customer.ts index 8c1e0a0cfe..e9489c62de 100644 --- a/packages/customer/src/models/customer.ts +++ b/packages/customer/src/models/customer.ts @@ -6,11 +6,9 @@ import { Collection, Entity, Filter, - Index, ManyToMany, - ManyToOne, - OnInit, OneToMany, + OnInit, OptionalProps, PrimaryKey, Property, diff --git a/packages/customer/src/services/customer-module.ts b/packages/customer/src/services/customer-module.ts index 49b6422e80..b58ffa5dc8 100644 --- a/packages/customer/src/services/customer-module.ts +++ b/packages/customer/src/services/customer-module.ts @@ -176,7 +176,7 @@ export default class CustomerModuleService< | { selector: CustomerTypes.FilterableCustomerProps data: CustomerTypes.CustomerUpdatableFields - } = [] + } if (isString(idsOrSelector)) { updateData = { @@ -269,7 +269,7 @@ export default class CustomerModuleService< | { selector: CustomerTypes.FilterableCustomerGroupProps data: CustomerTypes.CustomerGroupUpdatableFields - } = [] + } if (isString(groupIdOrSelector) || Array.isArray(groupIdOrSelector)) { const groupIdOrSelectorArray = Array.isArray(groupIdOrSelector) @@ -373,12 +373,10 @@ export default class CustomerModuleService< | CustomerTypes.CreateCustomerAddressDTO[], @MedusaContext() sharedContext: Context = {} ) { - const addresses = await this.addressService_.create( + return await this.addressService_.create( Array.isArray(data) ? data : [data], sharedContext ) - - return addresses } async updateAddresses( @@ -411,7 +409,7 @@ export default class CustomerModuleService< | { selector: CustomerTypes.FilterableCustomerAddressProps data: CustomerTypes.UpdateCustomerAddressDTO - } = [] + } if (isString(addressIdOrSelector)) { updateData = [ { diff --git a/packages/pricing/src/models/price-set-money-amount.ts b/packages/pricing/src/models/price-set-money-amount.ts index 4c381e78b1..1198e9a95c 100644 --- a/packages/pricing/src/models/price-set-money-amount.ts +++ b/packages/pricing/src/models/price-set-money-amount.ts @@ -4,11 +4,10 @@ import { Collection, Entity, Filter, - Index, ManyToOne, - OnInit, OneToMany, OneToOne, + OnInit, OptionalProps, PrimaryKey, PrimaryKeyType, @@ -84,7 +83,11 @@ export default class PriceSetMoneyAmount { }) updated_at: Date - @Property({ columnType: "timestamptz", nullable: true , index: "IDX_price_set_money_amount_deleted_at"}) + @Property({ + columnType: "timestamptz", + nullable: true, + index: "IDX_price_set_money_amount_deleted_at", + }) deleted_at: Date | null @BeforeCreate() diff --git a/packages/pricing/src/services/pricing-module.ts b/packages/pricing/src/services/pricing-module.ts index b588915df3..52aa312740 100644 --- a/packages/pricing/src/services/pricing-module.ts +++ b/packages/pricing/src/services/pricing-module.ts @@ -48,9 +48,9 @@ import { PriceRuleService, RuleTypeService, } from "@services" -import {entityNameToLinkableKeysMap, joinerConfig} from "../joiner-config" -import {validatePriceListDates} from "@utils" -import {ServiceTypes} from "@types" +import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" +import { validatePriceListDates } from "@utils" +import { ServiceTypes } from "@types" type InjectedDependencies = { baseRepository: DAL.RepositoryService @@ -950,7 +950,7 @@ export default class PricingModuleService< priceListsToCreate )) as unknown as PricingTypes.PriceListDTO[] - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { const { rules = {}, prices = [] } = data[i] const priceList = priceLists[i] @@ -1167,12 +1167,11 @@ export default class PricingModuleService< ): Promise { const priceLists = await this.createPriceListRules_(data, sharedContext) - return await this.baseRepository_.serialize( - priceLists, - { - populate: true, - } - ) + return await this.baseRepository_.serialize< + PricingTypes.PriceListRuleDTO[] + >(priceLists, { + populate: true, + }) } @InjectTransactionManager("baseRepository_") @@ -1193,12 +1192,11 @@ export default class PricingModuleService< sharedContext ) - return await this.baseRepository_.serialize( - priceLists, - { - populate: true, - } - ) + return await this.baseRepository_.serialize< + PricingTypes.PriceListRuleDTO[] + >(priceLists, { + populate: true, + }) } @InjectManager("baseRepository_") diff --git a/packages/pricing/src/types/repositories/price-rule.ts b/packages/pricing/src/types/repositories/price-rule.ts index af92fe08e5..539ee0e5d8 100644 --- a/packages/pricing/src/types/repositories/price-rule.ts +++ b/packages/pricing/src/types/repositories/price-rule.ts @@ -1,5 +1,4 @@ import { PriceSet, PriceSetMoneyAmount, RuleType } from "@models" -import { PriceSetDTO, PriceSetMoneyAmountDTO, RuleTypeDTO } from "@medusajs/types" export interface CreatePriceRuleDTO { id?: string diff --git a/packages/pricing/src/types/services/price-rule.ts b/packages/pricing/src/types/services/price-rule.ts index d3db234d02..e77efa3060 100644 --- a/packages/pricing/src/types/services/price-rule.ts +++ b/packages/pricing/src/types/services/price-rule.ts @@ -1,4 +1,4 @@ -import { BaseFilterable, PriceSetDTO, PriceSetMoneyAmountDTO, RuleTypeDTO } from "@medusajs/types" +import { BaseFilterable, PriceSetDTO, RuleTypeDTO } from "@medusajs/types" import { PriceSet, PriceSetMoneyAmount, RuleType } from "@models" export interface CreatePriceRuleDTO { diff --git a/packages/product/src/initialize/index.ts b/packages/product/src/initialize/index.ts index ef9d4e9503..efaadadc80 100644 --- a/packages/product/src/initialize/index.ts +++ b/packages/product/src/initialize/index.ts @@ -7,7 +7,7 @@ import { } from "@medusajs/modules-sdk" import { IProductModuleService, ModulesSdkTypes } from "@medusajs/types" -import { InitializeModuleInjectableDependencies } from "../types" +import { InitializeModuleInjectableDependencies } from "@types" import { moduleDefinition } from "../module-definition" export const initialize = async ( diff --git a/packages/promotion/src/services/promotion-module.ts b/packages/promotion/src/services/promotion-module.ts index 2fc707942a..008003032e 100644 --- a/packages/promotion/src/services/promotion-module.ts +++ b/packages/promotion/src/services/promotion-module.ts @@ -751,7 +751,7 @@ export default class PromotionModuleService< sharedContext ) - return this.retrieve( + return await this.retrieve( promotionId, { relations: ["rules", "rules.values"] }, sharedContext @@ -784,7 +784,7 @@ export default class PromotionModuleService< sharedContext ) - return this.retrieve( + return await this.retrieve( promotionId, { relations: [ @@ -825,7 +825,7 @@ export default class PromotionModuleService< sharedContext ) - return this.retrieve( + return await this.retrieve( promotionId, { relations: [ @@ -882,7 +882,7 @@ export default class PromotionModuleService< ): Promise { await this.removePromotionRules_(promotionId, rulesData, sharedContext) - return this.retrieve( + return await this.retrieve( promotionId, { relations: ["rules", "rules.values"] }, sharedContext @@ -926,7 +926,7 @@ export default class PromotionModuleService< sharedContext ) - return this.retrieve( + return await this.retrieve( promotionId, { relations: [ @@ -954,7 +954,7 @@ export default class PromotionModuleService< sharedContext ) - return this.retrieve( + return await this.retrieve( promotionId, { relations: [ diff --git a/packages/promotion/src/utils/compute-actions/buy-get.ts b/packages/promotion/src/utils/compute-actions/buy-get.ts index d3bcc3f68d..b6a718ae12 100644 --- a/packages/promotion/src/utils/compute-actions/buy-get.ts +++ b/packages/promotion/src/utils/compute-actions/buy-get.ts @@ -5,7 +5,7 @@ import { MedusaError, PromotionType, } from "@medusajs/utils" -import { areRulesValidForContext } from "../validations/promotion-rule" +import { areRulesValidForContext } from "../validations" import { computeActionForBudgetExceeded } from "./usage" export function getComputedActionsForBuyGet( diff --git a/packages/promotion/src/utils/validations/application-method.ts b/packages/promotion/src/utils/validations/application-method.ts index 7d022f0e9d..2dfea0df8e 100644 --- a/packages/promotion/src/utils/validations/application-method.ts +++ b/packages/promotion/src/utils/validations/application-method.ts @@ -2,16 +2,13 @@ import { ApplicationMethodAllocation, ApplicationMethodTargetType, ApplicationMethodType, - MedusaError, - PromotionType, isDefined, isPresent, + MedusaError, + PromotionType, } from "@medusajs/utils" import { Promotion } from "@models" -import { - CreateApplicationMethodDTO, - UpdateApplicationMethodDTO, -} from "../../types" +import { CreateApplicationMethodDTO, UpdateApplicationMethodDTO } from "@types" export const allowedAllocationTargetTypes: string[] = [ ApplicationMethodTargetType.SHIPPING_METHODS, diff --git a/packages/promotion/src/utils/validations/promotion-rule.ts b/packages/promotion/src/utils/validations/promotion-rule.ts index fa932ee0e5..1c9c7e4152 100644 --- a/packages/promotion/src/utils/validations/promotion-rule.ts +++ b/packages/promotion/src/utils/validations/promotion-rule.ts @@ -1,12 +1,12 @@ import { PromotionRuleDTO, PromotionRuleOperatorValues } from "@medusajs/types" import { - MedusaError, - PromotionRuleOperator, isPresent, isString, + MedusaError, pickValueFromObject, + PromotionRuleOperator, } from "@medusajs/utils" -import { CreatePromotionRuleDTO } from "../../types" +import { CreatePromotionRuleDTO } from "@types" export function validatePromotionRuleAttributes( promotionRulesData: CreatePromotionRuleDTO[]