( request: FastifyRequestTypebox<typeof GetHealthCheckDataSchema>, reply: FastifyReplyTypebox<typeof GetHealthCheckDataSchema>, )
| 45 | */ |
| 46 | |
| 47 | export const getHealthCheckData = async ( |
| 48 | request: FastifyRequestTypebox<typeof GetHealthCheckDataSchema>, |
| 49 | reply: FastifyReplyTypebox<typeof GetHealthCheckDataSchema>, |
| 50 | ) => { |
| 51 | try { |
| 52 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 53 | // @ts-ignore |
| 54 | const { startDate, endDate } = request.query; |
| 55 | const endDatePlus1 = new Date(endDate); |
| 56 | const newStartDate = new Date(startDate); |
| 57 | endDatePlus1.setDate(endDatePlus1.getDate() + 1); |
| 58 | |
| 59 | const data = await request.server.orm.getRepository(ModelHealthCheck).find({ |
| 60 | where: { |
| 61 | lastChecked: Between(newStartDate, endDatePlus1), |
| 62 | }, |
| 63 | order: { |
| 64 | lastChecked: "ASC", |
| 65 | }, |
| 66 | }); |
| 67 | |
| 68 | if (!data) { |
| 69 | return reply.code(404).send({ |
| 70 | message: ERROR_MESSAGES.HEALTH_CHECK_DATA_NOT_FOUND, |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | const res: any = {}; |
| 75 | for (const healthCheck of data) { |
| 76 | const { modelId, lastChecked, isAvailable, latency } = healthCheck; |
| 77 | if (!res[modelId]) { |
| 78 | res[modelId] = []; |
| 79 | } |
| 80 | res[modelId].push({ |
| 81 | time: lastChecked.toISOString(), |
| 82 | isAvailable, |
| 83 | latency, |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | const output = Object.keys(res).map(modelId => ({ |
| 88 | modelId, |
| 89 | data: res[modelId], |
| 90 | })); |
| 91 | |
| 92 | reply.code(200).send(output); |
| 93 | } catch (e: any) { |
| 94 | Sentry.captureException(e); |
| 95 | reply.code(500).send(e); |
| 96 | } |
| 97 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected