fix(medusa): Lint and missing transaction usage (#1297)

This commit is contained in:
Adrien de Peretti
2022-04-03 21:01:43 +02:00
committed by GitHub
parent b164977a19
commit ab2d81f786
30 changed files with 68 additions and 81 deletions
@@ -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,