-
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 otherSpeakers in lineup talk firestore model + provide…
…d voxxrin model mappers for lineup speakers/talks
- Loading branch information
Showing
4 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,66 @@ | ||
import {ValueObject} from "@/models/utils"; | ||
import {Speaker} from "../../../shared/daily-schedule.firestore"; | ||
import {Replace} from "../../../shared/type-utils"; | ||
import {LineupSpeaker, LineupTalk} from "../../../shared/event-lineup.firestore"; | ||
import {TalkId} from "@/models/VoxxrinTalk"; | ||
import {RoomId, VoxxrinRoom} from "@/models/VoxxrinRoom"; | ||
import {findRoom, findTalkFormat, findTrack, VoxxrinConferenceDescriptor} from "@/models/VoxxrinConferenceDescriptor"; | ||
import {match, P} from "ts-pattern"; | ||
import {TalkFormatId, VoxxrinTalkFormat} from "@/models/VoxxrinTalkFormat"; | ||
import {TrackId, VoxxrinTrack} from "@/models/VoxxrinTrack"; | ||
|
||
export class SpeakerId extends ValueObject<string>{ _speakerIdClassDiscriminator!: never; } | ||
export type VoxxrinDetailedSpeaker = Replace<Speaker, {id: SpeakerId}>; | ||
export type VoxxrinSimpleSpeaker = Omit<VoxxrinDetailedSpeaker, "bio"|"social">; | ||
|
||
export type VoxxrinLineupTalk = Replace<LineupTalk, { | ||
id: TalkId, | ||
format: VoxxrinTalkFormat, | ||
track: VoxxrinTrack, | ||
allocation: { | ||
room: VoxxrinRoom, | ||
}|undefined, | ||
otherSpeakers: VoxxrinSimpleSpeaker[], | ||
}> | ||
|
||
export type VoxxrinLineupSpeaker = Replace<LineupSpeaker, { | ||
id: SpeakerId, | ||
talks: VoxxrinLineupTalk[], | ||
}> | ||
|
||
export const toVoxxrinSpeaker = (speaker: Speaker): VoxxrinSimpleSpeaker => { | ||
return ({ | ||
photoUrl: speaker.photoUrl, | ||
companyName: speaker.companyName, | ||
fullName: speaker.fullName, | ||
id: new SpeakerId(speaker.id) | ||
}) | ||
} | ||
|
||
export const createVoxxrinSpeakerFromFirestore = (conferenceDescriptor: VoxxrinConferenceDescriptor, firestoreSpeaker: LineupSpeaker): VoxxrinLineupSpeaker => { | ||
return { | ||
...firestoreSpeaker, | ||
id: new SpeakerId(firestoreSpeaker.id), | ||
talks: firestoreSpeaker.talks.map(firestoreTalk => { | ||
const format = findTalkFormat(conferenceDescriptor, new TalkFormatId(firestoreTalk.format.id)); | ||
const track = findTrack(conferenceDescriptor, new TrackId(firestoreTalk.track.id)); | ||
const allocation = match(firestoreTalk.allocation) | ||
.with(P.not(P.nullish), allocation => { | ||
const room = findRoom(conferenceDescriptor, new RoomId(allocation.room.id)); | ||
return { | ||
...firestoreTalk.allocation, | ||
room | ||
}; | ||
}).otherwise(() => undefined); | ||
|
||
return { | ||
...firestoreTalk, | ||
id: new TalkId(firestoreTalk.id), | ||
allocation, | ||
format, | ||
track, | ||
otherSpeakers: firestoreTalk.otherSpeakers.map(sp => toVoxxrinSpeaker(sp)), | ||
}; | ||
}) | ||
} | ||
} |
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