-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#74 introduced firestore migration in order to introduce speakers in …
…existing events
- Loading branch information
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...s/src/functions/firestore/migrations/022-introduceEventSpeakersAndFixTalkUndefinedTags.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {getAllEventsDocs} from "../services/event-utils"; | ||
import {db} from "../../../firebase"; | ||
import {getEventTalks} from "../services/talk-utils"; | ||
import {detailedTalksToSpeakersLineup} from "../../../models/Event"; | ||
|
||
|
||
export async function introduceEventSpeakersAndFixTalkUndefinedTags(): Promise<"OK"|"Error"> { | ||
const eventDocs = await getAllEventsDocs({includePrivateSpaces: true}) | ||
await Promise.all([ | ||
...eventDocs.map(async eventDoc => { | ||
try { | ||
const eventTalks = await getEventTalks(eventDoc.ref, eventDoc.id); | ||
|
||
// Migrating event talks with empty tags in it | ||
const migratedEventTalks = await Promise.all(eventTalks.map(async eventTalk => { | ||
if(!eventTalk.tags) { | ||
await db.doc(`${eventDoc.ref.path}/talks/${eventTalk.id}`).update("tags", []) | ||
return { | ||
...eventTalk, | ||
tags: [] | ||
}; | ||
} else { | ||
return eventTalk; | ||
} | ||
})) | ||
|
||
const lineupSpeakers = detailedTalksToSpeakersLineup(migratedEventTalks); | ||
|
||
const eventSpeakersDoc = db.doc(`${eventDoc.ref.path}/speakers-allInOne/self`) | ||
await eventSpeakersDoc.set({ lineupSpeakers }); | ||
console.log(`Event speakers created for event id ${eventDoc.id}`) | ||
} catch (err) { | ||
console.error(`Error during Event speaker creation for ${eventDoc.id}: ${err}`) | ||
} | ||
}), | ||
]) | ||
|
||
return "OK" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters