add more backend services

This commit is contained in:
Sven Czarnian
2022-11-04 15:28:29 +01:00
parent ecc01fbb8c
commit 7807c2784c
3 changed files with 52 additions and 1 deletions

31
src/services/auth.ts Normal file
View File

@@ -0,0 +1,31 @@
import axios from 'axios';
import { Configuration } from './configuration';
import { User } from '../types';
export class Auth {
static async user(): Promise<User> {
const token = sessionStorage.getItem('token');
if (!token) {
return {
vatsimId: '',
fullName: '',
administrator: false,
airportConfigurationAccess: [],
};
}
return axios
.get<User>(`${Configuration.resourceServer}/auth/user`, {
headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
},
})
.then((response) => response.data)
.catch(() => ({
vatsimId: '',
fullName: '',
administrator: false,
airportConfigurationAccess: [],
}));
}
}

View File

@@ -1,4 +1,6 @@
import { Airport } from "./airport"; import { Airport } from "./airport";
import { Auth } from './auth';
import { Configuration } from "./configuration"; import { Configuration } from "./configuration";
import { System } from './system';
export { Airport, Configuration }; export { Airport, Auth, Configuration, System };

18
src/services/system.ts Normal file
View File

@@ -0,0 +1,18 @@
import axios from 'axios';
import { Configuration } from './configuration';
export class System {
static async timestamp(): Promise<number> {
const token = sessionStorage.getItem('token');
if (!token) return 0;
return axios
.get<number>(`${Configuration.resourceServer}/system/timestamp`, {
headers: {
Authorization: `Bearer ${token}`,
},
})
.then((response) => response.data)
.catch(() => 0);
}
}