@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
50 lines (44 loc) • 1.47 kB
text/typescript
import type { Response, Request } from 'express'
import { StoredReportData } from '../types/UserReports'
import { BookmarkStoreData } from '../types/Bookmark'
const getValues = (res: Response) => {
const csrfToken = (res.locals.csrfToken as unknown as string) || 'csrfToken'
const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
const token = res.locals.user?.token ? res.locals.user.token : 'token'
const pathSuffix = res.locals.pathSuffix || ''
const routePrefix = res.locals.routePrefix || ''
const definitions = res.locals.definitions || []
const requestedReports: StoredReportData[] = res.locals.requestedReports || []
const recentlyViewedReports: StoredReportData[] = res.locals.recentlyViewedReports || []
const bookmarks: BookmarkStoreData[] = res.locals.bookmarks || []
const { bookmarkingEnabled, downloadingEnabled, definitionsPath, dpdPathFromQuery, dpdPathFromConfig } = res.locals
return {
csrfToken,
userId,
token,
definitions,
requestedReports,
recentlyViewedReports,
bookmarks,
bookmarkingEnabled,
downloadingEnabled,
dpdPathFromQuery,
dpdPathFromConfig,
definitionsPath,
pathSuffix,
routePrefix,
}
}
const setDdpPathToReqQuery = (req: Request, value: string) => {
if (value) {
req.query = {
...req.query,
dataProductDefinitionsPath: value,
}
}
return req.query
}
export default {
getValues,
setDdpPathToReqQuery,
}