mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor quest controller
This commit is contained in:
1 parent
fd543ed594
commit
ac8e9d1cfa
2 files changed
+28
-25
No files matched your search
@@ -1,25 +0,0 @@
|
||||
import { Quest } from '@linux-odyssey/models'
|
||||
import { matchedData } from 'express-validator'
|
||||
import { asyncHandler } from '../../middleware/error.js'
|
||||
|
||||
export const getQuests = asyncHandler(async (req, res) => {
|
||||
const quests = await Quest.find({})
|
||||
res.json(
|
||||
quests.map(({ title, _id, requirements }) => ({
|
||||
_id,
|
||||
title,
|
||||
requirements,
|
||||
}))
|
||||
)
|
||||
})
|
||||
|
||||
export const getQuestDetail = asyncHandler(async (req, res) => {
|
||||
const { questId } = matchedData(req)
|
||||
const quest = await Quest.findById(questId)
|
||||
if (!quest) {
|
||||
res.status(404).json({ message: 'Quest not found.' })
|
||||
return
|
||||
}
|
||||
const { _id, title, order, instruction } = quest
|
||||
res.json({ _id, title, order, instruction })
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Quest } from '@linux-odyssey/models'
|
||||
import { matchedData } from 'express-validator'
|
||||
import type { Request, Response } from 'express'
|
||||
import { asyncHandler } from '../../middleware/error.js'
|
||||
|
||||
export const getQuests = asyncHandler(async (req: Request, res: Response) => {
|
||||
const quests = await Quest.find({})
|
||||
res.json(
|
||||
quests.map(({ title, _id, requirements }) => ({
|
||||
_id,
|
||||
title,
|
||||
requirements,
|
||||
}))
|
||||
)
|
||||
})
|
||||
|
||||
export const getQuestDetail = asyncHandler(
|
||||
async (req: Request, res: Response) => {
|
||||
const { questId } = matchedData(req)
|
||||
const quest = await Quest.findById(questId)
|
||||
if (!quest) {
|
||||
res.status(404).json({ message: 'Quest not found.' })
|
||||
return
|
||||
}
|
||||
const { _id, title, instruction, requirements } = quest
|
||||
res.json({ _id, title, instruction, requirements })
|
||||
}
|
||||
)
|
||||
Reference in new issue
Block a user