File: /var/dev/nowruzgan/admin/src/app/services/permission.service.ts
import { Injectable } from '@angular/core';
import { GenericService } from './generic.service';
import { Permission } from '../data.types';
import { environment } from '../../environments/environment';
@Injectable()
export class PermissionService extends GenericService {
async list(): Promise<Permission[]> {
let response = await this.http
.get(`${environment.apiBase}/permission`, this.headers)
.toPromise()
.catch(error => this.handleError(error));
if(!response) return [];
return (response as any[]).map(record => new Permission(record));
}
async update(action: string, role: string, allow: boolean): Promise<boolean> {
let response = await this.http
.patch(`${environment.apiBase}/permission`, {role, action, allow}, this.headers)
.toPromise()
.catch(error => false);
return !!response;
}
}