-
Notifications
You must be signed in to change notification settings - Fork 73
/
index.ts
140 lines (122 loc) · 3.52 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { fetchGraphQL } from '../..';
import { Session, AllSessionsResponse, SessionResult } from '../../../interfaces/session';
import { TimeslotResult } from '../../../interfaces/timeslot';
import { DayResult } from '../../../interfaces/day';
const sessionsQuery = `
query {
allDemo_Session (first: 30) {
results {
id
name
isPremium
description
sessionToMasterAsset {
results {
assetToPublicLink(first: 1) {
results {
id
relativeUrl
versionHash
}
}
}
}
room {
results {
id
name
}
}
timeslotToSession {
results {
id
taxonomyLabel
sortOrder
}
}
speakers {
results {
id
name
}
}
dayToSession {
results {
taxonomyName
sortOrder
}
}
sessionsTypeToSessions {
taxonomyName
}
}
}
}
`;
const parseSession = function (sessionResult: SessionResult) {
return parseSessionWithTimeSlot(sessionResult, {
id: '',
sortOrder: 0,
taxonomyLabel: {
'en-US': '',
},
});
};
const parseSessionWithTimeSlot = function (
sessionResult: SessionResult,
timeslotResult: TimeslotResult
) {
const session = {} as Session;
session.id = sessionResult.id;
session.name = sessionResult.name;
session.description = sessionResult.description;
const asset = sessionResult.sessionToMasterAsset.results[0]?.assetToPublicLink.results[0];
const relativeUrl = asset?.relativeUrl;
const versionHash = asset?.versionHash;
session.type =
sessionResult.sessionsTypeToSessions && sessionResult.sessionsTypeToSessions.taxonomyName;
session.isPremium = sessionResult.isPremium;
session.image = `${relativeUrl}?v=${versionHash}`;
if (sessionResult.room.results.length > 0) {
session.room = sessionResult.room.results[0].name;
}
if (sessionResult.speakers.results.length > 0) {
session.speaker = sessionResult.speakers.results[0].name;
if (sessionResult.speakers.results.length > 1) {
session.speaker = sessionResult.speakers.results
.map((speaker) => {
return speaker.name;
})
.join(', ');
}
}
session.Day = sessionResult.dayToSession.results[0].taxonomyName;
if (timeslotResult.id === '' && sessionResult.timeslotToSession.results.length > 0) {
session.timeslot = sessionResult.timeslotToSession.results[0].taxonomyLabel['en-US'];
session.sortOrder = sessionResult.timeslotToSession.results[0].sortOrder;
} else {
session.timeslot = timeslotResult.taxonomyLabel['en-US'];
session.sortOrder = timeslotResult.sortOrder;
}
return session;
};
export const getAllSessionsByDay = async (day: string): Promise<{ sessions: Session[] }> => {
const results: AllSessionsResponse = (await fetchGraphQL(sessionsQuery)) as AllSessionsResponse;
const sessions: Session[] = [];
results.data.allDemo_Session.results.forEach((s: SessionResult) => {
if (
s.dayToSession &&
s.dayToSession.results &&
s.dayToSession.results.find((e: DayResult) => e.sortOrder == day)
) {
if (s.timeslotToSession.results.length > 1) {
s.timeslotToSession.results.map((timedSession) =>
sessions.push(parseSessionWithTimeSlot(s, timedSession))
);
} else {
sessions.push(parseSession(s));
}
}
});
return { sessions: sessions.sort((a, b) => a.sortOrder - b.sortOrder) };
};