Skip to content

Commit

Permalink
fix: FIxed issue with api_url not populating
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-pisman committed Oct 2, 2023
1 parent 65ca82e commit 174856d
Showing 1 changed file with 33 additions and 38 deletions.
71 changes: 33 additions & 38 deletions src/app/services/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { FormGroup } from '@angular/forms';

Expand All @@ -17,27 +17,22 @@ import { SettingsService } from './settings.service';
@Injectable({ providedIn: 'root' })
export class ApiService {

API_URL: string | undefined;

constructor(private http: HttpClient, private settings: SettingsService) {
this.API_URL = settings.apiUrl;
}

constructor(private http: HttpClient, private settings: SettingsService) {}

// Authentification
login(username: string, password: string) {
let fd = new FormData();
fd.append('username', username);
fd.append('password', password);
return this.http.post(this.API_URL + '/auth/jwt/login', fd, { observe: 'response' });
return this.http.post(this.settings.apiUrl + '/auth/jwt/login', fd, { observe: 'response' });
}

// logout() {
// return this.http.post(this.API_URL + '/auth/jwt/logout', {});
// return this.http.post(this.settings.apiUrl + '/auth/jwt/logout', {});
// }

register(fd: FormGroup): Observable<any> {
return this.http.post(this.API_URL + '/auth/register', {
return this.http.post(this.settings.apiUrl + '/auth/register', {
email: fd.get('email')?.value,
password: fd.get('password')?.value,
first_name: fd.get('first_name')?.value,
Expand All @@ -49,7 +44,7 @@ export class ApiService {

// Get list of workspaces
getUserWorkspaces(): Observable<WorkspaceListModel> {
return this.http.get<WorkspaceListModel>(this.API_URL + '/workspaces');
return this.http.get<WorkspaceListModel>(this.settings.apiUrl + '/workspaces');
}

// Get workspace by workspace_id
Expand All @@ -68,69 +63,69 @@ export class ApiService {
params = polls ? params.append("include", "polls") : params;
}

return this.http.get<WorkspaceModel>(this.API_URL + '/workspaces/' + workspace_id, { params: params });
return this.http.get<WorkspaceModel>(this.settings.apiUrl + '/workspaces/' + workspace_id, { params: params });
}

// Create workspace
createWorkspace(data: any) {
return this.http.post(this.API_URL + '/workspaces', data);
return this.http.post(this.settings.apiUrl + '/workspaces', data);
}

// Update workspace
updateWorkspace(workspace_id: string, data: any) {
return this.http.patch(this.API_URL + '/workspaces/' + workspace_id, data);
return this.http.patch(this.settings.apiUrl + '/workspaces/' + workspace_id, data);
}

// Delete workspace
deleteWorkspace(workspace_id: string) {
return this.http.delete(this.API_URL + '/workspaces/' + workspace_id);
return this.http.delete(this.settings.apiUrl + '/workspaces/' + workspace_id);
}

// Get list of members in workspace
getWorkspaceMembers(workspace_id: string): Observable<MemberListModel> {
return this.http.get<MemberListModel>(this.API_URL + '/workspaces/' + workspace_id + '/members');
return this.http.get<MemberListModel>(this.settings.apiUrl + '/workspaces/' + workspace_id + '/members');
}

// Add member to workspace
addMemberToWorkspace(workspace_id: string, data: any) {
return this.http.post(this.API_URL + '/workspaces/' + workspace_id + '/members', data);
return this.http.post(this.settings.apiUrl + '/workspaces/' + workspace_id + '/members', data);
}

// Remove member from workspace
removeMemberFromWorkspace(workspace_id: string, member_workspace_id: string) {
return this.http.delete(this.API_URL + '/workspaces/' + workspace_id + '/members/' + member_workspace_id);
return this.http.delete(this.settings.apiUrl + '/workspaces/' + workspace_id + '/members/' + member_workspace_id);
}

// Get all policies
getAllWorkspacesPolicies(workspace_id: string): Observable<PolicyListModel> {
return this.http.get<PolicyListModel>(this.API_URL + '/workspaces/' + workspace_id + '/policies');
return this.http.get<PolicyListModel>(this.settings.apiUrl + '/workspaces/' + workspace_id + '/policies');
}

// Get workspace policy for specific account, or current user if account_id was not provided
getWorkspacePolicy(workspace_id: string, account_id?: string): Observable<PolicyModel> {
const options = account_id ? { params: { account_id: account_id } } : {};
return this.http.get<PolicyModel>(this.API_URL + '/workspaces/' + workspace_id + '/policy', options);
return this.http.get<PolicyModel>(this.settings.apiUrl + '/workspaces/' + workspace_id + '/policy', options);
}

// Update workspace policy
setWorkspacePolicy(workspace_id: string, data: any) {
return this.http.put(this.API_URL + '/workspaces/' + workspace_id + '/policy', data);
return this.http.put(this.settings.apiUrl + '/workspaces/' + workspace_id + '/policy', data);
}

getWorkspacePermissions(): Observable<Permissions> {
return this.http.get<Permissions>(this.API_URL + '/workspaces/permissions');
return this.http.get<Permissions>(this.settings.apiUrl + '/workspaces/permissions');
}

// Get list of groups in workspace
getWorkspaceGroups(id: string): Observable<GroupListModel> {
return this.http.get<GroupListModel>(this.API_URL + '/workspaces/' + id + '/groups');
return this.http.get<GroupListModel>(this.settings.apiUrl + '/workspaces/' + id + '/groups');
}

// Groups

// Create group in workspace
createGroup(workspace_id: string, data: any) {
return this.http.post(this.API_URL + '/workspaces/' + workspace_id + '/groups', data);
return this.http.post(this.settings.apiUrl + '/workspaces/' + workspace_id + '/groups', data);
}

// Get group by id
Expand All @@ -147,69 +142,69 @@ export class ApiService {
params = members ? params.append("include", "members") : params;
}

return this.http.get<GroupModel>(this.API_URL + '/groups/' + group_id, { params: params });
return this.http.get<GroupModel>(this.settings.apiUrl + '/groups/' + group_id, { params: params });
}

// Delete group by id
deleteGroup(group_id: string) {
return this.http.delete(this.API_URL + '/groups/' + group_id);
return this.http.delete(this.settings.apiUrl + '/groups/' + group_id);
}

// Update group
updateGroup(group_id: string, data: any) {
return this.http.patch(this.API_URL + '/groups/' + group_id, data);
return this.http.patch(this.settings.apiUrl + '/groups/' + group_id, data);
}

// Get list of members in group
getGroupMembers(group_id: string): Observable<MemberListModel> {
return this.http.get<MemberListModel>(this.API_URL + '/groups/' + group_id + '/members');
return this.http.get<MemberListModel>(this.settings.apiUrl + '/groups/' + group_id + '/members');
}

// Add member to group
addMemberToGroup(group_id: string, data: any) {
return this.http.post(this.API_URL + '/groups/' + group_id + '/members', data);
return this.http.post(this.settings.apiUrl + '/groups/' + group_id + '/members', data);
}

// Remove member from group
removeMemberFromGroup(group_id: string, member_id: string) {
return this.http.delete(this.API_URL + '/groups/' + group_id + '/members/' + member_id);
return this.http.delete(this.settings.apiUrl + '/groups/' + group_id + '/members/' + member_id);
}

// Get all group policies
getAllGroupsPolicies(group_id: string): Observable<PolicyListModel> {
return this.http.get<PolicyListModel>(this.API_URL + '/groups/' + group_id + '/policies');
return this.http.get<PolicyListModel>(this.settings.apiUrl + '/groups/' + group_id + '/policies');
}

// Get group policy for specific account, or current user if account_id was not provided
getGroupPolicy(group_id: string, account_id?: string): Observable<PolicyModel> {
const options = account_id ? { params: { account_id: account_id } } : {};
return this.http.get<PolicyModel>(this.API_URL + '/groups/' + group_id + '/policy', options);
return this.http.get<PolicyModel>(this.settings.apiUrl + '/groups/' + group_id + '/policy', options);
}

setGroupPolicy(group_id: string, data: any) {
return this.http.put(this.API_URL + '/groups/' + group_id + '/policy', data);
return this.http.put(this.settings.apiUrl + '/groups/' + group_id + '/policy', data);
}

getGroupPermissions(): Observable<Permissions> {
return this.http.get<Permissions>(this.API_URL + '/groups/permissions');
return this.http.get<Permissions>(this.settings.apiUrl + '/groups/permissions');
}

// Accounts
getAllAccounts(): Observable<AccountListModel> {
return this.http.get<AccountListModel>(this.API_URL + '/accounts');
return this.http.get<AccountListModel>(this.settings.apiUrl + '/accounts');
}


// Polls

// Get list of polls in workspace
getAllPolls(workspace_id: string): Observable<PollListModel> {
return this.http.get<PollListModel>(this.API_URL + '/workspaces/' + workspace_id + '/polls');
return this.http.get<PollListModel>(this.settings.apiUrl + '/workspaces/' + workspace_id + '/polls');
}

// Create poll in workspace
createPoll(workspace_id: string, data: NewPollRequestBody): Observable<PollModel> {
return this.http.post<PollModel>(this.API_URL + '/workspaces/' + workspace_id + '/polls', data);
return this.http.post<PollModel>(this.settings.apiUrl + '/workspaces/' + workspace_id + '/polls', data);
}

// Get poll by id
Expand All @@ -225,7 +220,7 @@ export class ApiService {
params = questions ? params.append("include", "members") : params;
params = policies ? params.append("include", "policies") : params;
}
return this.http.get<PollModel>(this.API_URL + '/polls/' + poll_id, { params: params });
return this.http.get<PollModel>(this.settings.apiUrl + '/polls/' + poll_id, { params: params });
}

}

0 comments on commit 174856d

Please sign in to comment.