Skip to content

Commit

Permalink
Add endpoint to remove views
Browse files Browse the repository at this point in the history
  • Loading branch information
pro1code1hack committed Jun 26, 2024
1 parent 2f140d5 commit 4f33a03
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
41 changes: 41 additions & 0 deletions apps/production/src/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ApiBearerAuth,
ApiOperation,
ApiOkResponse,
ApiNoContentResponse,
} from '@nestjs/swagger'
import { ILike } from 'typeorm'
import * as _isEmpty from 'lodash/isEmpty'
Expand Down Expand Up @@ -1988,4 +1989,44 @@ export class ProjectController {

return this.projectsViewsRepository.findView(params.viewId)
}

@ApiOperation({ summary: 'Delete project view' })
@ApiNoContentResponse()
@ApiBearerAuth()
@HttpCode(HttpStatus.NO_CONTENT)
@Delete(':projectId/views/:viewId')
@UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async deleteProjectView(
@Param() params: ProjectIdDto & ProjectViewIdDto,
@CurrentUserId() userId: string,
) {
const project = await this.projectService.findProject(params.projectId, [
'admin',
'share',
])

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

const user = await this.userService.findUserV2(userId, ['roles'])

if (!user) {
throw new NotFoundException('User not found.')
}

this.projectService.allowedToManage(project, userId, user.roles)

const view = await this.projectsViewsRepository.findProjectView(
params.projectId,
params.viewId,
)

if (!view) {
throw new NotFoundException('View not found.')
}

await this.projectsViewsRepository.deleteProjectView(params.viewId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export class ProjectsViewsRepository {
async updateProjectView(id: string, data: UpdateProjectViewDto) {
await this.viewsRepository.update({ id }, data)
}

async deleteProjectView(id: string) {
await this.viewsRepository.delete({ id })
}
}

0 comments on commit 4f33a03

Please sign in to comment.