-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathEventAPIUtils.js
More file actions
87 lines (81 loc) · 2.23 KB
/
Copy pathEventAPIUtils.js
File metadata and controls
87 lines (81 loc) · 2.23 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
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
// @flow
import CurrentUser from "./CurrentUser.js";
import { ProjectAPIData } from "./ProjectAPIUtils.js";
import type { FileInfo } from "../common/FileInfo.jsx";
import type { TagDefinition } from "./ProjectAPIUtils.js";
export type LocationTimezone = {|
id: string,
event_id: string,
location_name: string,
address_line_1: string,
address_line_2: string,
time_zone: string,
country: string,
state: string,
city: string,
|};
export type EventData = {|
event_id: string,
event_creator: string,
event_date_start: Date,
event_date_end: Date,
event_name: string,
event_organizers_text: string,
event_live_id: string,
event_rsvp_url: string,
event_agenda: string,
event_location: string,
event_description: string,
event_short_description: string,
event_thumbnail: FileInfo,
event_projects: $ReadOnlyArray<ProjectAPIData>,
event_legacy_organization: $ReadOnlyArray<TagDefinition>,
event_slug: string,
is_private: boolean,
is_activated: boolean,
show_headers: boolean,
event_conference_url: ?string,
event_conference_admin_url: ?string,
event_conference_participants: ?string,
event_time_zones: $ReadOnlyArray<LocationTimezone>,
event_approved: boolean,
|};
export type EventTileAPIData = {|
event_id: string,
event_slug: string,
event_date_start: Date,
event_date_end: Date,
event_name: string,
event_organizers_text: string,
event_location: string,
event_short_description: string,
event_thumbnail: FileInfo,
|};
export default class EventAPIUtils {
static fetchEventDetails(
id: number,
callback: EventData => void,
errCallback: APIError => void
): void {
fetch(new Request("/api/event/" + id + "/", { credentials: "include" }))
.then(response => {
if (!response.ok) {
throw Error();
}
return response.json();
})
.then(eventDetails => callback(eventDetails))
// TODO: Get catch to return http status code
.catch(
response =>
errCallback &&
errCallback({
errorCode: response.status,
errorMessage: JSON.stringify(response),
})
);
}
static isOwner(event: EventData): boolean {
return CurrentUser.userID() === event.event_creator;
}
}