Skip to content

Commit 225053a

Browse files
committed
Remove try/catch, adjust types to not throw.
1 parent 9fc96e4 commit 225053a

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

functions/src/events/scrapeEvents.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,15 @@ class HearingScraper extends EventScraper<HearingListItem, Hearing> {
148148
}
149149

150150
async getEvent({ EventId }: HearingListItem /* e.g. 4962 */) {
151+
EventId = 5091
151152
const data = await api.getHearing(EventId)
152153
const content = HearingContent.check(data)
153154
const eventInDb = await db
154155
.collection("events")
155156
.doc(`hearing-${String(EventId)}`)
156157
.get()
157-
158158
const eventData = eventInDb.data()
159-
try {
160-
Hearing.check(eventData)
161-
} catch (e) {
162-
console.log(e)
163-
}
164159
const hearing = Hearing.check(eventData)
165-
166160
const shouldScrape = withinCutoff(hearing.startsAt.toDate())
167161

168162
let maybeVideoURL = null
@@ -214,28 +208,32 @@ class HearingScraper extends EventScraper<HearingListItem, Hearing> {
214208
}
215209
}
216210
}
217-
218-
const event: Hearing = {
211+
let payload: Hearing = {
219212
id: `hearing-${EventId}`,
220213
type: "hearing",
221214
content,
222-
videoURL: hearing.videoURL
223-
? hearing.videoURL
224-
: maybeVideoURL
225-
? maybeVideoURL
226-
: null,
227-
videoFetchedAt: hearing.videoFetchedAt
228-
? hearing.videoFetchedAt
229-
: maybeVideoURL
230-
? Timestamp.now()
231-
: null,
232-
videoAssemblyId: hearing.videoAssemblyId
233-
? hearing.videoAssemblyId
234-
: transcript
235-
? transcript.id
236-
: null,
237215
...this.timestamps(content)
238216
}
217+
if (hearing.videoURL) {
218+
payload = { ...payload, videoURL: hearing.videoURL }
219+
}
220+
if (maybeVideoURL) {
221+
payload = { ...payload, videoURL: maybeVideoURL }
222+
}
223+
if (hearing.videoFetchedAt) {
224+
payload = { ...payload, videoFetchedAt: hearing.videoFetchedAt }
225+
}
226+
if (maybeVideoURL) {
227+
payload = { ...payload, videoFetchedAt: Timestamp.now() }
228+
}
229+
if (hearing.videoAssemblyId) {
230+
payload = { ...payload, videoAssemblyId: hearing.videoAssemblyId }
231+
}
232+
if (transcript) {
233+
payload = { ...payload, videoAssemblyId: transcript.id }
234+
}
235+
236+
const event: Hearing = payload
239237
return event
240238
}
241239
}

functions/src/events/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Literal as L,
55
Null,
66
Number,
7+
Optional,
78
Record,
89
Runtype,
910
Static,
@@ -77,9 +78,9 @@ export type Hearing = Static<typeof Hearing>
7778
export const Hearing = BaseEvent.extend({
7879
type: L("hearing"),
7980
content: HearingContent,
80-
videoURL: Nullable(String),
81-
videoAssemblyId: Nullable(String),
82-
videoFetchedAt: Nullable(InstanceOf(Timestamp))
81+
videoURL: Optional(String),
82+
videoAssemblyId: Optional(String),
83+
videoFetchedAt: Optional(InstanceOf(Timestamp))
8384
})
8485

8586
export type Event = Static<typeof Event>

0 commit comments

Comments
 (0)