forked from tuwien-csd/damap-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsent.guard.ts
48 lines (44 loc) · 1.3 KB
/
consent.guard.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
RouterStateSnapshot,
} from '@angular/router';
import { BackendService } from '@damap/core';
import { ConsentComponent } from '../components/consent/consent.component';
import { MatDialog } from '@angular/material/dialog';
@Injectable()
export class ConsentGuard implements CanActivate {
public consentGiven: boolean;
public consent;
constructor(
private backendService: BackendService,
private dialog: MatDialog,
) {
this.consentGiven = true;
}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
): boolean {
const consentResponse = this.backendService.getConsentGiven();
consentResponse.subscribe(response => {
if (response) {
this.consentGiven = true;
} else {
this.consentGiven = false;
let dialogRef = this.dialog.open(ConsentComponent, {
disableClose: true,
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.consentGiven = true;
this.consent = { consentGiven: true }; //create consentDO object to send
this.backendService.editConsent(this.consent).subscribe();
}
});
}
});
return this.consentGiven;
}
}