fix: make /api/routes/admin/gift-cards,routes/store/gift-cards,/routes/store/orders pass linting (#643)

This commit is contained in:
timothy22000
2021-10-25 08:00:22 +02:00
committed by GitHub
parent 82eee77610
commit 60e943260b
8 changed files with 59 additions and 92 deletions
+2 -3
View File
@@ -32,7 +32,7 @@
/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/gift-cards
/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
@@ -50,9 +50,8 @@
/packages/medusa/src/api/routes/store/auth /packages/medusa/src/api/routes/store/auth
/packages/medusa/src/api/routes/store/carts /packages/medusa/src/api/routes/store/carts
/packages/medusa/src/api/routes/store/customers /packages/medusa/src/api/routes/store/customers
/packages/medusa/src/api/routes/store/gift-cards
/packages/medusa/src/api/routes/store/orders
/packages/medusa/src/api/routes/store/products /packages/medusa/src/api/routes/store/products
/packages/medusa/src/api/routes/store/regions /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
@@ -43,9 +43,7 @@ import { defaultFields, defaultRelations } from "./"
*/ */
export default async (req, res) => { export default async (req, res) => {
const schema = Validator.object().keys({ const schema = Validator.object().keys({
value: Validator.number() value: Validator.number().integer().optional(),
.integer()
.optional(),
ends_at: Validator.date().optional(), ends_at: Validator.date().optional(),
is_disabled: Validator.boolean().optional(), is_disabled: Validator.boolean().optional(),
region_id: Validator.string().optional(), region_id: Validator.string().optional(),
@@ -57,21 +55,17 @@ 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 giftCardService = req.scope.resolve("giftCardService")
const giftCardService = req.scope.resolve("giftCardService")
const newly = await giftCardService.create({ const newly = await giftCardService.create({
...value, ...value,
balance: value.value, balance: value.value,
}) })
const giftCard = await giftCardService.retrieve(newly.id, { const giftCard = await giftCardService.retrieve(newly.id, {
select: defaultFields, select: defaultFields,
relations: defaultRelations, relations: defaultRelations,
}) })
res.status(200).json({ gift_card: giftCard }) res.status(200).json({ gift_card: giftCard })
} catch (err) {
throw err
}
} }
@@ -26,16 +26,12 @@
export default async (req, res) => { export default async (req, res) => {
const { id } = req.params const { id } = req.params
try { const giftCardService = req.scope.resolve("giftCardService")
const giftCardService = req.scope.resolve("giftCardService") await giftCardService.delete(id)
await giftCardService.delete(id)
res.json({ res.json({
id, id,
object: "gift-card", object: "gift-card",
deleted: true, deleted: true,
}) })
} catch (err) {
throw err
}
} }
@@ -22,15 +22,11 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => { export default async (req, res) => {
const { id } = req.params const { id } = req.params
try { const giftCardService = req.scope.resolve("giftCardService")
const giftCardService = req.scope.resolve("giftCardService") const giftCard = await giftCardService.retrieve(id, {
const giftCard = await giftCardService.retrieve(id, { select: defaultFields,
select: defaultFields, relations: defaultRelations,
relations: defaultRelations, })
})
res.status(200).json({ gift_card: giftCard }) res.status(200).json({ gift_card: giftCard })
} catch (err) {
throw err
}
} }
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
const route = Router() const route = Router()
export default app => { export default (app) => {
app.use("/gift-cards", route) app.use("/gift-cards", route)
route.get("/", middlewares.wrap(require("./list-gift-cards").default)) route.get("/", middlewares.wrap(require("./list-gift-cards").default))
@@ -33,10 +33,7 @@ export const defaultFields = [
"metadata", "metadata",
] ]
export const defaultRelations = [ export const defaultRelations = ["region", "order"]
"region",
"order",
]
export const allowedFields = [ export const allowedFields = [
"id", "id",
@@ -1,4 +1,3 @@
import { MedusaError, Validator } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./" import { defaultFields, defaultRelations } from "./"
/** /**
@@ -21,28 +20,24 @@ import { defaultFields, defaultRelations } from "./"
* $ref: "#/components/schemas/gift_card" * $ref: "#/components/schemas/gift_card"
*/ */
export default async (req, res) => { export default async (req, res) => {
try { 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 = {}
if ("q" in req.query) { if ("q" in req.query) {
selector.q = req.query.q selector.q = req.query.q
}
const giftCardService = req.scope.resolve("giftCardService")
const giftCards = await giftCardService.list(selector, {
select: defaultFields,
relations: defaultRelations,
order: { created_at: "DESC" },
limit: limit,
skip: offset,
})
res.status(200).json({ gift_cards: giftCards })
} catch (err) {
throw err
} }
const giftCardService = req.scope.resolve("giftCardService")
const giftCards = await giftCardService.list(selector, {
select: defaultFields,
relations: defaultRelations,
order: { created_at: "DESC" },
limit: limit,
skip: offset,
})
res.status(200).json({ gift_cards: giftCards })
} }
@@ -47,9 +47,7 @@ export default async (req, res) => {
const { id } = req.params const { id } = req.params
const schema = Validator.object().keys({ const schema = Validator.object().keys({
balance: Validator.number() balance: Validator.number().precision(0).optional(),
.precision(0)
.optional(),
ends_at: Validator.date().optional(), ends_at: Validator.date().optional(),
is_disabled: Validator.boolean().optional(), is_disabled: Validator.boolean().optional(),
region_id: Validator.string().optional(), region_id: Validator.string().optional(),
@@ -61,18 +59,14 @@ 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 giftCardService = req.scope.resolve("giftCardService")
const giftCardService = req.scope.resolve("giftCardService")
await giftCardService.update(id, value) await giftCardService.update(id, value)
const giftCard = await giftCardService.retrieve(id, { const giftCard = await giftCardService.retrieve(id, {
select: defaultFields, select: defaultFields,
relations: defaultRelations, relations: defaultRelations,
}) })
res.status(200).json({ gift_card: giftCard }) res.status(200).json({ gift_card: giftCard })
} catch (err) {
throw err
}
} }
@@ -22,15 +22,11 @@ import { defaultFields, defaultRelations } from "."
export default async (req, res) => { export default async (req, res) => {
const { cart_id } = req.params const { cart_id } = req.params
try { const orderService = req.scope.resolve("orderService")
const orderService = req.scope.resolve("orderService") const order = await orderService.retrieveByCartId(cart_id, {
const order = await orderService.retrieveByCartId(cart_id, { select: defaultFields,
select: defaultFields, relations: defaultRelations,
relations: defaultRelations, })
})
res.json({ order }) res.json({ order })
} catch (error) {
throw error
}
} }