import { Ring } from '../../model/rings'; import { User } from '../../model/user'; const checkAccess = (user: User, ring: Ring, url: string): boolean => { const ringAnswers = user.answers.find((ans) => ans.ring.id === ring.id); const phase = ringAnswers?.phase || 0; if (url.includes('trivial') && phase !== 1) { return false; } if (url.includes('challenge') && phase !== 2) { return false; } if (url.includes('closure') && phase < 3) { return false; } if (url.includes('event')) { if (ring.order !== 5) { return false; } if (phase !== 3) { return false; } const { startDate, endDate } = ring.closure.info; const today = new Date(); if (new Date(startDate) >= today || new Date(endDate) <= today) { return false; } } if (url.includes('clinicCase')) { if (ring.order !== 5) { return false; } if (phase !== 2) { return false; } const { startDate, endDate } = ring.clinicCase.info; const today = new Date(); if (new Date(startDate) >= today || new Date(endDate) <= today) { return false; } } return true; }; export default checkAccess;