2022-11-19 14:21:26 +00:00
|
|
|
// api routes
|
|
|
|
import {
|
|
|
|
USER_WORKSPACES,
|
|
|
|
WORKSPACES_ENDPOINT,
|
|
|
|
INVITE_WORKSPACE,
|
|
|
|
WORKSPACE_DETAIL,
|
|
|
|
JOIN_WORKSPACE,
|
|
|
|
WORKSPACE_MEMBERS,
|
|
|
|
WORKSPACE_MEMBER_DETAIL,
|
|
|
|
WORKSPACE_INVITATIONS,
|
|
|
|
WORKSPACE_INVITATION_DETAIL,
|
|
|
|
USER_WORKSPACE_INVITATION,
|
|
|
|
USER_WORKSPACE_INVITATIONS,
|
2022-12-12 14:44:34 +00:00
|
|
|
LAST_ACTIVE_WORKSPACE_AND_PROJECTS,
|
2022-11-19 14:21:26 +00:00
|
|
|
} from "constants/api-routes";
|
|
|
|
// services
|
|
|
|
import APIService from "lib/services/api.service";
|
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
// types
|
2022-12-16 14:56:25 +00:00
|
|
|
import {
|
|
|
|
IWorkspace,
|
|
|
|
IWorkspaceMember,
|
|
|
|
IWorkspaceMemberInvitation,
|
|
|
|
ILastActiveWorkspaceDetails,
|
|
|
|
} from "types";
|
2022-12-12 04:49:52 +00:00
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
class WorkspaceService extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async userWorkspaces(): Promise<IWorkspace[]> {
|
2022-11-19 14:21:26 +00:00
|
|
|
return this.get(USER_WORKSPACES)
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async createWorkspace(data: Partial<IWorkspace>): Promise<IWorkspace> {
|
2022-11-19 14:21:26 +00:00
|
|
|
return this.post(WORKSPACES_ENDPOINT, data)
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async updateWorkspace(workspaceSlug: string, data: Partial<IWorkspace>): Promise<IWorkspace> {
|
|
|
|
return this.patch(WORKSPACE_DETAIL(workspaceSlug), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-12-12 04:49:52 +00:00
|
|
|
|
|
|
|
async deleteWorkspace(workspaceSlug: string): Promise<any> {
|
|
|
|
return this.delete(WORKSPACE_DETAIL(workspaceSlug))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async inviteWorkspace(workspaceSlug: string, data: any): Promise<any> {
|
|
|
|
return this.post(INVITE_WORKSPACE(workspaceSlug), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-12-12 04:49:52 +00:00
|
|
|
|
|
|
|
async joinWorkspace(workspaceSlug: string, InvitationId: string, data: any): Promise<any> {
|
|
|
|
return this.post(JOIN_WORKSPACE(workspaceSlug, InvitationId), data, {
|
2022-11-19 14:21:26 +00:00
|
|
|
headers: {},
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async joinWorkspaces(data: any): Promise<any> {
|
|
|
|
return this.post(USER_WORKSPACE_INVITATIONS, data)
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-16 14:56:25 +00:00
|
|
|
async getLastActiveWorkspaceAndProjects(): Promise<ILastActiveWorkspaceDetails> {
|
|
|
|
return this.get(LAST_ACTIVE_WORKSPACE_AND_PROJECTS)
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async userWorkspaceInvitations(): Promise<IWorkspaceMemberInvitation[]> {
|
2022-11-19 14:21:26 +00:00
|
|
|
return this.get(USER_WORKSPACE_INVITATIONS)
|
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async workspaceMembers(workspaceSlug: string): Promise<IWorkspaceMember[]> {
|
|
|
|
return this.get(WORKSPACE_MEMBERS(workspaceSlug))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-12-06 04:41:56 +00:00
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async updateWorkspaceMember(
|
|
|
|
workspaceSlug: string,
|
|
|
|
memberId: string,
|
|
|
|
data: Partial<IWorkspaceMember>
|
|
|
|
): Promise<IWorkspaceMember> {
|
|
|
|
return this.put(WORKSPACE_MEMBER_DETAIL(workspaceSlug, memberId), data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-12-06 04:41:56 +00:00
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async deleteWorkspaceMember(workspaceSlug: string, memberId: string): Promise<any> {
|
|
|
|
return this.delete(WORKSPACE_MEMBER_DETAIL(workspaceSlug, memberId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async workspaceInvitations(workspaceSlug: string): Promise<IWorkspaceMemberInvitation[]> {
|
|
|
|
return this.get(WORKSPACE_INVITATIONS(workspaceSlug))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async getWorkspaceInvitation(invitationId: string): Promise<IWorkspaceMemberInvitation> {
|
|
|
|
return this.get(USER_WORKSPACE_INVITATION(invitationId), { headers: {} })
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
async updateWorkspaceInvitation(
|
|
|
|
workspaceSlug: string,
|
|
|
|
invitationId: string
|
|
|
|
): Promise<IWorkspaceMemberInvitation> {
|
|
|
|
return this.put(WORKSPACE_INVITATION_DETAIL(workspaceSlug, invitationId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-12-12 04:49:52 +00:00
|
|
|
|
|
|
|
async deleteWorkspaceInvitations(workspaceSlug: string, invitationId: string): Promise<any> {
|
|
|
|
return this.delete(WORKSPACE_INVITATION_DETAIL(workspaceSlug, invitationId))
|
2022-11-19 14:21:26 +00:00
|
|
|
.then((response) => {
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new WorkspaceService();
|