mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: add error commands page
This commit is contained in:
1 parent
d249207283
commit
50e53b5667
6 files changed
+60
-1
No files matched your search
@@ -0,0 +1,9 @@
|
||||
import { errorCommands } from '../models/commands.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function commandListController(req, res) {
|
||||
const payload = {
|
||||
errorCommands: await errorCommands(),
|
||||
}
|
||||
res.render('commands', payload)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Command } from '@linux-odyssey/models'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function errorCommands() {
|
||||
const commands = await Command.find({ error: { $ne: '' } })
|
||||
.populate({
|
||||
path: 'session',
|
||||
populate: [
|
||||
{
|
||||
path: 'user',
|
||||
},
|
||||
{ path: 'quest' },
|
||||
],
|
||||
})
|
||||
.exec()
|
||||
return commands.map(({ command, error, createdAt, session }) => {
|
||||
const { user, quest } = session
|
||||
return {
|
||||
command,
|
||||
error,
|
||||
createdAt: createdAt.toLocaleString(),
|
||||
user: user.username,
|
||||
quest: quest.id,
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2,10 +2,12 @@ import { Router } from 'express'
|
||||
|
||||
import { homeController } from './controllers/index.js'
|
||||
import { userListController } from './controllers/users.js'
|
||||
import { commandListController } from './controllers/commands.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.get('/', homeController)
|
||||
router.get('/users', userListController)
|
||||
router.get('/commands', commandListController)
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,22 @@
|
||||
<h1>Commands</h1>
|
||||
<div>
|
||||
<h2>Error commands</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Command</th>
|
||||
<th>User</th>
|
||||
<th>Quest</th>
|
||||
<th>Error</th>
|
||||
<th>Created At</th>
|
||||
</tr>
|
||||
{{#each errorCommands}}
|
||||
<tr>
|
||||
<td>{{command}}</td>
|
||||
<td>{{user}}</td>
|
||||
<td>{{quest}}</td>
|
||||
<td>{{error}}</td>
|
||||
<td>{{createdAt}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
</div>
|
||||
@@ -1,5 +1,4 @@
|
||||
<h1>Welcome to {{title}}</h1>
|
||||
<p>This is the content of the homepage.</p>
|
||||
<div>
|
||||
<h2>Users</h2>
|
||||
<table>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<ul>
|
||||
<li><a href='/'>Home</a></li>
|
||||
<li><a href='/users'>Users</a></li>
|
||||
<li><a href='/commands'>Commands</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
{{{body}}}
|
||||
|
||||
Reference in new issue
Block a user