cityssm/lottery-licence-manager

View on GitHub
handlers/locations-get/view.js

Summary

Maintainability
A
0 mins
Test Coverage
F
28%
import * as configFunctions from "../../helpers/functions.config.js";
import * as dateTimeFns from "@cityssm/expressjs-server-js/dateTimeFns.js";
import { getLicences } from "../../helpers/licencesDB/getLicences.js";
import { getLocation } from "../../helpers/licencesDB/getLocation.js";
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
export const handler = (request, response, next) => {
    const locationID = Number(request.params.locationID);
    if (Number.isNaN(locationID)) {
        return next();
    }
    const location = getLocation(locationID, request.session);
    if (!location) {
        return response.redirect(urlPrefix + "/locations/?error=locationNotFound");
    }
    const licences = getLicences({
        locationID
    }, request.session, {
        includeOrganization: true,
        limit: -1
    }).licences;
    return response.render("location-view", {
        headTitle: location.locationDisplayName,
        location,
        licences,
        currentDateInteger: dateTimeFns.dateToInteger(new Date())
    });
};
export default handler;