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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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