fix: make /api/routes/admin/gift-cards,routes/store/gift-cards,/routes/store/orders pass linting (#643)
This commit is contained in:
+2
-3
@@ -32,7 +32,7 @@
|
||||
/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/gift-cards
|
||||
|
||||
/packages/medusa/src/api/routes/admin/notes
|
||||
/packages/medusa/src/api/routes/admin/notifications
|
||||
/packages/medusa/src/api/routes/admin/orders
|
||||
@@ -50,9 +50,8 @@
|
||||
/packages/medusa/src/api/routes/store/auth
|
||||
/packages/medusa/src/api/routes/store/carts
|
||||
/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/regions
|
||||
/packages/medusa/src/api/routes/store/return-reasons
|
||||
/packages/medusa/src/api/routes/store/returns
|
||||
|
||||
@@ -43,9 +43,7 @@ import { defaultFields, defaultRelations } from "./"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
value: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
value: Validator.number().integer().optional(),
|
||||
ends_at: Validator.date().optional(),
|
||||
is_disabled: Validator.boolean().optional(),
|
||||
region_id: Validator.string().optional(),
|
||||
@@ -57,21 +55,17 @@ export default async (req, res) => {
|
||||
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({
|
||||
...value,
|
||||
balance: value.value,
|
||||
})
|
||||
const newly = await giftCardService.create({
|
||||
...value,
|
||||
balance: value.value,
|
||||
})
|
||||
|
||||
const giftCard = await giftCardService.retrieve(newly.id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
const giftCard = await giftCardService.retrieve(newly.id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
|
||||
res.status(200).json({ gift_card: giftCard })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
res.status(200).json({ gift_card: giftCard })
|
||||
}
|
||||
|
||||
@@ -26,16 +26,12 @@
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const giftCardService = req.scope.resolve("giftCardService")
|
||||
await giftCardService.delete(id)
|
||||
const giftCardService = req.scope.resolve("giftCardService")
|
||||
await giftCardService.delete(id)
|
||||
|
||||
res.json({
|
||||
id,
|
||||
object: "gift-card",
|
||||
deleted: true,
|
||||
})
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
res.json({
|
||||
id,
|
||||
object: "gift-card",
|
||||
deleted: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,15 +22,11 @@ import { defaultFields, defaultRelations } from "./"
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const giftCardService = req.scope.resolve("giftCardService")
|
||||
const giftCard = await giftCardService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
const giftCardService = req.scope.resolve("giftCardService")
|
||||
const giftCard = await giftCardService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
|
||||
res.status(200).json({ gift_card: giftCard })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
res.status(200).json({ gift_card: giftCard })
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default app => {
|
||||
export default (app) => {
|
||||
app.use("/gift-cards", route)
|
||||
|
||||
route.get("/", middlewares.wrap(require("./list-gift-cards").default))
|
||||
@@ -33,10 +33,7 @@ export const defaultFields = [
|
||||
"metadata",
|
||||
]
|
||||
|
||||
export const defaultRelations = [
|
||||
"region",
|
||||
"order",
|
||||
]
|
||||
export const defaultRelations = ["region", "order"]
|
||||
|
||||
export const allowedFields = [
|
||||
"id",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
import { defaultFields, defaultRelations } from "./"
|
||||
|
||||
/**
|
||||
@@ -21,28 +20,24 @@ import { defaultFields, defaultRelations } from "./"
|
||||
* $ref: "#/components/schemas/gift_card"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
try {
|
||||
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 = {}
|
||||
|
||||
if ("q" in req.query) {
|
||||
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
|
||||
if ("q" in req.query) {
|
||||
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 })
|
||||
}
|
||||
|
||||
@@ -47,9 +47,7 @@ export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
balance: Validator.number()
|
||||
.precision(0)
|
||||
.optional(),
|
||||
balance: Validator.number().precision(0).optional(),
|
||||
ends_at: Validator.date().optional(),
|
||||
is_disabled: Validator.boolean().optional(),
|
||||
region_id: Validator.string().optional(),
|
||||
@@ -61,18 +59,14 @@ export default async (req, res) => {
|
||||
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, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
const giftCard = await giftCardService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
|
||||
res.status(200).json({ gift_card: giftCard })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
res.status(200).json({ gift_card: giftCard })
|
||||
}
|
||||
|
||||
@@ -22,15 +22,11 @@ import { defaultFields, defaultRelations } from "."
|
||||
export default async (req, res) => {
|
||||
const { cart_id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const order = await orderService.retrieveByCartId(cart_id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const order = await orderService.retrieveByCartId(cart_id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
res.json({ order })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user