Skip to content

Commit

Permalink
Fix: Prevent wrong field name/types to be added in Firestore through …
Browse files Browse the repository at this point in the history
…the API (#144)

* Prevent wrong field name/types to be added in Firestore

* minor CI build changes
  • Loading branch information
HugoGresse authored Oct 12, 2024
1 parent 830cc86 commit c8135ec
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 69 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Build project
name: Build & test front & functions project

on: [push, pull_request]

jobs:
build:
name: Build front project
name: Build & test front & functions project
runs-on: ubuntu-latest

steps:
Expand All @@ -14,10 +14,11 @@ jobs:
- run: bun install --frozen-lockfile
- run: bun run build
- run: bun run tscheck

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
node-version-file: ./functions/.nvmrc

- name: Build serverless functions
working-directory: ./functions
Expand Down
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
}
Loading

0 comments on commit c8135ec

Please sign in to comment.