-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconference.service.ts
More file actions
55 lines (49 loc) · 1.72 KB
/
Copy pathconference.service.ts
File metadata and controls
55 lines (49 loc) · 1.72 KB
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
import { format, isAfter, isBefore } from 'date-fns';
import { axiosInstance } from '../config/axios.config';
import { FullConferenceDto } from '../types/conference-api.type';
import { parseTime } from '../utils/presentation.utils';
export class ConferenceService {
static async getConferenceData(): Promise<FullConferenceDto> {
const response = await axiosInstance.get<FullConferenceDto>('/api/conference/index');
response.data.presentations = ConferenceService.sortPresentationsByStartDate(response.data);
ConferenceService.prefixConferenceImages(response.data);
return response.data;
}
private static sortPresentationsByStartDate(conference: FullConferenceDto) {
return conference.presentations.sort((a, b) => {
const aStartDate = parseTime(a.startTime);
const bStartDate = parseTime(b.startTime);
if (isBefore(aStartDate, bStartDate)) {
return -1;
}
if (isAfter(aStartDate, bStartDate)) {
return 1;
}
return 0;
});
}
static getFormattedTimestamp(timestamp: string) {
if (/^\d{2}:\d{2}$/.test(timestamp)) {
return timestamp;
}
try {
return format(new Date(timestamp), 'HH:mm');
} catch {
return timestamp || 'n/a';
}
}
static prefixConferenceImages(conference: FullConferenceDto) {
conference.presentations.forEach((p) => {
if (p.presenter) {
p.presenter.pictureUrl = ConferenceService.prefixPresenterImage(p.presenter);
}
});
return conference;
}
static prefixPresenterImage(presenter: { pictureUrl: string }) {
if (presenter.pictureUrl.startsWith('http')) {
return presenter.pictureUrl;
}
return `https://konferencia.simonyi.bme.hu${presenter.pictureUrl}`;
}
}