Skip to content

Commit

Permalink
Add GET monitors by project ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaumaus committed Aug 25, 2024
1 parent 623fa83 commit c84708f
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions apps/production/src/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
ApiOkResponse,
ApiNoContentResponse,
} from '@nestjs/swagger'
import { FindConditions, ILike, In } from 'typeorm'
import { Equal, FindConditions, ILike, In } from 'typeorm'
import * as _isEmpty from 'lodash/isEmpty'
import * as _map from 'lodash/map'
import * as _trim from 'lodash/trim'
Expand Down Expand Up @@ -1892,7 +1892,7 @@ export class ProjectController {
await this.projectService.deleteShare(shareId)
}

@ApiOperation({ summary: 'Get monitors for the project' })
@ApiOperation({ summary: 'Get monitors for all user projects' })
@ApiBearerAuth()
@ApiOkResponse({ type: MonitorEntity })
@Get('/monitors')
Expand Down Expand Up @@ -2191,6 +2191,47 @@ export class ProjectController {
return this.projectService.sendPredictAiRequest(params.projectId)
}

@ApiOperation({ summary: 'Get monitors for a project' })
@ApiBearerAuth()
@ApiOkResponse({ type: MonitorEntity })
@Get(':projectId/monitors')
@Auth([], true, true)
public async getProjectMonitors(
@Param() { projectId }: ProjectIdDto,
@CurrentUserId() userId: string,
@Query('take') take: number | undefined,
@Query('skip') skip: number | undefined,
@Headers() headers: { 'x-password'?: string },
): Promise<Pagination<MonitorEntity>> {
this.logger.log({ userId, take, skip }, 'GET /project/:projectId/monitors')

const project = await this.projectService.findProject(projectId, [
'admin',
'share',
])

if (!project) {
throw new NotFoundException('Project not found.')
}

this.projectService.allowedToView(project, userId, headers['x-password'])

const result = await this.projectService.paginateMonitors(
{
take,
skip,
},
{ project: Equal(project.id) },
)

result.results = _map(result.results, monitor => ({
..._omit(monitor, ['project']),
projectId: monitor.project.id,
}))

return result
}

@ApiOperation({ summary: 'Create monitor for the project' })
@ApiBearerAuth()
@ApiOkResponse({ type: MonitorEntity })
Expand Down

0 comments on commit c84708f

Please sign in to comment.