Skip to content

Commit

Permalink
event queries
Browse files Browse the repository at this point in the history
  • Loading branch information
wslyvh committed Nov 2, 2024
1 parent e6e97a0 commit 861974e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
7 changes: 7 additions & 0 deletions devcon-api/src/controllers/speakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export async function GetSpeaker(req: Request, res: Response) {
where: {
OR: [{ id: req.params.id }, { sourceId: req.params.id }],
},
include: {
sessions: {
include: {
slot_room: true,
},
},
},
})

if (!data) return res.status(404).send({ status: 404, message: 'Not Found' })
Expand Down
6 changes: 2 additions & 4 deletions devcon-app/src/pages/speakers/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppLayout } from 'components/domain/app/Layout'
import { SpeakerView, SpeakerSessions, cardClass } from 'components/domain/app/dc7/speakers/index'
import React from 'react'
import { fetchSessionsBySpeaker, fetchSpeaker, fetchSpeakers } from 'services/event-data'
import { fetchSpeaker, fetchSpeakers } from 'services/event-data'
import { SEO } from 'components/domain/seo'
import cn from 'classnames'

Expand Down Expand Up @@ -47,13 +47,11 @@ export async function getStaticProps(context: any) {
}
}

const sessions = await fetchSessionsBySpeaker(speaker.id)

return {
props: {
speaker: {
...speaker,
sessions,
sessions: speaker.sessions,
},
},
revalidate: 60,
Expand Down
14 changes: 7 additions & 7 deletions devcon-app/src/services/event-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,11 @@ export const fetchEvent = async (): Promise<any> => {
}

export const fetchSessionsBySpeaker = async (id: string): Promise<Array<SessionType>> => {
// return await get(`/speakers/${id}/sessions?event=${eventName}`)
// no endpoint exists, so fetches and filters all sessions recursively
return (await fetchSessions()).filter(i => i.speakers.some(x => x.id === id))
return await get(`/speakers/${id}/sessions?event=${eventName}`)
}

export const fetchSessionsByRoom = async (id: string): Promise<Array<SessionType>> => {
// return await get(`/sessions?room=${id}&event=${eventName}`)
return (await fetchSessions()).filter(i => i.room?.id === id)
return await get(`/sessions?room=${id}&event=${eventName}`)
}

export const fetchExpertiseLevels = async (): Promise<Array<string>> => {
Expand Down Expand Up @@ -265,7 +262,10 @@ export const fetchSpeaker = async (id: string): Promise<Speaker | undefined> =>

if (!speaker || speaker.detail === 'Not found.') return undefined

return speaker
return {
...speaker,
sessions: speaker.sessions?.filter((i: any) => i.eventId === eventName),
}
}

async function get(slug: string) {
Expand All @@ -283,7 +283,7 @@ async function get(slug: string) {

// Extract nested items when using api.devcon.org
if (response.data) data = response.data
if (response.data.items) data = response.data.items
if (response.data?.items) data = response.data.items

cache.set(slug, data)

Expand Down

0 comments on commit 861974e

Please sign in to comment.