Impersination backend
This commit is contained in:
6
client/src/app/model/interface/customer.interface.ts
Normal file
6
client/src/app/model/interface/customer.interface.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface ICustomer {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
updatetAt: String;
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import { AG_GRID_LOCALE_DE } from '@ag-grid-community/locale';
|
||||
import { AgGridAngular } from 'ag-grid-angular';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { AgGridContainerComponent } from '../../../../shared/ag-grid/components/ag-grid-container/ag-grid-container.component';
|
||||
import { ICustomer } from '../../../../model/interface/customer.interface';
|
||||
|
||||
@Component({
|
||||
selector: 'app-handover-dialog',
|
||||
@@ -82,8 +83,8 @@ export class HandoverDialogComponent extends AgGridContainerComponent {
|
||||
|
||||
isLoading: boolean = false;
|
||||
|
||||
customers: { name: string, id: string }[] = [];
|
||||
filteredCustomers: Observable<any[]> = new Observable();
|
||||
customers: ICustomer[] = [];
|
||||
filteredCustomers: Observable<ICustomer[]> = new Observable();
|
||||
|
||||
handoverForm = new FormGroup({
|
||||
customer: new FormControl<any>(null, Validators.required),
|
||||
@@ -125,18 +126,14 @@ export class HandoverDialogComponent extends AgGridContainerComponent {
|
||||
return promise;
|
||||
}
|
||||
|
||||
loadCustomers() {
|
||||
|
||||
|
||||
return new Promise(async resolve => {
|
||||
const customers = await this.api.getCustomers();
|
||||
this.customers = customers;
|
||||
this.filteredCustomers = this.handoverForm.controls.customer.valueChanges.pipe(
|
||||
startWith(''),
|
||||
map(value => this._filter(value || '')),
|
||||
);
|
||||
resolve(customers)
|
||||
});
|
||||
async loadCustomers() {
|
||||
const customers = await this.api.refreshCustomers()
|
||||
this.customers = customers;
|
||||
this.filteredCustomers = this.handoverForm.controls.customer.valueChanges.pipe(
|
||||
startWith(''),
|
||||
map(value => this._filter(value || '')),
|
||||
);
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
private _filter(value: string): any[] {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { IUser } from '../model/interface/user.interface';
|
||||
import { IKey } from '../model/interface/key.interface';
|
||||
import { ICylinder } from '../model/interface/cylinder.interface';
|
||||
import { HotToastService } from '@ngxpert/hot-toast';
|
||||
import { ICustomer } from '../model/interface/customer.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,6 +17,7 @@ export class ApiService {
|
||||
public keys: BehaviorSubject<IKey[]> = new BehaviorSubject<IKey[]>([]);
|
||||
public cylinders: BehaviorSubject<ICylinder[]> = new BehaviorSubject<ICylinder[]>([]);
|
||||
public systems: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);
|
||||
public customers: BehaviorSubject<ICustomer[]> = new BehaviorSubject<ICustomer[]>([]);
|
||||
|
||||
|
||||
public user: BehaviorSubject<IUser> = new BehaviorSubject<IUser>(null!);
|
||||
@@ -55,6 +57,9 @@ export class ApiService {
|
||||
return this.http.get<IKey[]>('api/key')
|
||||
}
|
||||
|
||||
/**
|
||||
* triggert das Laden der Schlüssel vom Server und speichert sie in keys
|
||||
*/
|
||||
refreshKeys(): void{
|
||||
this.getKeys().subscribe({
|
||||
next: keys => {
|
||||
@@ -138,16 +143,25 @@ export class ApiService {
|
||||
return this.http.post('api/customer', data);
|
||||
}
|
||||
|
||||
getCustomers(): Promise<any[]> {
|
||||
return new Promise(resolve => {
|
||||
this.http.get<any[]>('api/customer').subscribe({
|
||||
next: (customers) => resolve(customers),
|
||||
error: (err) => {
|
||||
this.toast.error('Fehler beim Laden der Mieter');
|
||||
resolve([]);
|
||||
}
|
||||
private getCustomers(): Observable<ICustomer[]> {
|
||||
return this.http.get<ICustomer[]>('api/customer')
|
||||
}
|
||||
|
||||
})
|
||||
/**
|
||||
* triggert das Laden der Schlüssel vom Server und speichert sie in keys
|
||||
*/
|
||||
refreshCustomers(): Promise<ICustomer[]> {
|
||||
return new Promise(resolve => {
|
||||
this.getCustomers().subscribe({
|
||||
next: customers => {
|
||||
this.customers.next(customers);
|
||||
resolve(customers)
|
||||
},
|
||||
error: () => {
|
||||
this.toast.error('Fehler beim Laden der Schlüssel');
|
||||
resolve([])
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -176,6 +190,12 @@ export class ApiService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht das System vom Server und zeigt Toast an.
|
||||
* Aktualisiert die Systeme danach
|
||||
* @param system zu löschen
|
||||
* @returns true oder false
|
||||
*/
|
||||
deleteSystem(system: any): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
this.http.delete(`api/system${system.id}`).pipe(
|
||||
@@ -239,6 +259,11 @@ export class ApiService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert die Schließanlagen im Behaviour Subject
|
||||
* systems
|
||||
* @returns Promise wenn geladen
|
||||
*/
|
||||
refreshSystems(): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
this.getSystems().subscribe({
|
||||
|
||||
Reference in New Issue
Block a user