@@ -2,94 +2,94 @@ import { Injectable } from '@angular/core';
22import { RestService } from '../../shared/services/rest.service' ;
33import { Observable } from 'rxjs' ;
44import {
5- PermissionGetManyResponse ,
6- PermissionResponse ,
7- PermissionRequest ,
8- PermissionRequestAcceptUser ,
5+ PermissionGetManyResponse ,
6+ PermissionResponse ,
7+ PermissionRequest ,
8+ PermissionRequestAcceptUser ,
99} from './permission.model' ;
1010import { map } from 'rxjs/operators' ;
1111import { UserMinimalService } from '../users/user-minimal.service' ;
1212
1313@Injectable ( {
14- providedIn : 'root' ,
14+ providedIn : 'root' ,
1515} )
1616export class PermissionService {
17- endpoint = 'permission' ;
18- constructor (
19- private restService : RestService ,
20- private userMinimalService : UserMinimalService
21- ) { }
17+ endpoint = 'permission' ;
18+ constructor (
19+ private restService : RestService ,
20+ private userMinimalService : UserMinimalService
21+ ) { }
2222
23- createPermission ( body : PermissionRequest ) : Observable < PermissionResponse > {
24- return this . restService . post ( this . endpoint , body , {
25- observe : 'response' ,
26- } ) ;
27- }
23+ createPermission ( body : PermissionRequest ) : Observable < PermissionResponse > {
24+ return this . restService . post ( this . endpoint , body , {
25+ observe : 'response' ,
26+ } ) ;
27+ }
2828
29- createPermissionAcceptUser ( body : PermissionRequestAcceptUser ) : Observable < PermissionResponse > {
30- return this . restService . put ( this . endpoint + '/acceptUser' , body , undefined , {
31- observe : 'response' ,
32- } ) ;
33- }
29+ createPermissionAcceptUser (
30+ body : PermissionRequestAcceptUser
31+ ) : Observable < PermissionResponse > {
32+ return this . restService . put (
33+ this . endpoint + '/acceptUser' ,
34+ body ,
35+ undefined ,
36+ {
37+ observe : 'response' ,
38+ }
39+ ) ;
40+ }
3441
35- updatePermission (
36- body : PermissionRequest ,
37- id : number
38- ) : Observable < PermissionResponse > {
39- return this . restService . put ( this . endpoint , body , id , {
40- observe : 'response' ,
41- } ) ;
42- }
42+ updatePermission (
43+ body : PermissionRequest ,
44+ id : number
45+ ) : Observable < PermissionResponse > {
46+ return this . restService . put ( this . endpoint , body , id , {
47+ observe : 'response' ,
48+ } ) ;
49+ }
4350
44- getPermission ( id : number ) : Observable < PermissionResponse > {
45- return this . restService . get ( this . endpoint , { } , id ) . pipe (
46- map ( ( response : PermissionResponse ) => {
47- response . createdByName = this . userMinimalService . getUserNameFrom (
48- response . createdBy
49- ) ;
50- response . updatedByName = this . userMinimalService . getUserNameFrom (
51- response . updatedBy
52- ) ;
53- return response ;
54- } )
51+ getPermission ( id : number ) : Observable < PermissionResponse > {
52+ return this . restService . get ( this . endpoint , { } , id ) . pipe (
53+ map ( ( response : PermissionResponse ) => {
54+ response . createdByName = this . userMinimalService . getUserNameFrom (
55+ response . createdBy
5556 ) ;
56- }
57+ response . updatedByName = this . userMinimalService . getUserNameFrom (
58+ response . updatedBy
59+ ) ;
60+ return response ;
61+ } )
62+ ) ;
63+ }
5764
58- getPermissions (
59- limit : number = 1000 ,
60- offset : number = 0 ,
61- orderByColumn ?: string ,
62- orderByDirection ?: string ,
63- userId ?: number ,
64- organisationId ?: number
65- ) : Observable < PermissionGetManyResponse > {
66- if ( userId ) {
67- return this . restService . get ( this . endpoint , {
68- limit : limit ,
69- offset : offset ,
70- orderOn : orderByColumn ,
71- sort : orderByDirection ,
72- userId : userId ,
73- } ) ;
74- } else if ( organisationId ) {
75- return this . restService . get ( this . endpoint , {
76- limit : limit ,
77- offset : offset ,
78- orderOn : orderByColumn ,
79- sort : orderByDirection ,
80- organisationId : organisationId ,
81- } ) ;
82- } else {
83- return this . restService . get ( this . endpoint , {
84- limit : limit ,
85- offset : offset ,
86- orderOn : orderByColumn ,
87- sort : orderByDirection ,
88- } ) ;
89- }
65+ getPermissions (
66+ limit : number = 1000 ,
67+ offset : number = 0 ,
68+ orderByColumn ?: string ,
69+ orderByDirection ?: string ,
70+ userId ?: number ,
71+ organisationId ?: number
72+ ) : Observable < PermissionGetManyResponse > {
73+ if ( userId || organisationId ) {
74+ return this . restService . get ( this . endpoint , {
75+ limit : limit ,
76+ offset : offset ,
77+ orderOn : orderByColumn ,
78+ sort : orderByDirection ,
79+ userId : userId ,
80+ organisationId : organisationId ,
81+ } ) ;
82+ } else {
83+ return this . restService . get ( this . endpoint , {
84+ limit : limit ,
85+ offset : offset ,
86+ orderOn : orderByColumn ,
87+ sort : orderByDirection ,
88+ } ) ;
9089 }
90+ }
9191
92- deletePermission ( id : number ) {
93- return this . restService . delete ( this . endpoint , id ) ;
94- }
92+ deletePermission ( id : number ) {
93+ return this . restService . delete ( this . endpoint , id ) ;
94+ }
9595}
0 commit comments