39 lines
832 B
TypeScript
39 lines
832 B
TypeScript
|
export default class ApiService {
|
||
|
|
||
|
static async getUser(userId?: number) {
|
||
|
return (await fetch('/api/v1/client/user/')).json();
|
||
|
}
|
||
|
|
||
|
static async getConnections() {
|
||
|
return (await fetch('/api/v1/client/connections')).json();
|
||
|
}
|
||
|
static async getAllUsers() {
|
||
|
return (await fetch('/api/v1/admin/users')).json();
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|