fix: make packages/medusa/src/api/routes/admin/auth and 3 others pass eslint (#666)

This commit is contained in:
Audrey Kon
2021-10-26 02:17:42 +08:00
committed by GitHub
parent e97367d26e
commit 95f80f8a66
16 changed files with 112 additions and 184 deletions

View File

@@ -10,7 +10,6 @@
/packages/medusa/src/subscribers/notification.js
/packages/medusa/src/subscribers/order.js
/packages/medusa/src/subscribers/product.js
/packages/medusa/src/loaders/api.js
/packages/medusa/src/loaders/database.js
/packages/medusa/src/loaders/defaults.js
@@ -24,33 +23,24 @@
/packages/medusa/src/loaders/repositories.js
/packages/medusa/src/loaders/services.js
/packages/medusa/src/loaders/subscribers.js
/packages/medusa/src/api/routes/admin/apps
/packages/medusa/src/api/routes/admin/auth
/packages/medusa/src/api/routes/admin/collections
/packages/medusa/src/api/routes/admin/customers
/packages/medusa/src/api/routes/admin/discounts
/packages/medusa/src/api/routes/admin/draft-orders
/packages/medusa/src/api/routes/admin/notes
/packages/medusa/src/api/routes/admin/notifications
/packages/medusa/src/api/routes/admin/orders
/packages/medusa/src/api/routes/admin/regions
/packages/medusa/src/api/routes/admin/return-reasons
/packages/medusa/src/api/routes/admin/returns
/packages/medusa/src/api/routes/admin/shipping-options
/packages/medusa/src/api/routes/admin/shipping-profiles
/packages/medusa/src/api/routes/admin/store
/packages/medusa/src/api/routes/admin/users
/packages/medusa/src/api/routes/store/carts
/packages/medusa/src/api/routes/store/regions
/packages/medusa/src/api/routes/store/return-reasons
/packages/medusa/src/api/routes/store/returns
/packages/medusa/src/api/routes/store/swaps
# END OF FILES TODO
@@ -61,7 +51,6 @@
/packages/medusa/src/helpers
/packages/medusa/src/migrations
/packages/medusa/src/utils
/integration-tests
/docs
/docs-util

View File

@@ -39,17 +39,13 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const regionService = req.scope.resolve("regionService")
await regionService.addCountry(region_id, value.country_code)
const regionService = req.scope.resolve("regionService")
await regionService.addCountry(region_id, value.country_code)
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region })
} catch (err) {
throw err
}
res.status(200).json({ region })
}

View File

@@ -39,16 +39,12 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const regionService = req.scope.resolve("regionService")
await regionService.addFulfillmentProvider(region_id, value.provider_id)
const regionService = req.scope.resolve("regionService")
await regionService.addFulfillmentProvider(region_id, value.provider_id)
const data = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region: data })
} catch (err) {
throw err
}
const data = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region: data })
}

View File

@@ -39,16 +39,12 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const regionService = req.scope.resolve("regionService")
await regionService.addPaymentProvider(region_id, value.provider_id)
const regionService = req.scope.resolve("regionService")
await regionService.addPaymentProvider(region_id, value.provider_id)
const data = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region: data })
} catch (err) {
throw err
}
const data = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region: data })
}

View File

@@ -66,17 +66,13 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const regionService = req.scope.resolve("regionService")
const result = await regionService.create(value)
const regionService = req.scope.resolve("regionService")
const result = await regionService.create(value)
const region = await regionService.retrieve(result.id, {
select: defaultFields,
relations: defaultRelations,
})
const region = await regionService.retrieve(result.id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region })
} catch (err) {
throw err
}
res.status(200).json({ region })
}

View File

@@ -23,17 +23,13 @@ import { defaultRelations, defaultFields } from "./"
export default async (req, res) => {
const { id, key } = req.params
try {
const regionService = req.scope.resolve("regionService")
await regionService.deleteMetadata(id, key)
const regionService = req.scope.resolve("regionService")
await regionService.deleteMetadata(id, key)
const region = await regionService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
const region = await regionService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region })
} catch (err) {
throw err
}
res.status(200).json({ region })
}

View File

@@ -1,5 +1,3 @@
import { MedusaError, Validator } from "medusa-core-utils"
/**
* @oas [delete] /regions/{id}
* operationId: "DeleteRegionsRegion"
@@ -27,16 +25,12 @@ import { MedusaError, Validator } from "medusa-core-utils"
*/
export default async (req, res) => {
const { region_id } = req.params
try {
const regionService = req.scope.resolve("regionService")
await regionService.delete(region_id)
const regionService = req.scope.resolve("regionService")
await regionService.delete(region_id)
res.status(200).json({
id: region_id,
object: "region",
deleted: true,
})
} catch (err) {
throw err
}
res.status(200).json({
id: region_id,
object: "region",
deleted: true,
})
}

View File

@@ -22,25 +22,21 @@
export default async (req, res) => {
const { region_id } = req.params
try {
const fulfillmentProviderService = req.scope.resolve(
"fulfillmentProviderService"
)
const regionService = req.scope.resolve("regionService")
const region = await regionService.retrieve(region_id, {
relations: ["fulfillment_providers"],
})
const fulfillmentProviderService = req.scope.resolve(
"fulfillmentProviderService"
)
const regionService = req.scope.resolve("regionService")
const region = await regionService.retrieve(region_id, {
relations: ["fulfillment_providers"],
})
const fpsIds = region.fulfillment_providers.map(fp => fp.id) || []
const fpsIds = region.fulfillment_providers.map((fp) => fp.id) || []
const options = await fulfillmentProviderService.listFulfillmentOptions(
fpsIds
)
const options = await fulfillmentProviderService.listFulfillmentOptions(
fpsIds
)
res.status(200).json({
fulfillment_options: options,
})
} catch (err) {
throw err
}
res.status(200).json({
fulfillment_options: options,
})
}

View File

@@ -1,4 +1,3 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
@@ -22,15 +21,11 @@ import { defaultRelations, defaultFields } from "./"
*/
export default async (req, res) => {
const { region_id } = req.params
try {
const regionService = req.scope.resolve("regionService")
const data = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
const regionService = req.scope.resolve("regionService")
const data = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region: data })
} catch (err) {
throw err
}
res.status(200).json({ region: data })
}

View File

@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
const route = Router()
export default app => {
export default (app) => {
app.use("/regions", route)
route.get("/", middlewares.wrap(require("./list-regions").default))

View File

@@ -20,25 +20,21 @@ import { defaultFields, defaultRelations } from "./"
* $ref: "#/components/schemas/region"
*/
export default async (req, res) => {
try {
const regionService = req.scope.resolve("regionService")
const regionService = req.scope.resolve("regionService")
const limit = parseInt(req.query.limit) || 50
const offset = parseInt(req.query.offset) || 0
const limit = parseInt(req.query.limit) || 50
const offset = parseInt(req.query.offset) || 0
const selector = {}
const selector = {}
const listConfig = {
select: defaultFields,
relations: defaultRelations,
skip: offset,
take: limit,
}
let regions = await regionService.list(selector, listConfig)
res.json({ regions, count: regions.length, offset, limit })
} catch (err) {
throw err
const listConfig = {
select: defaultFields,
relations: defaultRelations,
skip: offset,
take: limit,
}
const regions = await regionService.list(selector, listConfig)
res.json({ regions, count: regions.length, offset, limit })
}

View File

@@ -1,4 +1,3 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
@@ -23,17 +22,13 @@ import { defaultRelations, defaultFields } from "./"
*/
export default async (req, res) => {
const { region_id, country_code } = req.params
try {
const regionService = req.scope.resolve("regionService")
await regionService.removeCountry(region_id, country_code)
const regionService = req.scope.resolve("regionService")
await regionService.removeCountry(region_id, country_code)
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.json({ region })
} catch (err) {
throw err
}
res.json({ region })
}

View File

@@ -1,4 +1,3 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
@@ -23,18 +22,14 @@ import { defaultRelations, defaultFields } from "./"
*/
export default async (req, res) => {
const { region_id, provider_id } = req.params
try {
const regionService = req.scope.resolve("regionService")
const regionService = req.scope.resolve("regionService")
await regionService.removeFulfillmentProvider(region_id, provider_id)
await regionService.removeFulfillmentProvider(region_id, provider_id)
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.json({ region })
} catch (err) {
throw err
}
res.json({ region })
}

View File

@@ -1,4 +1,3 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultRelations, defaultFields } from "./"
/**
@@ -23,17 +22,13 @@ import { defaultRelations, defaultFields } from "./"
*/
export default async (req, res) => {
const { region_id, provider_id } = req.params
try {
const regionService = req.scope.resolve("regionService")
await regionService.removePaymentProvider(region_id, provider_id)
const regionService = req.scope.resolve("regionService")
await regionService.removePaymentProvider(region_id, provider_id)
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.json({ region })
} catch (err) {
throw err
}
res.json({ region })
}

View File

@@ -1,4 +1,5 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "."
export default async (req, res) => {
const { id } = req.params
@@ -13,17 +14,13 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const regionService = req.scope.resolve("regionService")
await regionService.setMetadata(id, value.key, value.value)
const regionService = req.scope.resolve("regionService")
await regionService.setMetadata(id, value.key, value.value)
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
const region = await regionService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region })
} catch (err) {
throw err
}
res.status(200).json({ region })
}

View File

@@ -70,16 +70,12 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const regionService = req.scope.resolve("regionService")
await regionService.update(region_id, value)
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
const regionService = req.scope.resolve("regionService")
await regionService.update(region_id, value)
const region = await regionService.retrieve(region_id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ region })
} catch (err) {
throw err
}
res.status(200).json({ region })
}