2020-03-17 22:16:34 +00:00
|
|
|
export default class ApiService {
|
|
|
|
|
|
|
|
static async getUser(userId?: number) {
|
|
|
|
return (await fetch('/api/v1/client/user/')).json();
|
|
|
|
}
|
|
|
|
|
2020-04-12 14:25:42 +00:00
|
|
|
|
2020-03-17 22:16:34 +00:00
|
|
|
static async getAllUsers() {
|
|
|
|
return (await fetch('/api/v1/admin/users')).json();
|
|
|
|
}
|
|
|
|
|
2020-04-12 14:25:42 +00:00
|
|
|
static async getChild(id: number): Promise<IApiResponse> {
|
|
|
|
return (await fetch(`/api/v1/client/child/${id}`)).json();
|
|
|
|
}
|
|
|
|
|
|
|
|
static async createConnection(payload: { child_id: number, email: string, is_parent: boolean }) {
|
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(payload),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return (await fetch('/api/v1/client/connections/create', options)).json();
|
|
|
|
} catch (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static async updateChildCover(child_id: number, profile_cover: string) {
|
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
profile_cover
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
const response = await fetch(`/api/v1/client/child/${child_id}/profile/cover`, options);
|
|
|
|
console.log(response);
|
|
|
|
return response.json();
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static async createCall(payload: { connection_id: number, child_id: number }) {
|
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(payload),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
const response = await fetch('/api/v1/client/call/create', options);
|
|
|
|
return response.json();
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 22:16:34 +00:00
|
|
|
static async createChild(name: string, dob: Date, avatar: string): Promise<any> {
|
|
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
name,
|
|
|
|
dob,
|
|
|
|
avatar
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
const response = await fetch('/api/v1/client/child/', options);
|
|
|
|
console.log(response);
|
|
|
|
return response.json();
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 14:25:42 +00:00
|
|
|
|
|
|
|
interface IApiResponse {
|
|
|
|
code: number;
|
|
|
|
data?: any;
|
|
|
|
message?: string;
|
|
|
|
}
|