-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Prevent wrong field name/types to be added in Firestore through …
…the API (#144) * Prevent wrong field name/types to be added in Firestore * minor CI build changes
- Loading branch information
1 parent
830cc86
commit c8135ec
Showing
7 changed files
with
368 additions
and
69 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
82 changes: 82 additions & 0 deletions
82
functions/src/api/routes/overwriteSpeakerSessions/convertBodySessionToSession.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,82 @@ | ||
import { Session, Event } from '../../../types' | ||
import { OverwriteSpeakerSessionsType } from './overwriteSpeakerSessions' | ||
|
||
type ElementType<T> = T extends (infer U)[] ? U : never | ||
|
||
export const convertBodySessionToSession = ( | ||
session: ElementType<OverwriteSpeakerSessionsType['sessions']>, | ||
event: Event | ||
): Session => { | ||
const realSession: Partial<Session> = { | ||
id: session.id, | ||
} | ||
|
||
if (session.dateStart && session.dateEnd) { | ||
realSession.dates = { | ||
start: session.dateStart, | ||
end: session.dateEnd, | ||
} | ||
} | ||
|
||
// TypeScript doesn't support type at compile time, and transformers is not working with vite. So we need to do this shit | ||
if (session.title) { | ||
realSession.title = session.title | ||
} | ||
if (session.abstract) { | ||
realSession.abstract = session.abstract | ||
} | ||
if (session.durationMinutes) { | ||
realSession.durationMinutes = session.durationMinutes | ||
} | ||
if (session.hideTrackTitle) { | ||
realSession.hideTrackTitle = session.hideTrackTitle | ||
} | ||
if (session.showInFeedback) { | ||
realSession.showInFeedback = session.showInFeedback | ||
} | ||
if (session.imageUrl) { | ||
realSession.imageUrl = session.imageUrl | ||
} | ||
if (session.videoLink) { | ||
realSession.videoLink = session.videoLink | ||
} | ||
if (session.presentationLink) { | ||
realSession.presentationLink = session.presentationLink | ||
} | ||
if (session.language) { | ||
realSession.language = session.language | ||
} | ||
if (session.level) { | ||
realSession.level = session.level | ||
} | ||
if (session.note) { | ||
realSession.note = session.note | ||
} | ||
if (session.teasingHidden) { | ||
realSession.teasingHidden = session.teasingHidden | ||
} | ||
|
||
if (session.trackId || session.trackName) { | ||
realSession.trackId = (event.tracks || []).find( | ||
(track) => track.name === session.trackId || track.name === session.trackName | ||
)?.id | ||
} | ||
|
||
if (session.categoryId || session.categoryName) { | ||
realSession.category = (event.categories || []).find( | ||
(cat) => cat.name === session.categoryId || cat.name === session.categoryName | ||
)?.id | ||
} | ||
|
||
if (session.formatId || session.formatName) { | ||
realSession.format = (event.formats || []).find( | ||
(format) => format.name === session.formatId || format.name === session.formatName | ||
)?.id | ||
} | ||
|
||
if (session.speakerIds) { | ||
realSession.speakers = session.speakerIds | ||
} | ||
|
||
return realSession as Session | ||
} |
Oops, something went wrong.