Skip to content

Commit c7ac187

Browse files
committed
add event watchdog
1 parent dddf02b commit c7ac187

File tree

5 files changed

+77
-48
lines changed

5 files changed

+77
-48
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Event" ADD COLUMN "contentfulEventRestrictions" TEXT[];
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "WebhookType" ADD VALUE 'WATCHDOG';

prisma/schema.prisma

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ datasource db {
77
}
88

99
generator client {
10-
provider = "prisma-client-js"
10+
provider = "prisma-client-js"
1111
previewFeatures = ["filterJson"]
1212
}
1313

@@ -57,39 +57,39 @@ model Event {
5757
metadata Json?
5858
5959
// Data
60-
name String
61-
startDate DateTime
62-
endDate DateTime
63-
ticketPrice Float
64-
earlyBirdPrice Float
65-
earlyBirdCutoff DateTime
66-
groupPrice Float?
67-
registrationCutoff DateTime
68-
managers String[] // codeday account usernames
69-
registrationsOpen Boolean @default(false)
70-
contentfulWebname String?
71-
showcaseId String?
72-
minorWaiverId String?
73-
adultWaiverId String?
74-
eventRestrictions EventRestriction[]
60+
name String
61+
startDate DateTime
62+
endDate DateTime
63+
ticketPrice Float
64+
earlyBirdPrice Float
65+
earlyBirdCutoff DateTime
66+
groupPrice Float?
67+
registrationCutoff DateTime
68+
managers String[] // codeday account usernames
69+
registrationsOpen Boolean @default(false)
70+
contentfulWebname String?
71+
showcaseId String?
72+
minorWaiverId String?
73+
adultWaiverId String?
74+
eventRestrictions EventRestriction[]
7575
contentfulEventRestrictions String[]
76-
timezone String?
77-
majorityAge Int @default(18)
78-
overnightMinAge Int?
79-
minAge Int?
80-
maxAge Int?
81-
requiresPromoCode Boolean @default(false)
76+
timezone String?
77+
majorityAge Int @default(18)
78+
overnightMinAge Int?
79+
minAge Int?
80+
maxAge Int?
81+
requiresPromoCode Boolean @default(false)
8282
// Relations
83-
eventGroup EventGroup @relation(fields: [eventGroupId], references: [id])
84-
eventGroupId String
85-
venue Venue? @relation(fields: [venueId], references: [id])
86-
venueId String?
87-
sponsors Sponsor[]
88-
tickets Ticket[]
89-
schedule ScheduleItem[]
90-
promoCodes PromoCode[]
91-
interestedEmails MailingListMember[]
92-
webhooks Webhook[]
83+
eventGroup EventGroup @relation(fields: [eventGroupId], references: [id])
84+
eventGroupId String
85+
venue Venue? @relation(fields: [venueId], references: [id])
86+
venueId String?
87+
sponsors Sponsor[]
88+
tickets Ticket[]
89+
schedule ScheduleItem[]
90+
promoCodes PromoCode[]
91+
interestedEmails MailingListMember[]
92+
webhooks Webhook[]
9393
}
9494

9595
enum WebhookService {
@@ -100,6 +100,7 @@ enum WebhookService {
100100
enum WebhookType {
101101
ALL
102102
DIGEST
103+
WATCHDOG
103104
}
104105

105106
model Webhook {
@@ -190,7 +191,7 @@ model Person {
190191
age Int?
191192
username String?
192193
pronouns String?
193-
locale String @default("en-US")
194+
locale String @default("en-US")
194195
195196
Ticket Ticket[]
196197
}
@@ -206,21 +207,21 @@ enum TicketType {
206207

207208
model Ticket {
208209
// Metadata
209-
id String @id @default(cuid())
210-
createdAt DateTime @default(now())
211-
updatedAt DateTime @updatedAt
210+
id String @id @default(cuid())
211+
createdAt DateTime @default(now())
212+
updatedAt DateTime @updatedAt
212213
/// @TypeGraphQL.omit(input: ["update", "where", "orderBy"])
213-
metadata Json?
214+
metadata Json?
214215
// Data
215-
privateKey String? @default(uuid())
216-
firstName String
217-
lastName String
218-
email String?
219-
phone String?
220-
whatsApp String?
221-
username String?
222-
locale String @default("en-US")
223-
age Int?
216+
privateKey String? @default(uuid())
217+
firstName String
218+
lastName String
219+
email String?
220+
phone String?
221+
whatsApp String?
222+
username String?
223+
locale String @default("en-US")
224+
age Int?
224225
225226
waiverTrackingId String?
226227
waiverUrl String?
@@ -230,7 +231,7 @@ model Ticket {
230231
checkedIn DateTime?
231232
checkedOut DateTime?
232233
233-
surveyResponses Json?
234+
surveyResponses Json?
234235
235236
couponCode String?
236237
type TicketType @default(STUDENT)
@@ -386,4 +387,4 @@ model EventRestriction {
386387
title String
387388
details String?
388389
Events Event[]
389-
}
390+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { DateTime } from 'luxon';
2+
import { prisma } from '../services';
3+
import { sendWebhook } from './sendWebhook';
4+
5+
6+
export async function eventConfigWatchdog(): Promise<void> {
7+
const has_venue_closed_regs = await prisma.event.findMany({ where: { venueId: { not: null }, registrationsOpen: false, startDate: { gt: DateTime.now().toJSDate() } }});
8+
const has_regs_no_venue = await prisma.event.findMany({ where: { venueId: null, registrationsOpen: true, startDate: { gt: DateTime.now().toJSDate() } } });
9+
const watchdog_hooks = await prisma.webhook.findMany({ where: { type: 'WATCHDOG' } });
10+
11+
watchdog_hooks.forEach(async (h) => {
12+
if(has_venue_closed_regs.length > 0) {
13+
await sendWebhook(h, { title: 'WARNING: Events with venue and closed registrations', message: has_venue_closed_regs.map((e) => `${e.name}: https://clear.codeday.org/events/${e.id}`).join('\n') })
14+
}
15+
})
16+
17+
watchdog_hooks.forEach(async (h) => {
18+
if(has_regs_no_venue.length > 0) {
19+
await sendWebhook(h, { title: 'URGENT: Events with open registrations and no venue', message: has_regs_no_venue.map((e) => `${e.name}: https://clear.codeday.org/events/${e.id}`).join('\n') })
20+
}
21+
})
22+
}

src/webhooks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { prisma } from "../services";
44
import { sendEventDigests } from "./sendEventDigests";
55
import { sendEventGroupDigests } from "./sendEventGroupDigests";
66
import { sendWebhook } from "./sendWebhook";
7+
import { eventConfigWatchdog } from "./eventConfigWatchdog";
78

89
export async function automaticDigests(): Promise<void> {
910
const rule = new schedule.RecurrenceRule();
@@ -14,6 +15,7 @@ export async function automaticDigests(): Promise<void> {
1415
schedule.scheduleJob(rule, () => {
1516
sendEventDigests();
1617
sendEventGroupDigests();
18+
eventConfigWatchdog();
1719
});
1820
}
1921

0 commit comments

Comments
 (0)