sunrise-cms/handlers/maps-get/next.ts

29 lines
683 B
TypeScript

import type { Request, Response } from 'express'
import getNextMapId from '../../database/getNextMapId.js'
import { getConfigProperty } from '../../helpers/functions.config.js'
export default async function handler(
request: Request,
response: Response
): Promise<void> {
const mapId = Number.parseInt(request.params.mapId, 10)
const nextMapId = await getNextMapId(mapId)
if (nextMapId === undefined) {
response.redirect(
`${getConfigProperty(
'reverseProxy.urlPrefix'
)}/maps/?error=noNextMapIdFound`
)
return
}
response.redirect(
`${getConfigProperty(
'reverseProxy.urlPrefix'
)}/maps/${nextMapId.toString()}`
)
}