119 lines
3.0 KiB
TypeScript
119 lines
3.0 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { inject, Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
import { IUser } from '../model/interface/user.interface';
|
|
import { IKey } from '../model/interface/key.interface';
|
|
import { ICylinder } from '../model/interface/cylinder.interface';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ApiService {
|
|
private http: HttpClient = inject(HttpClient);
|
|
|
|
constructor() { }
|
|
|
|
|
|
getAllUsers(): Observable<IUser[]> {
|
|
return this.http.get<IUser[]>('/api/user');
|
|
}
|
|
|
|
saveUser(user: IUser) {
|
|
return this.http.post('/api/user', user);
|
|
}
|
|
|
|
getRoles(): Observable<{id: string, name: string}[]> {
|
|
return this.http.get<{id: string, name: string}[]>('/api/role');
|
|
}
|
|
|
|
getKeys(): Observable<IKey[]> {
|
|
return this.http.get<IKey[]>('api/key')
|
|
}
|
|
|
|
updateKey(key: IKey): Observable<IKey> {
|
|
return this.http.put<IKey>('api/key', key);
|
|
}
|
|
|
|
createKey(key: any) {
|
|
return this.http.post<IKey>('api/key', key);
|
|
}
|
|
|
|
createSystem(keySystem: any) {
|
|
return this.http.post('api/system', keySystem);
|
|
}
|
|
|
|
getSystems(): Observable<any[]> {
|
|
return this.http.get<any[]>('api/system');
|
|
}
|
|
|
|
getSystemManagers(id: string): Observable<IUser[]> {
|
|
return this.http.get<any[]>(`api/system/${id}/manager`);
|
|
}
|
|
|
|
handoverKey(data: any) {
|
|
return this.http.post(`api/key/${data.key.id}/handover`, data);
|
|
}
|
|
|
|
getHandovers(keyID: string): Observable<any[]> {
|
|
return this.http.get<any[]>(`api/key/${keyID}/handover`);
|
|
}
|
|
|
|
createCustomer(data: { name: string, system: any}) {
|
|
return this.http.post('api/customer', data);
|
|
}
|
|
|
|
getCustomers(): Observable<any[]> {
|
|
return this.http.get<any[]>('api/customer')
|
|
}
|
|
|
|
deleteKey(id: string) {
|
|
return this.http.delete(`api/key/${id}`);
|
|
}
|
|
|
|
getKeyArchive(): Observable<IKey[]> {
|
|
return this.http.get<IKey[]>('api/key/archive');
|
|
}
|
|
|
|
restoreKey(id: string) {
|
|
return this.http.put(`api/key/${id}/restore`, null);
|
|
}
|
|
|
|
getCylinders(): Observable<ICylinder[]> {
|
|
return this.http.get<ICylinder[]>('api/cylinder');
|
|
}
|
|
|
|
deleteCylinder(cylinder: ICylinder): Observable<any> {
|
|
return this.http.delete(`api/cylinder/${cylinder.id}`)
|
|
}
|
|
|
|
deleteUser(id: string) {
|
|
return this.http.delete(`api/user/${id}`)
|
|
}
|
|
|
|
addManager(systemID: string, email: string): Observable<IUser[]> {
|
|
return this.http.post<IUser[]>(`api/system/${systemID}/manager`, {
|
|
email,
|
|
action: 'add'
|
|
});
|
|
}
|
|
|
|
removeManager(systemID: string, email: string): Observable<IUser[]> {
|
|
return this.http.post<IUser[]>(`api/system/${systemID}/manager`, {
|
|
email,
|
|
action: 'remove'
|
|
});
|
|
}
|
|
|
|
getStats(): Observable<{ keys: number, cylinders: number, systems: number }> {
|
|
return this.http.get<{ keys: number, cylinders: number, systems: number }>('api/user/stats');
|
|
}
|
|
|
|
getActivities(): Observable<any[]> {
|
|
return this.http.get<any[]>('api/user/activities');
|
|
}
|
|
|
|
createCylinder(data: any) {
|
|
return this.http.post<ICylinder>('api/cylinder', data);
|
|
}
|
|
}
|