frontend/src/app/service/session.service.ts
garrettmills 3e9a0a03f8
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Add session service and startup logic to check for authed user (#15)
2020-10-12 20:31:20 -05:00

49 lines
1.1 KiB
TypeScript

import { Injectable } from '@angular/core';
import {ApiService} from './api.service';
@Injectable({
providedIn: 'root'
})
export class SessionService {
public appName!: string;
public systemBase!: string;
protected data: any = {};
constructor(
protected readonly api: ApiService,
) { }
async stat() {
return new Promise((res, rej) => {
this.api.stat().subscribe(response => {
res(response.data);
});
});
}
async initialize() {
return new Promise((res, rej) => {
this.api.get('/session').subscribe(response => {
this.data = response.data;
res();
});
});
}
buildAppUrl(...parts: string[]): string {
parts = parts.map(x => {
if ( x.startsWith('/') ) {
x = x.slice(1);
}
if ( x.endsWith('/') ) {
x = x.slice(0, -1);
}
return x;
});
return `${this.systemBase}${this.systemBase.endsWith('/') ? '' : '/'}${parts.join('/')}`;
}
}