@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
45 lines (42 loc) • 1.44 kB
JavaScript
import logger from '../utils/logger.js';
class ReportDataStore {
redisClient;
prefix;
constructor(redisClient, prefix = 'dprReportStoreUser:') {
this.redisClient = redisClient;
redisClient.on('error', error => {
logger.error(error, `Redis error`);
});
this.prefix = prefix;
}
async ensureConnected() {
if (!this.redisClient.isOpen) {
await this.redisClient.connect();
}
}
async setUserConfig(userId, config) {
await this.ensureConnected();
await this.redisClient.set(`${this.prefix}${userId}`, JSON.stringify(config));
}
async getUserConfig(userId) {
await this.ensureConnected();
const userConfig = await this.redisClient.get(`${this.prefix}${userId}`);
return userConfig ? JSON.parse(String(userConfig)) : this.setBaseplate(userId);
}
async setBaseplate(userId) {
logger.info(`Initialising new DPR user config in store. prefix: ${this.prefix}`);
const userConfig = { ...baseplateStore };
await this.setUserConfig(userId, userConfig);
return { ...baseplateStore };
}
}
const baseplateStore = {
requestedReports: [],
recentlyViewedReports: [],
bookmarks: [],
subscriptions: [],
downloadPermissions: [],
defaultFilters: [],
};
export { ReportDataStore, ReportDataStore as default };
//# sourceMappingURL=reportDataStore.js.map