Skip to content

Commit

Permalink
feat(web): remove deployment unpaginated
Browse files Browse the repository at this point in the history
  • Loading branch information
robot9706 committed Dec 3, 2024
1 parent cec5c5a commit 11bfeb2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
14 changes: 1 addition & 13 deletions web/crux/src/app/deploy/deploy.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,7 @@ export type DeploymentStatusDto = (typeof DEPLOYMENT_STATUS_VALUES)[number]

export type EnvironmentToConfigBundleNameMap = Record<string, string>

export class DeploymentQueryDto {
@IsOptional()
@IsInt()
@Type(() => Number)
@ApiProperty()
readonly skip?: number

@IsOptional()
@IsInt()
@Type(() => Number)
@ApiProperty()
readonly take?: number

export class DeploymentQueryDto extends PaginationQuery {
@IsOptional()
@IsString()
@Type(() => String)
Expand Down
18 changes: 3 additions & 15 deletions web/crux/src/app/deploy/deploy.http.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,13 @@ export default class DeployHttpController {
'Get the list of deployments. Request needs to include `teamSlug` in URL. Query could include `skip` and `take` to paginate. A deployment should include `id`, `prefix`, `status`, `note`, `audit` log details, project `name`, `id`, `type`, version `name`, `type`, `id`, and node `name`, `id`, `type`.',
summary: 'Fetch the list of deployments.',
})
@ApiExtraModels(DeploymentDto, DeploymentListDto)
@ApiOkResponse({
schema: {
anyOf: refs(DeploymentDto, DeploymentListDto),
},
description: 'List of deployments.',
})
@ApiOkResponse({ type: DeploymentQueryDto, description: 'Paginated list of deployments.' })
@ApiForbiddenResponse({ description: 'Unauthorized request for deployments.' })
async getDeployments(
@TeamSlug() teamSlug: string,
@Query() query: DeploymentQueryDto,
): Promise<DeploymentDto[] | DeploymentListDto> {
const page = await this.service.getDeployments(teamSlug, query)
if (!!query.skip || !!query.take) {
return page
}

// NOTE(@robot9706): If no pagination parameters are present return the items only to be backward compatible
return page.items
): Promise<DeploymentListDto> {
return await this.service.getDeployments(teamSlug, query)
}

@Get(ROUTE_DEPLOYMENT_ID)
Expand Down
8 changes: 4 additions & 4 deletions web/crux/src/app/deploy/deploy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ export default class DeployService {
},
},
},
nodeId: query?.nodeId,
status: query?.status ? this.mapper.statusDtoToDb(query.status) : undefined,
nodeId: query.nodeId,
status: query.status ? this.mapper.statusDtoToDb(query.status) : undefined,
}

if (query.configBundleId) {
Expand Down Expand Up @@ -876,8 +876,8 @@ export default class DeployService {
orderBy: {
createdAt: 'desc',
},
skip: query?.skip,
take: query?.take,
skip: query.skip,
take: query.take,
include: {
version: {
select: {
Expand Down
15 changes: 7 additions & 8 deletions web/crux/src/app/node/node.http.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { Identity } from '@ory/kratos-client'
import UuidParams from 'src/decorators/api-params.decorator'
import { CreatedResponse, CreatedWithLocation } from '../../interceptors/created-with-location.decorator'
import { DeploymentDto } from '../deploy/deploy.dto'
import { DeploymentDto, DeploymentListDto } from '../deploy/deploy.dto'
import DeployService from '../deploy/deploy.service'
import { DisableAuth, IdentityFromRequest } from '../token/jwt-auth.guard'
import NodeTeamAccessGuard from './guards/node.team-access.http.guard'
Expand All @@ -46,6 +46,7 @@ import NodeService from './node.service'
import DeleteNodeValidationPipe from './pipes/node.delete.pipe'
import NodeGenerateScriptValidationPipe from './pipes/node.generate-script.pipe'
import NodeGetScriptValidationPipe from './pipes/node.get-script.pipe'
import { PaginationQuery } from 'src/shared/dtos/paginating'

@Controller(`${ROUTE_TEAM_SLUG}/${ROUTE_NODES}`)
@ApiTags(ROUTE_NODES)
Expand Down Expand Up @@ -265,17 +266,15 @@ export default class NodeHttpController {
summary: 'Fetch the list of deployments.',
})
@ApiOkResponse({
type: DeploymentDto,
isArray: true,
description: 'List of deployments.',
type: DeploymentListDto,
description: 'Paginated list of deployments.',
})
@ApiForbiddenResponse({ description: 'Unauthorized request for deployments.' })
async getDeployments(@TeamSlug() teamSlug: string, @NodeId() nodeId: string): Promise<DeploymentDto[]> {
const paged = await this.deployService.getDeployments(teamSlug, {
async getDeployments(@TeamSlug() teamSlug: string, @NodeId() nodeId: string, @Query() query: PaginationQuery): Promise<DeploymentListDto> {
return await this.deployService.getDeployments(teamSlug, {
...query,
nodeId,
})

return paged.items
}

@Post(`${ROUTE_NODE_ID}/kick`)
Expand Down

0 comments on commit 11bfeb2

Please sign in to comment.