mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
fix: wrap all async controller with error handler
* add validations to newCommand
This commit is contained in:
1 parent
1af85651b8
commit
c2dac8d385
13 files changed
+120
-120
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { Quest } from '@linux-odyssey/models'
|
||||
import { matchedData } from 'express-validator'
|
||||
import { asyncHandler } from '../../middleware/error.js'
|
||||
|
||||
export async function getQuests(req, res) {
|
||||
export const getQuests = asyncHandler(async (req, res) => {
|
||||
const quests = await Quest.find({})
|
||||
res.json(
|
||||
quests.map(({ title, _id, requirements }) => ({
|
||||
@@ -10,9 +11,9 @@ export async function getQuests(req, res) {
|
||||
requirements,
|
||||
}))
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
export async function getQuestDetail(req, res) {
|
||||
export const getQuestDetail = asyncHandler(async (req, res) => {
|
||||
const { questId } = matchedData(req)
|
||||
const quest = await Quest.findById(questId)
|
||||
if (!quest) {
|
||||
@@ -21,4 +22,4 @@ export async function getQuestDetail(req, res) {
|
||||
}
|
||||
const { _id, title, order, instruction } = quest
|
||||
res.json({ _id, title, order, instruction })
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user