forked from keyshade-xyz/keyshade
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-client): Added workspace role controller (keyshade-xyz#430)
- Loading branch information
Showing
18 changed files
with
435 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { APIClient } from '@api-client/core/client' | ||
import { parsePaginationUrl } from '@api-client/core/pagination-parser' | ||
import { parseResponse } from '@api-client/core/response-parser' | ||
import { ClientResponse } from '@api-client/types/index.types' | ||
import { | ||
CreateWorkspaceRoleRequest, | ||
CreateWorkspaceRoleResponse, | ||
UpdateWorkspaceRoleRequest, | ||
UpdateWorkspaceRoleResponse, | ||
DeleteWorkspaceRoleRequest, | ||
DeleteWorkspaceRoleResponse, | ||
CheckWorkspaceRoleExistsResponse, | ||
GetWorkspaceRoleRequest, | ||
GetWorkspaceRoleResponse, | ||
GetWorkspaceRolesOfWorkspaceRequest, | ||
GetWorkspaceRolesOfWorkspaceResponse, | ||
CheckWorkspaceRoleExistsRequest | ||
} from '@api-client/types/workspace-role.types' | ||
|
||
export default class WorkspaceRoleController { | ||
private apiClient: APIClient | ||
|
||
constructor(private readonly backendUrl: string) { | ||
this.apiClient = new APIClient(this.backendUrl) | ||
} | ||
|
||
async createWorkspaceRole( | ||
request: CreateWorkspaceRoleRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<CreateWorkspaceRoleResponse>> { | ||
const response = await this.apiClient.post( | ||
`/api/workspace-role/${request.workspaceSlug}`, | ||
request, | ||
headers | ||
) | ||
|
||
return await parseResponse<CreateWorkspaceRoleResponse>(response) | ||
} | ||
|
||
async updateWorkspaceRole( | ||
request: UpdateWorkspaceRoleRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<UpdateWorkspaceRoleResponse>> { | ||
const response = await this.apiClient.put( | ||
`/api/workspace-role/${request.workspaceRoleSlug}`, | ||
request, | ||
headers | ||
) | ||
|
||
return await parseResponse<UpdateWorkspaceRoleResponse>(response) | ||
} | ||
|
||
async deleteWorkspaceRole( | ||
request: DeleteWorkspaceRoleRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<DeleteWorkspaceRoleResponse>> { | ||
const response = await this.apiClient.delete( | ||
`/api/workspace-role/${request.workspaceRoleSlug}`, | ||
headers | ||
) | ||
|
||
return await parseResponse<DeleteWorkspaceRoleResponse>(response) | ||
} | ||
|
||
async checkWorkspaceRoleExists( | ||
request: CheckWorkspaceRoleExistsRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<CheckWorkspaceRoleExistsResponse>> { | ||
const response = await this.apiClient.get( | ||
`/api/workspace-role/${request.workspaceSlug}/exists/${request.workspaceRoleName}`, | ||
headers | ||
) | ||
|
||
return await parseResponse<CheckWorkspaceRoleExistsResponse>(response) | ||
} | ||
|
||
async getWorkspaceRole( | ||
request: GetWorkspaceRoleRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<GetWorkspaceRoleResponse>> { | ||
const response = await this.apiClient.get( | ||
`/api/workspace-role/${request.workspaceRoleSlug}`, | ||
headers | ||
) | ||
|
||
return await parseResponse<GetWorkspaceRoleResponse>(response) | ||
} | ||
|
||
async getWorkspaceRolesOfWorkspace( | ||
request: GetWorkspaceRolesOfWorkspaceRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<GetWorkspaceRolesOfWorkspaceResponse>> { | ||
const url = parsePaginationUrl( | ||
`/api/workspace-role/${request.workspaceSlug}/all`, | ||
request | ||
) | ||
const response = await this.apiClient.get(url, headers) | ||
|
||
return await parseResponse<GetWorkspaceRolesOfWorkspaceResponse>(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { PageRequest } from '@api-client/types/index.types' | ||
|
||
/** | ||
* Constructs a URL by appending the given page request | ||
* parameters to the given base URL. | ||
* | ||
* @param baseUrl The base URL to append to. | ||
* @param request The page request to parse. | ||
* @returns The constructed URL. | ||
*/ | ||
export function parsePaginationUrl( | ||
baseUrl: string, | ||
request: PageRequest | ||
): string { | ||
let url = `${baseUrl}?` | ||
request.page && (url += `page=${request.page}&`) | ||
request.limit && (url += `limit=${request.limit}&`) | ||
request.sort && (url += `sort=${request.sort}&`) | ||
request.order && (url += `order=${request.order}&`) | ||
request.search && (url += `search=${request.search}&`) | ||
|
||
return url | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.