mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
30 lines
939 B
TypeScript
30 lines
939 B
TypeScript
import { Request, Response } from 'express'
|
|
import Pagination from '../models/pagination.js'
|
|
import { sessionList, sessionDetail } from '../models/sessions.js'
|
|
|
|
export async function sessionListController(req: Request, res: Response) {
|
|
const { nextKey, order } = req.query as { nextKey: string; order: string }
|
|
const itemsPerPage = 50
|
|
|
|
try {
|
|
const pagination = new Pagination(order, itemsPerPage, nextKey)
|
|
const sessions = await sessionList(pagination)
|
|
const newNextKey = sessions[sessions.length - 1]?._id
|
|
|
|
res.render('sessions', {
|
|
sessions,
|
|
nextKey: newNextKey,
|
|
order: pagination.getOrder(),
|
|
})
|
|
} catch (error) {
|
|
console.log(error)
|
|
res.status(500).send('Error fetching session data')
|
|
}
|
|
}
|
|
|
|
export async function sessionDetailController(req: Request, res: Response) {
|
|
const { id } = req.params
|
|
const session = await sessionDetail(id)
|
|
res.render('sessionDetail', { session })
|
|
}
|