Skip to content

Commit

Permalink
applied suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Sep 14, 2024
1 parent ef7a770 commit 8085710
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 130 deletions.
2 changes: 1 addition & 1 deletion packages/api-client/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Config } from 'jest'

const config: Config = {
displayName: 'api',
testMatch: ['**/workspace-role.spec.ts'],
testMatch: ['**/*.spec.ts'],
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
Expand Down
12 changes: 5 additions & 7 deletions packages/api-client/src/controllers/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIClient } from '@api-client/core/client'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'
import { parseResponse } from '@api-client/core/response-parser'
import {
CreateEnvironmentRequest,
Expand Down Expand Up @@ -63,13 +64,10 @@ export default class EnvironmentController {
request: GetAllEnvironmentsOfProjectRequest,
headers?: Record<string, string>
): Promise<ClientResponse<GetAllEnvironmentsOfProjectResponse>> {
let url = `/api/environment/all/${request.projectSlug}?`
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}&`)

const url = parsePaginationUrl(
`/api/environment/all/${request.projectSlug}`,
request
)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetAllEnvironmentsOfProjectResponse>(response)
Expand Down
12 changes: 5 additions & 7 deletions packages/api-client/src/controllers/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { APIClient } from '@api-client/core/client'
import { ClientResponse } from '@api-client/types/index.types'
import { parseResponse } from '@api-client/core/response-parser'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'

export default class IntegrationController {
private apiClient: APIClient
Expand Down Expand Up @@ -60,13 +61,10 @@ export default class IntegrationController {
request: GetAllIntegrationRequest,
headers?: Record<string, string>
): Promise<ClientResponse<GetAllIntegrationResponse>> {
let url = `/api/integration/all/${request.workspaceSlug}`
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}&`)

const url = parsePaginationUrl(
`/api/integration/all/${request.workspaceSlug}`,
request
)
const response = await this.apiClient.get(url, headers)
return await parseResponse<GetAllIntegrationResponse>(response)
}
Expand Down
21 changes: 9 additions & 12 deletions packages/api-client/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
UpdateProjectResponse
} from '@api-client/types/project.types'
import { parseResponse } from '@api-client/core/response-parser'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'

export default class ProjectController {
private apiClient: APIClient
Expand Down Expand Up @@ -121,12 +122,10 @@ export default class ProjectController {
request: GetForkRequest,
headers: Record<string, string>
): Promise<ClientResponse<GetForkResponse>> {
let url = `/api/project/${request.projectSlug}/forks`
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}&`)
const url = parsePaginationUrl(
`/api/project/${request.projectSlug}/forks`,
request
)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetForkResponse>(response)
Expand All @@ -136,12 +135,10 @@ export default class ProjectController {
request: GetAllProjectsRequest,
headers: Record<string, string>
): Promise<ClientResponse<GetAllProjectsResponse>> {
let url = `/api/project/all/${request.workspaceSlug}`
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}&`)
const url = parsePaginationUrl(
`/api/project/all/${request.workspaceSlug}`,
request
)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetAllProjectsResponse>(response)
Expand Down
16 changes: 9 additions & 7 deletions packages/api-client/src/controllers/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UpdateSecretRequest,
UpdateSecretResponse
} from '@api-client/types/secret.types'
import { parsePaginationUrl } from '@api-client/core/pagination-parser'

export default class SecretController {
private apiClient: APIClient
Expand Down Expand Up @@ -78,13 +79,14 @@ export default class SecretController {
request: GetAllSecretsOfProjectRequest,
headers?: Record<string, string>
): Promise<ClientResponse<GetAllSecretsOfProjectResponse>> {
let url = `/api/secret/${request.projectSlug}?decryptValue=true`
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}&`)
const response = await this.apiClient.get(url, headers)
const url = parsePaginationUrl(
`/api/secret/${request.projectSlug}`,
request
)
const response = await this.apiClient.get(
`${url}&decryptValue=true`,
headers
)

return await parseResponse<GetAllSecretsOfProjectResponse>(response)
}
Expand Down
11 changes: 5 additions & 6 deletions packages/api-client/src/controllers/variable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 {
Expand Down Expand Up @@ -77,12 +78,10 @@ export default class VariableController {
request: GetAllVariablesOfProjectRequest,
headers: Record<string, string>
): Promise<ClientResponse<GetAllVariablesOfProjectResponse>> {
let url = `/api/variable/${request.projectSlug}`
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}&`)
const url = parsePaginationUrl(
`/api/variable/${request.projectSlug}`,
request
)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetAllVariablesOfProjectResponse>(response)
Expand Down
15 changes: 7 additions & 8 deletions packages/api-client/src/controllers/workspace-role.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 {
Expand All @@ -13,7 +14,7 @@ import {
GetWorkspaceRoleResponse,
GetWorkspaceRolesOfWorkspaceRequest,
GetWorkspaceRolesOfWorkspaceResponse,
CheckWOrkspaceRoleExistsRequest
CheckWorkspaceRoleExistsRequest
} from '@api-client/types/workspace-role.types'

export default class WorkspaceRoleController {
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class WorkspaceRoleController {
}

async checkWorkspaceRoleExists(
request: CheckWOrkspaceRoleExistsRequest,
request: CheckWorkspaceRoleExistsRequest,
headers?: Record<string, string>
): Promise<ClientResponse<CheckWorkspaceRoleExistsResponse>> {
const response = await this.apiClient.get(
Expand All @@ -89,12 +90,10 @@ export default class WorkspaceRoleController {
request: GetWorkspaceRolesOfWorkspaceRequest,
headers?: Record<string, string>
): Promise<ClientResponse<GetWorkspaceRolesOfWorkspaceResponse>> {
let url = `/api/workspace-role/${request.workspaceSlug}/all?`
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}&`)
const url = parsePaginationUrl(
`/api/workspace-role/${request.workspaceSlug}/all`,
request
)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetWorkspaceRolesOfWorkspaceResponse>(response)
Expand Down
9 changes: 2 additions & 7 deletions packages/api-client/src/controllers/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 {
Expand Down Expand Up @@ -79,13 +80,7 @@ export default class WorkspaceController {
request: GetAllWorkspacesOfUserRequest,
headers?: Record<string, string>
): Promise<ClientResponse<GetAllWorkspacesOfUserResponse>> {
let url = `/api/workspace?`
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}&`)

const url = parsePaginationUrl('/api/workspace', request)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetAllWorkspacesOfUserResponse>(response)
Expand Down
23 changes: 23 additions & 0 deletions packages/api-client/src/core/pagination-parser.ts
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
}
11 changes: 3 additions & 8 deletions packages/api-client/src/types/environment.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from './index.types'
import { PageRequest, PageResponse } from './index.types'

export interface CreateEnvironmentRequest {
name: string
Expand Down Expand Up @@ -49,17 +49,12 @@ export interface GetEnvironmentResponse {
projectId: string
}

export interface GetAllEnvironmentsOfProjectRequest {
export interface GetAllEnvironmentsOfProjectRequest extends PageRequest {
projectSlug: string
page?: number
limit?: number
sort?: string
order?: string
search?: string
}

export interface GetAllEnvironmentsOfProjectResponse
extends Page<{
extends PageResponse<{
id: string
slug: string
name: string
Expand Down
4 changes: 2 additions & 2 deletions packages/api-client/src/types/event.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from './index.types'
import { PageResponse } from './index.types'

export enum EventSource {
SECRET,
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface GetEventsRequest {
}

export interface GetEventsResponse
extends Page<{
extends PageResponse<{
id: string
source: EventSource
triggerer: EventTriggerer
Expand Down
10 changes: 9 additions & 1 deletion packages/api-client/src/types/index.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Page<T> {
export interface PageResponse<T> {
items: T[]
metadata: {
page: number
Expand All @@ -15,6 +15,14 @@ export interface Page<T> {
}
}

export interface PageRequest {
page?: number
limit?: number
sort?: string
order?: string
search?: string
}

export interface ResponseError {
message: string
error: string
Expand Down
11 changes: 3 additions & 8 deletions packages/api-client/src/types/integration.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from './index.types'
import { PageRequest, PageResponse } from './index.types'

export enum IntegrationType {
DISCORD,
Expand Down Expand Up @@ -109,17 +109,12 @@ export interface GetIntegrationResponse {
environmentId: string
}

export interface GetAllIntegrationRequest {
page?: number
limit?: number
sort?: string
order?: string
search?: string
export interface GetAllIntegrationRequest extends PageRequest {
workspaceSlug: string
}

export interface GetAllIntegrationResponse
extends Page<{
extends PageResponse<{
id: string
name: string
slug: string
Expand Down
20 changes: 5 additions & 15 deletions packages/api-client/src/types/project.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from './index.types'
import { PageRequest, PageResponse } from './index.types'

export interface CreateProjectRequest {
name: string
Expand Down Expand Up @@ -120,18 +120,13 @@ export interface UnlinkProjectRequest {

export interface UnlinkProjectResponse {}

export interface GetForkRequest {
export interface GetForkRequest extends PageRequest {
projectSlug: string
workspaceSlug: string
page?: number
limit?: number
sort?: string
order?: string
search?: string
}

export interface GetForkResponse
extends Page<{
extends PageResponse<{
id: string
name: string
slug: string
Expand All @@ -150,17 +145,12 @@ export interface GetForkResponse
forkedFromId: string
}> {}

export interface GetAllProjectsRequest {
export interface GetAllProjectsRequest extends PageRequest {
workspaceSlug: string
page?: number
limit?: number
sort?: string
order?: string
search?: string
}

export interface GetAllProjectsResponse
extends Page<{
extends PageResponse<{
id: string
name: string
slug: string
Expand Down
11 changes: 3 additions & 8 deletions packages/api-client/src/types/secret.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from './index.types'
import { PageRequest, PageResponse } from './index.types'

export interface CreateSecretRequest {
projectSlug: string
Expand Down Expand Up @@ -78,16 +78,11 @@ export interface RollBackSecretResponse {
count: string
}

export interface GetAllSecretsOfProjectRequest {
export interface GetAllSecretsOfProjectRequest extends PageRequest {
projectSlug: string
page?: number
limit?: number
sort?: string
order?: string
search?: string
}
export interface GetAllSecretsOfProjectResponse
extends Page<{
extends PageResponse<{
secret: {
id: string
slug: string
Expand Down
Loading

0 comments on commit 8085710

Please sign in to comment.