chore: Make packages/medusa/src/api/routes/admin/notifications pass linting (#675)
Co-authored-by: Nicholas Ni <nicholas_ni@intuit.com>
This commit is contained in:
1 parent
95f80f8a66
commit
25ed7dc056
4 files changed
+65
-74
No files matched your search
@@ -30,7 +30,6 @@
|
|||||||
/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/orders
|
/packages/medusa/src/api/routes/admin/orders
|
||||||
/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
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
|||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
export default app => {
|
export default (app) => {
|
||||||
app.use("/notifications", route)
|
app.use("/notifications", route)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,63 +21,59 @@ import { defaultRelations, defaultFields } from "./"
|
|||||||
* $ref: "#/components/schemas/notification"
|
* $ref: "#/components/schemas/notification"
|
||||||
*/
|
*/
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
const notificationService = req.scope.resolve("notificationService")
|
||||||
const notificationService = req.scope.resolve("notificationService")
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
let selector = {}
|
const selector = {}
|
||||||
|
|
||||||
let includeFields = []
|
let includeFields = []
|
||||||
if ("fields" in req.query) {
|
if ("fields" in req.query) {
|
||||||
includeFields = req.query.fields.split(",")
|
includeFields = req.query.fields.split(",")
|
||||||
}
|
|
||||||
|
|
||||||
let expandFields = []
|
|
||||||
if ("expand" in req.query) {
|
|
||||||
expandFields = req.query.expand.split(",")
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("event_name" in req.query) {
|
|
||||||
const values = req.query.event_name.split(",")
|
|
||||||
selector.event_name = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("resource_type" in req.query) {
|
|
||||||
const values = req.query.resource_type.split(",")
|
|
||||||
selector.resource_type = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("resource_id" in req.query) {
|
|
||||||
const values = req.query.resource_id.split(",")
|
|
||||||
selector.resource_id = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("to" in req.query) {
|
|
||||||
const values = req.query.to.split(",")
|
|
||||||
selector.to = values.length > 1 ? values : values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!("include_resends" in req.query)) {
|
|
||||||
selector.parent_id = null
|
|
||||||
}
|
|
||||||
|
|
||||||
const listConfig = {
|
|
||||||
select: includeFields.length ? includeFields : defaultFields,
|
|
||||||
relations: expandFields.length ? expandFields : defaultRelations,
|
|
||||||
skip: offset,
|
|
||||||
take: limit,
|
|
||||||
order: { created_at: "DESC" },
|
|
||||||
}
|
|
||||||
|
|
||||||
const notifications = await notificationService.list(selector, listConfig)
|
|
||||||
|
|
||||||
const fields = [...listConfig.select, ...listConfig.relations]
|
|
||||||
const data = notifications.map(o => _.pick(o, fields))
|
|
||||||
|
|
||||||
res.json({ notifications: data, offset, limit })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let expandFields = []
|
||||||
|
if ("expand" in req.query) {
|
||||||
|
expandFields = req.query.expand.split(",")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("event_name" in req.query) {
|
||||||
|
const values = req.query.event_name.split(",")
|
||||||
|
selector.event_name = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("resource_type" in req.query) {
|
||||||
|
const values = req.query.resource_type.split(",")
|
||||||
|
selector.resource_type = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("resource_id" in req.query) {
|
||||||
|
const values = req.query.resource_id.split(",")
|
||||||
|
selector.resource_id = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("to" in req.query) {
|
||||||
|
const values = req.query.to.split(",")
|
||||||
|
selector.to = values.length > 1 ? values : values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!("include_resends" in req.query)) {
|
||||||
|
selector.parent_id = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const listConfig = {
|
||||||
|
select: includeFields.length ? includeFields : defaultFields,
|
||||||
|
relations: expandFields.length ? expandFields : defaultRelations,
|
||||||
|
skip: offset,
|
||||||
|
take: limit,
|
||||||
|
order: { created_at: "DESC" },
|
||||||
|
}
|
||||||
|
|
||||||
|
const notifications = await notificationService.list(selector, listConfig)
|
||||||
|
|
||||||
|
const fields = [...listConfig.select, ...listConfig.relations]
|
||||||
|
const data = notifications.map((o) => _.pick(o, fields))
|
||||||
|
|
||||||
|
res.json({ notifications: data, offset, limit })
|
||||||
}
|
}
|
||||||
@@ -32,24 +32,20 @@ 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 notificationService = req.scope.resolve("notificationService")
|
||||||
const notificationService = req.scope.resolve("notificationService")
|
|
||||||
|
|
||||||
const config = {}
|
const config = {}
|
||||||
|
|
||||||
if (value.to) {
|
if (value.to) {
|
||||||
config.to = value.to
|
config.to = value.to
|
||||||
}
|
|
||||||
|
|
||||||
await notificationService.resend(id, config)
|
|
||||||
|
|
||||||
const notification = await notificationService.retrieve(id, {
|
|
||||||
select: defaultFields,
|
|
||||||
relations: defaultRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.json({ notification })
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await notificationService.resend(id, config)
|
||||||
|
|
||||||
|
const notification = await notificationService.retrieve(id, {
|
||||||
|
select: defaultFields,
|
||||||
|
relations: defaultRelations,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.json({ notification })
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user