-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathwebinars.ts
More file actions
143 lines (113 loc) · 3.33 KB
/
webinars.ts
File metadata and controls
143 lines (113 loc) · 3.33 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
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
141
142
143
import { useState } from "#app";
export const useMyWebinars = () => useState("myWebinars", () => []);
export const useWebinars = () => useState("webinars", () => []);
export const useWebinar = () => useState("webinar", () => null);
export async function getRating(skill_id: string) {
const user = <any>useUser();
let user_id = user?.value?.id ?? null;
try {
if (!!!user_id) {
throw { data: { detail: "Invalid User Id" } };
}
if (!!!skill_id) {
throw { data: { detail: "Invalid Skill Id" } };
}
const response = await GET(`/events/ratings/${user_id}/${skill_id}`);
return [response == null ? 0 : response, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function deleteWebinar(id: string) {
try {
if (!!!id) {
throw { data: { detail: "Invalid webinar Id" } };
}
const response = await DELETE(`/events/calendar/${id}`);
return [response, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function getWebinar(id: string) {
try {
if (!!!id) {
throw { data: { detail: "Invalid webinar Id" } };
}
const response = await GET(`/events/webinars/${id}`);
const webinar = useWebinar();
webinar.value = response ?? null;
return [response, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function createWebinar(body: any) {
try {
const response = await POST(`/events/webinars`, body);
return [response, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function editWebinar(id: string, body: any) {
try {
if (!!!id) {
throw { data: { detail: "Invalid webinar Id" } };
}
const response = await PATCH(`/events/webinars/${id}`, body);
return [response, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function getMyWebinars() {
const user = <any>useUser();
let user_id = user?.value?.id ?? null;
try {
if (!!!user_id) {
throw { data: { detail: "Invalid User Id" } };
}
const response = await GET(`/events/calendar?type=webinar&instructor_id=${user_id}`);
const myWebinars = useMyWebinars();
myWebinars.value = response?.events ?? [];
return [response, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function getWebinarsForThisSubSkill(subSkillID: string) {
try {
if (!!!subSkillID) {
throw { data: { detail: "Invalid sub skill ID" } };
}
const response = await GET(`/events/calendar?type=webinar&skill_id=${subSkillID}`);
const webinars = useWebinars();
webinars.value = response?.events ?? [];
return [webinars.value, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function getAllWebinars() {
try {
const response = await GET(`/events/webinars`);
const webinars = useWebinars();
webinars.value = response ?? [];
return [response, null];
} catch (error: any) {
return [null, error.data];
}
}
export async function registerForWebinarByID(webinarID: string) {
try {
if (!!!webinarID) {
throw { data: "Invalid webinar ID" };
}
const response = await POST(`/events/webinars/${webinarID}/participants`);
await getBalance();
return [response, null];
} catch (error: any) {
return [null, error.data];
}
}