Skip to content

Commit dc3d95b

Browse files
committed
enforcing dailyRatings are defined (for some weird reasons, we've got error due to undefined dailyRatings for a given day 🤔
1 parent ff7b9e0 commit dc3d95b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cloud/functions/src/crawlers/crawl.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,12 @@ const saveEvent = async function (event: FullEvent, crawlerDescriptor: z.infer<t
373373
const ratingsTalkIds = talkFeedbacksDoc.map(doc => doc.id);
374374
await Promise.all([
375375
...event.daySchedules.map(async daySchedule => {
376-
const dailyRatings = (await db.doc(`${resolvedEventFirestorePath(event.id, maybeSpaceToken)}/organizer-space/${organizerSecretToken}/daily-ratings/${daySchedule.day}`).get()).data() as Record<string, object>;
376+
const dailyRatingsDoc = db.doc(`${resolvedEventFirestorePath(event.id, maybeSpaceToken)}/organizer-space/${organizerSecretToken}/daily-ratings/${daySchedule.day}`);
377+
let dailyRatings = (await dailyRatingsDoc.get()).data() as Record<string, object>;
378+
if(!dailyRatings) {
379+
dailyRatings = {};
380+
await dailyRatingsDoc.create(dailyRatings);
381+
}
377382
const talkIds = daySchedule.timeSlots.flatMap(ts => ts.type === 'talks' ? ts.talks.map(t => t.id) : [])
378383
const dailyRatingsToUpdate = talkIds.reduce((dailyRatingsToUpdate, talkId) => {
379384
if(!dailyRatings[talkId]) {
@@ -383,7 +388,7 @@ const saveEvent = async function (event: FullEvent, crawlerDescriptor: z.infer<t
383388
}, {} as Record<string, object>)
384389

385390
if(Object.keys(dailyRatingsToUpdate).length) {
386-
await db.doc(`${resolvedEventFirestorePath(event.id, maybeSpaceToken)}/organizer-space/${organizerSecretToken}/daily-ratings/${daySchedule.day}`).update(dailyRatingsToUpdate);
391+
await dailyRatingsDoc.update(dailyRatingsToUpdate);
387392
}
388393
}),
389394
...event.talks.map(async talk => {

0 commit comments

Comments
 (0)