@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
99 lines (95 loc) • 2.83 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
const getValues = (res) => {
const csrfToken = res.locals['csrfToken'] || 'csrfToken';
const dprUser = setDprUserContext(res);
return {
token: dprUser.token,
dprUser,
...setUserReports(res),
...setDpdPaths(res),
...setFeatures(res),
...setDefinitions(res),
csrfToken,
};
};
const setDefinitions = (res) => {
const definitions = res.locals['definitions'] || [];
return {
definitions,
};
};
const setFeatures = (res) => {
return {
bookmarkingEnabled: res.app.locals['bookmarkingEnabled'],
downloadingEnabled: res.app.locals['downloadingEnabled'],
saveDefaultsEnabled: res.app.locals['saveDefaultsEnabled'],
subscriptionsEnabled: res.app.locals['subscriptionsEnabled'],
requestMissingEnabled: res.app.locals['requestMissingEnabled'],
collectionsEnabled: res.app.locals['collectionsEnabled'],
};
};
const setUserReports = (res) => {
const requestedReports = res.locals['requestedReports'] || [];
const recentlyViewedReports = res.locals['recentlyViewedReports'] || [];
const bookmarks = res.locals['bookmarks'] || [];
const subscriptions = res.locals['subscriptions'] || [];
return {
requestedReports,
recentlyViewedReports,
bookmarks,
subscriptions,
};
};
const setDpdPaths = (res) => {
const { definitionsPath, dpdPathFromQuery, dpdPathFromConfig, pathSuffix } = res.locals;
return {
definitionsPath,
dpdPathFromQuery,
dpdPathFromConfig,
pathSuffix: pathSuffix || '',
};
};
const setDprUserContext = (res) => {
const { dprUser } = res.locals;
const id = dprUser?.id;
const token = dprUser?.token;
const activeCaseLoadId = dprUser?.activeCaseLoadId;
const staffId = dprUser?.staffId;
const email = dprUser?.emailAddress || '';
const displayName = dprUser?.displayName || '';
return {
id,
token,
activeCaseLoadId,
staffId,
email,
displayName,
};
};
const setDdpPathToReqQuery = (req, value) => {
if (value) {
req.query = {
...req.query,
dataProductDefinitionsPath: value,
};
}
return req.query;
};
const getRouteLocals = (res) => {
const locals = res.app.locals.dprPaths;
if (!locals) {
throw new Error('Dpr Library Path locals not initialized');
}
return locals;
};
var localsHelper = {
getValues,
getRouteLocals,
setDdpPathToReqQuery,
};
exports.default = localsHelper;
exports.getRouteLocals = getRouteLocals;
exports.getValues = getValues;
exports.setDdpPathToReqQuery = setDdpPathToReqQuery;
//# sourceMappingURL=localsHelper.js.map