index.ts
1import { Request, Response } from 'express';
2import constants from '../constants';
3import RequestWithSession from '../interfaces/RequestWithSession';
4import { eventEmitter } from '../utils/reminder';
5
6interface Options {
7 title: string;
8 [key: string]: any;
9}
10
11let reminders: any[] = [];
12
13eventEmitter.on('reminder', (reminder) => {
14 reminders.push(reminder);
15});
16
17export async function render(
18 req: Request | RequestWithSession,
19 res: Response,
20 page: string,
21 options: Options = { title: '' },
22): Promise<void> {
23 const userData = req.session?.user;
24
25 const filteredReminders = reminders.filter(
26 (reminder: any) => reminder.role === (userData ? userData.role : 'user'),
27 );
28
29 res.render(page, {
30 ...options,
31 ...constants,
32 userData: userData || null,
33 reminders: filteredReminders,
34 });
35}
36