| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | Get, |
| 6 | HttpCode, |
| 7 | HttpStatus, |
| 8 | Param, |
| 9 | Put, |
| 10 | Session, |
| 11 | } from '@nestjs/common'; |
| 12 | import { |
| 13 | ApiBadRequestResponse, |
| 14 | ApiForbiddenResponse, |
| 15 | ApiNoContentResponse, |
| 16 | ApiNotFoundResponse, |
| 17 | ApiOkResponse, |
| 18 | ApiOperation, |
| 19 | ApiTags, |
| 20 | } from '@nestjs/swagger'; |
| 21 | import type { UserSession |
| 22 | |
| 23 | import { ErrorResponseDTO } |
| 24 | import { CollaboratorsService } |
| 25 | import { |
| 26 | ListRepositoryTeamsResponseDTO, |
| 27 | SetTeamRoleRequestDTO, |
| 28 | } from './dto/collaborator.dto.js'; |
| 29 | |
| 30 | @ApiTags('Collaborators') |
| 31 | @Controller('repositories/:username/:repo/teams') |
| 32 | export class TeamsController |
| 33 | constructor(private readonly |
| 34 | |
| 35 | @Get() |
| 36 | @ApiOperation({ |
| 37 | summary: 'List teams and their access', |
| 38 | description: |
| 39 | "Every team in the repository's organization, with its role here or null. Admins only.", |
| 40 | }) |
| 41 | @ApiOkResponse({ type |
| 42 | @ApiBadRequestResponse({ type |
| 43 | @ApiForbiddenResponse({ type |
| 44 | @ApiNotFoundResponse({ type |
| 45 | list( |
| 46 | @Param('username' |
| 47 | @Param('repo' |
| 48 | @Session() session |
| 49 | ): Promise<ListRepositoryTeamsResponseDTO |
| 50 | return this.collaborators |
| 51 | username, |
| 52 | repo, |
| 53 | requesterId: session.user |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | @Put(':teamId' |
| 58 | @HttpCode(HttpStatus. |
| 59 | @ApiOperation({ |
| 60 | summary: 'Give a team a role', |
| 61 | description: |
| 62 | 'Every member of the team gets the role on this repository. Admins only.', |
| 63 | }) |
| 64 | @ApiNoContentResponse() |
| 65 | @ApiBadRequestResponse({ type |
| 66 | @ApiForbiddenResponse({ type |
| 67 | @ApiNotFoundResponse({ type |
| 68 | setRole( |
| 69 | @Param('username' |
| 70 | @Param('repo' |
| 71 | @Param('teamId' |
| 72 | @Body() body |
| 73 | @Session() session |
| 74 | ): Promise<void |
| 75 | return this.collaborators |
| 76 | username, |
| 77 | repo, |
| 78 | requesterId: session.user |
| 79 | teamId, |
| 80 | role: body.role |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | @Delete(':teamId' |
| 85 | @HttpCode(HttpStatus. |
| 86 | @ApiOperation({ summary |
| 87 | @ApiNoContentResponse() |
| 88 | @ApiForbiddenResponse({ type |
| 89 | @ApiNotFoundResponse({ type |
| 90 | remove( |
| 91 | @Param('username' |
| 92 | @Param('repo' |
| 93 | @Param('teamId' |
| 94 | @Session() session |
| 95 | ): Promise<void |
| 96 | return this.collaborators |
| 97 | username, |
| 98 | repo, |
| 99 | requesterId: session.user |
| 100 | teamId, |
| 101 | }); |
| 102 | } |
| 103 | } |