fix(medusa): Lint and missing transaction usage (#1297)
This commit is contained in:
committed by
GitHub
parent
b164977a19
commit
ab2d81f786
@@ -189,7 +189,7 @@ export class AdminPostDraftOrdersReq {
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, any> = {}
|
||||
metadata?: Record<string, unknown> = {}
|
||||
}
|
||||
|
||||
class ShippingMethod {
|
||||
@@ -198,7 +198,7 @@ class ShippingMethod {
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
data?: Record<string, any> = {}
|
||||
data?: Record<string, unknown> = {}
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@@ -228,5 +228,5 @@ class Item {
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, any> = {}
|
||||
metadata?: Record<string, unknown> = {}
|
||||
}
|
||||
|
||||
@@ -134,5 +134,5 @@ export class AdminPostDraftOrdersDraftOrderLineItemsReq {
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, any> = {}
|
||||
metadata?: Record<string, unknown> = {}
|
||||
}
|
||||
|
||||
@@ -128,5 +128,5 @@ export class AdminPostDraftOrdersDraftOrderLineItemsItemReq {
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
metadata?: Record<string, any> = {}
|
||||
metadata?: Record<string, unknown> = {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Router } from "express"
|
||||
import { Notification } from "./../../../../"
|
||||
import { PaginatedResponse } from "./../../../../types/common"
|
||||
import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -54,7 +54,7 @@ export default async (req, res) => {
|
||||
include_resends,
|
||||
} = await validator(AdminGetNotificationsParams, req.query)
|
||||
|
||||
const selector: any = {}
|
||||
const selector: Record<string, unknown> = {}
|
||||
|
||||
let includeFields: string[] = []
|
||||
if (fields) {
|
||||
|
||||
@@ -47,7 +47,7 @@ export default async (req, res) => {
|
||||
"notificationService"
|
||||
)
|
||||
|
||||
const config: any = {}
|
||||
const config: Record<string, unknown> = {}
|
||||
|
||||
if (validatedBody.to) {
|
||||
config.to = validatedBody.to
|
||||
|
||||
@@ -70,5 +70,5 @@ export class AdminPostOrdersOrderShippingMethodsReq {
|
||||
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
data?: Record<string, any> = {}
|
||||
data?: Record<string, unknown> = {}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Type, Transform } from "class-transformer"
|
||||
import { Type } from "class-transformer"
|
||||
import {
|
||||
IsEmail,
|
||||
IsOptional,
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
SwapService,
|
||||
} from "../../../../services"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /order/{id}/swaps
|
||||
@@ -201,10 +202,12 @@ export default async (req, res) => {
|
||||
case "swap_created": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async (manager) => {
|
||||
const swaps = await swapService.list({
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
})
|
||||
async (transactionManager: EntityManager) => {
|
||||
const swaps = await swapService
|
||||
.withTransaction(transactionManager)
|
||||
.list({
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
})
|
||||
|
||||
if (!swaps.length) {
|
||||
throw new MedusaError(
|
||||
@@ -213,10 +216,12 @@ export default async (req, res) => {
|
||||
)
|
||||
}
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
select: defaultAdminOrdersFields,
|
||||
relations: defaultAdminOrdersRelations,
|
||||
})
|
||||
const order = await orderService
|
||||
.withTransaction(transactionManager)
|
||||
.retrieve(id, {
|
||||
select: defaultAdminOrdersFields,
|
||||
relations: defaultAdminOrdersRelations,
|
||||
})
|
||||
|
||||
return {
|
||||
response_code: 200,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defaultAdminOrdersRelations, defaultAdminOrdersFields } from "."
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { IsNumber, IsOptional, IsString } from "class-validator"
|
||||
import { identity, omit, pick, pickBy } from "lodash"
|
||||
import { omit, pick, pickBy } from "lodash"
|
||||
import { OrderService } from "../../../../services"
|
||||
import { AdminListOrdersSelector } from "../../../../types/orders"
|
||||
import { Type } from "class-transformer"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Transform, Type } from "class-transformer"
|
||||
import { Type } from "class-transformer"
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
import { ProductService, ProductVariantService } from "../../../../services"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
|
||||
@@ -107,7 +107,7 @@ export type AdminRegionsDeleteRes = DeleteResponse
|
||||
|
||||
export class FulfillmentOption {
|
||||
provider_id: string
|
||||
options: any[]
|
||||
options: unknown[]
|
||||
}
|
||||
|
||||
export class AdminGetRegionsRegionFulfillmentOptionsRes {
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
import { getListConfig, pickByConfig } from "./utils/get-query-config"
|
||||
import {
|
||||
IsArray,
|
||||
ValidateNested,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from "class-validator"
|
||||
import { IsArray, IsNumber, IsOptional, IsString } from "class-validator"
|
||||
import { Type } from "class-transformer"
|
||||
import { omit, pickBy, pick, identity } from "lodash"
|
||||
import { omit, pickBy, identity } from "lodash"
|
||||
|
||||
import { TaxRate } from "../../../.."
|
||||
import {
|
||||
NumericalComparisonOperator,
|
||||
FindConfig,
|
||||
} from "../../../../types/common"
|
||||
import { NumericalComparisonOperator } from "../../../../types/common"
|
||||
import { TaxRateService } from "../../../../services"
|
||||
import { IsType } from "../../../../utils/validators/is-type"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
@@ -23,7 +23,7 @@ export default (app) => {
|
||||
}
|
||||
|
||||
export type AdminUploadRes = {
|
||||
uploads: any[]
|
||||
uploads: unknown[]
|
||||
}
|
||||
|
||||
export type AdminDeleteUploadRes = DeleteResponse
|
||||
|
||||
@@ -43,7 +43,7 @@ export default async (req, res) => {
|
||||
// Add JWT to cookie
|
||||
req.session.jwt = jwt.sign(
|
||||
{ customer_id: result.customer?.id },
|
||||
(config as any).jwtSecret,
|
||||
config.jwtSecret as string,
|
||||
{
|
||||
expiresIn: "30d",
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ export type StoreProductsRes = {
|
||||
}
|
||||
|
||||
export type StorePostSearchRes = {
|
||||
hits: any[]
|
||||
[k: string]: any
|
||||
hits: unknown[]
|
||||
[k: string]: unknown
|
||||
}
|
||||
|
||||
export type StoreProductsListRes = PaginatedResponse & {
|
||||
|
||||
@@ -42,5 +42,5 @@ export class StorePostSearchReq {
|
||||
limit?: number
|
||||
|
||||
@IsOptional()
|
||||
filter?: any
|
||||
filter?: unknown
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export default async (req, res) => {
|
||||
)
|
||||
|
||||
// should be selector
|
||||
const query: any = {}
|
||||
const query: Record<string, unknown> = {}
|
||||
|
||||
if ("is_return" in req.query) {
|
||||
query.is_return = validated.is_return === "true"
|
||||
|
||||
@@ -15,6 +15,7 @@ import OrderService from "../../../../services/order"
|
||||
import ReturnService from "../../../../services/return"
|
||||
import SwapService from "../../../../services/swap"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /swaps
|
||||
@@ -182,10 +183,12 @@ export default async (req, res) => {
|
||||
case "swap_created": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async (manager) => {
|
||||
const swaps = await swapService.list({
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
})
|
||||
async (transactionManager: EntityManager) => {
|
||||
const swaps = await swapService
|
||||
.withTransaction(transactionManager)
|
||||
.list({
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
})
|
||||
|
||||
if (!swaps.length) {
|
||||
throw new MedusaError(
|
||||
@@ -194,10 +197,12 @@ export default async (req, res) => {
|
||||
)
|
||||
}
|
||||
|
||||
const swap = await swapService.retrieve(swaps[0].id, {
|
||||
select: defaultStoreSwapFields,
|
||||
relations: defaultStoreSwapRelations,
|
||||
})
|
||||
const swap = await swapService
|
||||
.withTransaction(transactionManager)
|
||||
.retrieve(swaps[0].id, {
|
||||
select: defaultStoreSwapFields,
|
||||
relations: defaultStoreSwapRelations,
|
||||
})
|
||||
|
||||
return {
|
||||
response_code: 200,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { omit, pickBy } from "lodash"
|
||||
import { AdminGetCustomersParams } from "../../api/routes/admin/customers/list-customers"
|
||||
import { AdminGetCustomersParams } from "../../api/routes/admin/customers"
|
||||
import { AdminCustomersListRes } from "../../api"
|
||||
import { CustomerService } from "../../services"
|
||||
import { FindConfig } from "../../types/common"
|
||||
@@ -9,8 +9,7 @@ import { Customer } from "../../models/customer"
|
||||
const listAndCount = async (
|
||||
scope,
|
||||
query,
|
||||
body,
|
||||
context = {}
|
||||
body
|
||||
): Promise<AdminCustomersListRes> => {
|
||||
const validatedQueryParams = await validator(AdminGetCustomersParams, query)
|
||||
|
||||
|
||||
@@ -1190,7 +1190,7 @@ class CartService extends BaseService {
|
||||
*/
|
||||
async authorizePayment(
|
||||
cartId: string,
|
||||
context: Record<string, any> = {}
|
||||
context: Record<string, unknown> = {}
|
||||
): Promise<Cart> {
|
||||
return this.atomicPhase_(async (manager: EntityManager) => {
|
||||
const cartRepository = manager.getCustomRepository(this.cartRepository_)
|
||||
@@ -1500,7 +1500,7 @@ class CartService extends BaseService {
|
||||
async addShippingMethod(
|
||||
cartId: string,
|
||||
optionId: string,
|
||||
data: Record<string, any> = {}
|
||||
data: Record<string, unknown> = {}
|
||||
): Promise<Cart> {
|
||||
return this.atomicPhase_(async (manager: EntityManager) => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
|
||||
@@ -654,7 +654,7 @@ class DiscountService extends BaseService {
|
||||
resolvedConditionType.type
|
||||
)
|
||||
},
|
||||
async (err: any) => {
|
||||
async (err: { code: string }) => {
|
||||
if (err.code === PostgresError.DUPLICATE_ERROR) {
|
||||
// A unique key constraint failed meaning the combination of
|
||||
// discount rule id, type, and operator already exists in the db.
|
||||
|
||||
@@ -257,7 +257,7 @@ class InviteService extends BaseService {
|
||||
)
|
||||
}
|
||||
|
||||
async resend(id): Promise<any> {
|
||||
async resend(id): Promise<void> {
|
||||
const inviteRepo = this.manager_.getCustomRepository(InviteRepository)
|
||||
|
||||
const invite = await inviteRepo.findOne({ id })
|
||||
|
||||
@@ -188,9 +188,8 @@ class OrderService extends BaseService {
|
||||
const orderRepo = this.manager_.getCustomRepository(this.orderRepository_)
|
||||
const query = this.buildQuery_(selector, config)
|
||||
|
||||
const { select, relations, totalsToSelect } = this.transformQueryForTotals_(
|
||||
config
|
||||
)
|
||||
const { select, relations, totalsToSelect } =
|
||||
this.transformQueryForTotals_(config)
|
||||
|
||||
if (select && select.length) {
|
||||
query.select = select
|
||||
@@ -249,9 +248,8 @@ class OrderService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
const { select, relations, totalsToSelect } = this.transformQueryForTotals_(
|
||||
config
|
||||
)
|
||||
const { select, relations, totalsToSelect } =
|
||||
this.transformQueryForTotals_(config)
|
||||
|
||||
if (select && select.length) {
|
||||
query.select = select
|
||||
@@ -341,9 +339,8 @@ class OrderService extends BaseService {
|
||||
const orderRepo = this.manager_.getCustomRepository(this.orderRepository_)
|
||||
const validatedId = this.validateId_(orderId)
|
||||
|
||||
const { select, relations, totalsToSelect } = this.transformQueryForTotals_(
|
||||
config
|
||||
)
|
||||
const { select, relations, totalsToSelect } =
|
||||
this.transformQueryForTotals_(config)
|
||||
|
||||
const query = {
|
||||
where: { id: validatedId },
|
||||
@@ -379,9 +376,8 @@ class OrderService extends BaseService {
|
||||
async retrieveByCartId(cartId, config = {}) {
|
||||
const orderRepo = this.manager_.getCustomRepository(this.orderRepository_)
|
||||
|
||||
const { select, relations, totalsToSelect } = this.transformQueryForTotals_(
|
||||
config
|
||||
)
|
||||
const { select, relations, totalsToSelect } =
|
||||
this.transformQueryForTotals_(config)
|
||||
|
||||
const query = {
|
||||
where: { cart_id: cartId },
|
||||
@@ -417,9 +413,8 @@ class OrderService extends BaseService {
|
||||
async retrieveByExternalId(externalId, config = {}) {
|
||||
const orderRepo = this.manager_.getCustomRepository(this.orderRepository_)
|
||||
|
||||
const { select, relations, totalsToSelect } = this.transformQueryForTotals_(
|
||||
config
|
||||
)
|
||||
const { select, relations, totalsToSelect } =
|
||||
this.transformQueryForTotals_(config)
|
||||
|
||||
const query = {
|
||||
where: { external_id: externalId },
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { JsonWebTokenError } from "jsonwebtoken"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { Brackets, EntityManager, ILike, SelectQueryBuilder } from "typeorm"
|
||||
|
||||
@@ -422,9 +422,8 @@ class ReturnService extends BaseService {
|
||||
}
|
||||
)
|
||||
|
||||
const calculationContext = this.totalsService_.getCalculationContext(
|
||||
order
|
||||
)
|
||||
const calculationContext =
|
||||
this.totalsService_.getCalculationContext(order)
|
||||
|
||||
const taxLines = await this.taxProviderService_
|
||||
.withTransaction(manager)
|
||||
@@ -496,9 +495,8 @@ class ReturnService extends BaseService {
|
||||
return returnOrder
|
||||
}
|
||||
|
||||
const fulfillmentData = await this.fulfillmentProviderService_.createReturn(
|
||||
returnData
|
||||
)
|
||||
const fulfillmentData =
|
||||
await this.fulfillmentProviderService_.createReturn(returnData)
|
||||
|
||||
returnOrder.shipping_data = fulfillmentData
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import _ from "lodash"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { ITaxCalculationStrategy } from "../interfaces/tax-calculation-strategy"
|
||||
import { TaxCalculationContext } from "../interfaces/tax-service"
|
||||
import { ITaxCalculationStrategy, TaxCalculationContext } from "../interfaces"
|
||||
import { Cart } from "../models/cart"
|
||||
import { Discount } from "../models/discount"
|
||||
import { DiscountRuleType } from "../models/discount-rule"
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
} from "../interfaces/price-selection-strategy"
|
||||
import { MoneyAmountRepository } from "../repositories/money-amount"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
|
||||
class PriceSelectionStrategy extends AbstractPriceSelectionStrategy {
|
||||
private moneyAmountRepository_: typeof MoneyAmountRepository
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
IsBoolean,
|
||||
IsInt,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Validate,
|
||||
|
||||
Reference in New Issue
Block a user