-
-
Notifications
You must be signed in to change notification settings - Fork 115
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): Create controller for Variable module (#395)
Co-authored-by: vr-varad <varadgupta21#gmail.com>
- Loading branch information
Showing
3 changed files
with
457 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { APIClient } from '../core/client' | ||
import { parseResponse } from '../core/response-parser' | ||
import { ClientResponse } from '../types/index.types' | ||
import { | ||
CreateVariableRequest, | ||
CreateVariableResponse, | ||
DeleteVariableRequest, | ||
DeleteVariableResponse, | ||
GetAllVariablesOfEnvironmentRequest, | ||
GetAllVariablesOfEnvironmentResponse, | ||
GetAllVariablesOfProjectRequest, | ||
GetAllVariablesOfProjectResponse, | ||
RollBackVariableRequest, | ||
RollBackVariableResponse, | ||
UpdateVariableRequest, | ||
UpdateVariableResponse | ||
} from '../types/variable.types' | ||
|
||
export default class VariableController { | ||
private apiClient: APIClient | ||
|
||
constructor(private readonly backendUrl: string) { | ||
this.apiClient = new APIClient(this.backendUrl) | ||
} | ||
|
||
async createVariable( | ||
request: CreateVariableRequest, | ||
headers: Record<string, string> | ||
): Promise<ClientResponse<CreateVariableResponse>> { | ||
const response = await this.apiClient.post( | ||
`/api/variable/${request.projectId}`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<CreateVariableResponse>(response) | ||
} | ||
|
||
async updateVariable( | ||
request: UpdateVariableRequest, | ||
headers: Record<string, string> | ||
): Promise<ClientResponse<UpdateVariableResponse>> { | ||
const response = await this.apiClient.put( | ||
`/api/variable/${request.variableId}`, | ||
request, | ||
headers | ||
) | ||
|
||
return await parseResponse<UpdateVariableResponse>(response) | ||
} | ||
|
||
async rollbackVariable( | ||
request: RollBackVariableRequest, | ||
headers: Record<string, string> | ||
): Promise<ClientResponse<RollBackVariableResponse>> { | ||
const response = await this.apiClient.put( | ||
`/api/variable/${request.variableId}/rollback/${request.version}?environmentId=${request.environmentId}`, | ||
request, | ||
headers | ||
) | ||
|
||
return await parseResponse<RollBackVariableResponse>(response) | ||
} | ||
|
||
async deleteVariable( | ||
request: DeleteVariableRequest, | ||
headers: Record<string, string> | ||
): Promise<ClientResponse<DeleteVariableResponse>> { | ||
const response = await this.apiClient.delete( | ||
`/api/variable/${request.variableId}`, | ||
headers | ||
) | ||
|
||
return await parseResponse<DeleteVariableResponse>(response) | ||
} | ||
|
||
async getAllVariablesOfProject( | ||
request: GetAllVariablesOfProjectRequest, | ||
headers: Record<string, string> | ||
): Promise<ClientResponse<GetAllVariablesOfProjectResponse>> { | ||
let url = `/api/variable/${request.projectId}` | ||
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) | ||
|
||
return await parseResponse<GetAllVariablesOfProjectResponse>(response) | ||
} | ||
|
||
async getAllVariablesOfEnvironment( | ||
request: GetAllVariablesOfEnvironmentRequest, | ||
headers: Record<string, string> | ||
): Promise<ClientResponse<GetAllVariablesOfEnvironmentResponse>> { | ||
let url = `/api/variable/${request.projectId}/${request.environmentId}` | ||
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) | ||
|
||
return await parseResponse<GetAllVariablesOfEnvironmentResponse>(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { Page } from '../../../../apps/cli/src/types/index.types' | ||
|
||
export interface CreateVariableRequest { | ||
projectId: string | ||
name: string | ||
note?: string | ||
entries?: [ | ||
{ | ||
value: string | ||
environmentId: string | ||
} | ||
] | ||
} | ||
|
||
export interface CreateVariableResponse { | ||
id: string | ||
name: string | ||
createdAt: string | ||
updatedAt: string | ||
note: string | null | ||
lastUpdatedById: string | ||
projectId: string | ||
project: { | ||
workspaceId: string | ||
} | ||
versions: [ | ||
{ | ||
value: string | ||
environmentId: string | ||
} | ||
] | ||
} | ||
export interface UpdateVariableRequest { | ||
variableId: string | ||
name?: string | ||
entries?: [ | ||
{ | ||
value: string | ||
environmentId: string | ||
} | ||
] | ||
} | ||
export interface UpdateVariableResponse { | ||
variable: { | ||
id: string | ||
name: string | ||
note: string | ||
} | ||
updatedVersions: [ | ||
{ | ||
value: string | ||
environmentId: string | ||
} | ||
] | ||
} | ||
|
||
export interface RollBackVariableRequest { | ||
variableId: string | ||
version: number | ||
environmentId: string | ||
} | ||
|
||
export interface RollBackVariableResponse { | ||
count: string | ||
} | ||
|
||
export interface DeleteVariableRequest { | ||
variableId: string | ||
} | ||
|
||
export interface DeleteVariableResponse {} | ||
|
||
export interface GetAllVariablesOfProjectRequest { | ||
projectId: string | ||
page?: number | ||
limit?: number | ||
sort?: string | ||
order?: string | ||
search?: string | ||
} | ||
|
||
export interface GetAllVariablesOfProjectResponse | ||
extends Page<{ | ||
variable: { | ||
id: string | ||
name: string | ||
createdAt: string | ||
updatedAt: string | ||
note: string | null | ||
lastUpdatedById: string | ||
projectId: string | ||
lastUpdatedBy: { | ||
id: string | ||
name: string | ||
} | ||
} | ||
values: { | ||
environment: { | ||
id: string | ||
name: string | ||
} | ||
value: string | ||
version: number | ||
} | ||
}> {} | ||
|
||
export interface GetAllVariablesOfEnvironmentRequest { | ||
projectId: string | ||
environmentId: string | ||
page?: number | ||
limit?: number | ||
sort?: string | ||
order?: string | ||
search?: string | ||
} | ||
|
||
export interface GetAllVariablesOfEnvironmentResponse | ||
extends Page<{ | ||
name: string | ||
value: string | ||
isPlaintext: boolean | ||
}> {} |
Oops, something went wrong.