@@ -13,22 +13,26 @@ export class ClientService {
1313 private readonly roleCollaborationService : RoleCollaborationService
1414 ) { }
1515
16- async getClientList ( userId : string ) {
16+ async getClientList ( userId : string , orderBy : string = 'created_at' , sort : string = 'asc' ) {
1717 const currentTeamData : any = await this . teamService . getCurrentTeam ( userId ) ;
1818 const currentTeamId = currentTeamData . data . user_team [ 0 ] . team . id ;
1919 const isAdmin =
2020 currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
2121 this . roleCollaborationService . ROLES_IDS . ROLE_ADMIN ;
2222
23- if ( isAdmin ) {
23+ const isOwner =
24+ currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
25+ this . roleCollaborationService . ROLES_IDS . ROLE_OWNER ;
26+
27+ if ( isAdmin || isOwner ) {
2428 const query = `{
2529 client(
2630 where: {
2731 team_id: {
2832 _eq: "${ currentTeamId } "
2933 }
3034 }
31- order_by: {created_at: asc }
35+ order_by: {${ orderBy } : ${ sort } }
3236 ) {
3337 id
3438 name
@@ -68,32 +72,38 @@ export class ClientService {
6872 currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
6973 this . roleCollaborationService . ROLES_IDS . ROLE_ADMIN ;
7074
71- if ( isAdmin ) {
72- const query = `mutation {
73- insert_client(
74- objects: {
75- name: ${ name ? '"' + name + '"' : null }
76- team_id: "${ currentTeamId } "
77- language: ${ language ? '"' + language + '"' : null }
78- avatar: ${ avatar ? '"' + avatar + '"' : null }
79- country: ${ country ? '"' + country + '"' : null }
80- city: ${ city ? '"' + city + '"' : null }
81- state: ${ state ? '"' + state + '"' : null }
82- phone: ${ phone ? '"' + phone + '"' : null }
83- email: ${ email ? '"' + email + '"' : null }
84- zip: ${ zip ? '"' + zip + '"' : null }
85- company_name: "${ companyName } "
86- }
87- ) {
88- returning {
89- id
90- }
91- }
92- }` ;
75+ const isOwner =
76+ currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
77+ this . roleCollaborationService . ROLES_IDS . ROLE_OWNER ;
78+
79+ if ( isAdmin || isOwner ) {
80+ const variables = {
81+ object : {
82+ name : name || null ,
83+ team_id : currentTeamId ,
84+ language : language || null ,
85+ avatar : avatar || null ,
86+ country : country || null ,
87+ city : city || null ,
88+ state : state || null ,
89+ phone : phone || null ,
90+ email : email || null ,
91+ zip : zip || null ,
92+ company_name : companyName ,
93+ } ,
94+ } ;
95+
96+ const query = `mutation insert_client($object: [client_insert_input!]!) {
97+ insert_client:insert_client(objects: $object) {
98+ returning {
99+ id
100+ }
101+ }
102+ }` ;
93103
94104 return new Promise ( ( resolve , reject ) => {
95105 this . httpRequestsService
96- . request ( query )
106+ . graphql ( query , variables )
97107 . subscribe ( ( res : AxiosResponse ) => resolve ( res ) , ( error : AxiosError ) => reject ( error ) ) ;
98108 } ) ;
99109 } else {
@@ -107,7 +117,11 @@ export class ClientService {
107117 currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
108118 this . roleCollaborationService . ROLES_IDS . ROLE_ADMIN ;
109119
110- if ( isAdmin ) {
120+ const isOwner =
121+ currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
122+ this . roleCollaborationService . ROLES_IDS . ROLE_OWNER ;
123+
124+ if ( isAdmin || isOwner ) {
111125 const query = `mutation {
112126 delete_client(
113127 where: {
@@ -150,7 +164,11 @@ export class ClientService {
150164 currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
151165 this . roleCollaborationService . ROLES_IDS . ROLE_ADMIN ;
152166
153- if ( isAdmin ) {
167+ const isOwner =
168+ currentTeamData . data . user_team [ 0 ] . role_collaboration_id ===
169+ this . roleCollaborationService . ROLES_IDS . ROLE_OWNER ;
170+
171+ if ( isAdmin || isOwner ) {
154172 const query = `mutation {
155173 update_client(
156174 where: {
0 commit comments