sunrise-cms/handlers/lots-get/previous.ts

31 lines
759 B
TypeScript

import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js'
import { getPreviousLotId } from '../../helpers/functions.lots.js'
export async function handler(
request: Request,
response: Response
): Promise<void> {
const lotId = Number.parseInt(request.params.lotId, 10)
const previousLotId = await getPreviousLotId(lotId)
if (previousLotId === undefined) {
response.redirect(
`${configFunctions.getConfigProperty(
'reverseProxy.urlPrefix'
)}/lots/?error=noPreviousLotIdFound`
)
return
}
response.redirect(
`${configFunctions.getConfigProperty(
'reverseProxy.urlPrefix'
)}/lots/${previousLotId.toString()}`
)
}
export default handler