-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforecast-reports.ts
More file actions
69 lines (54 loc) · 2.19 KB
/
Copy pathforecast-reports.ts
File metadata and controls
69 lines (54 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { config } from '../config/config'
import { checkEstofexReport } from '../utilites/estofex'
import { getEstofexImage, getEstofexReport } from '../services/estofex'
import { getTomorrowPretempReport } from '../services/pretemp'
import { sendPhotoMessage } from '../services/telegram'
import { getLastAlertReport, updateLastAlertReport } from '../models/alert-report'
export const registerForecastReportsRoutes = (fastify) => {
fastify.route({
method: 'POST',
url: '/check-pretemp-report',
handler: async (_, reply) => {
const lastAlertReport = await getLastAlertReport()
if (!lastAlertReport.is_critic || lastAlertReport.pretemp_sent) {
return reply.status(204).send(undefined)
}
const tomorrowReport = await getTomorrowPretempReport()
if (!tomorrowReport) {
return reply.status(204).send(undefined)
}
await sendPhotoMessage(config.chat_id, tomorrowReport, 'Nuovo report Pretemp disponibile')
await updateLastAlertReport(
{
pretemp_sent: true,
},
lastAlertReport.id
)
reply.status(204).send(undefined)
},
})
fastify.route({
method: 'POST',
url: '/check-estofex-report',
handler: async (_, reply) => {
const lastAlertReport = await getLastAlertReport()
if (!lastAlertReport.is_critic || lastAlertReport.estofex_sent) {
return reply.status(204).send(undefined)
}
const tomorrowReport = await getEstofexReport()
const isReportValid = checkEstofexReport(tomorrowReport)
if (!isReportValid) {
return reply.status(204).send(undefined)
}
const estofexImage = await getEstofexImage()
await sendPhotoMessage(config.chat_id, estofexImage, 'Nuovo report Estofex disponibile')
await updateLastAlertReport(
{
estofex_sent: true,
},
lastAlertReport.id
)
reply.status(204).send(undefined)
},
})
}