| 1 | import { |
| 2 | Controller, |
| 3 | Delete, |
| 4 | Get, |
| 5 | HttpCode, |
| 6 | HttpStatus, |
| 7 | Param, |
| 8 | Put, |
| 9 | Session, |
| 10 | } from '@nestjs/common'; |
| 11 | import { |
| 12 | ApiBadRequestResponse, |
| 13 | ApiForbiddenResponse, |
| 14 | ApiNoContentResponse, |
| 15 | ApiNotFoundResponse, |
| 16 | ApiOkResponse, |
| 17 | ApiOperation, |
| 18 | ApiTags, |
| 19 | } from '@nestjs/swagger'; |
| 20 | import type { UserSession |
| 21 | |
| 22 | import { ErrorResponseDTO } |
| 23 | import { |
| 24 | ListOrganizationTeamsResponseDTO, |
| 25 | OrganizationTeamDTO, |
| 26 | } from './dto/organization.dto.js'; |
| 27 | import { TeamsService } |
| 28 | |
| 29 | @ApiTags('Organizations') |
| 30 | @Controller('organizations/:slug/teams') |
| 31 | export class OrganizationTeamsController |
| 32 | constructor(private readonly |
| 33 | |
| 34 | @Get() |
| 35 | @ApiOperation({ summary |
| 36 | @ApiOkResponse({ type |
| 37 | @ApiNotFoundResponse({ type |
| 38 | list( |
| 39 | @Param('slug' |
| 40 | @Session() session |
| 41 | ): Promise<ListOrganizationTeamsResponseDTO |
| 42 | return this.teams |
| 43 | } |
| 44 | |
| 45 | @Get(':team' |
| 46 | @ApiOperation({ |
| 47 | summary: 'Read a team', |
| 48 | description: |
| 49 | 'Its members, its maintainers and the repositories it reaches. Members only.', |
| 50 | }) |
| 51 | @ApiOkResponse({ type |
| 52 | @ApiNotFoundResponse({ type |
| 53 | get( |
| 54 | @Param('slug' |
| 55 | @Param('team' |
| 56 | @Session() session |
| 57 | ): Promise<OrganizationTeamDTO |
| 58 | return this.teams |
| 59 | } |
| 60 | |
| 61 | @Put(':team/members/:username' |
| 62 | @HttpCode(HttpStatus. |
| 63 | @ApiOperation({ |
| 64 | summary: 'Add a member to a team', |
| 65 | description: |
| 66 | 'Takes a member of the organization. Admins and the team maintainers only.', |
| 67 | }) |
| 68 | @ApiNoContentResponse() |
| 69 | @ApiBadRequestResponse({ type |
| 70 | @ApiForbiddenResponse({ type |
| 71 | @ApiNotFoundResponse({ type |
| 72 | addMember( |
| 73 | @Param('slug' |
| 74 | @Param('team' |
| 75 | @Param('username' |
| 76 | @Session() session |
| 77 | ): Promise<void |
| 78 | return this.teams |
| 79 | } |
| 80 | |
| 81 | @Delete(':team/members/:username' |
| 82 | @HttpCode(HttpStatus. |
| 83 | @ApiOperation({ |
| 84 | summary: 'Remove a member from a team', |
| 85 | description: 'Admins and the team maintainers only.', |
| 86 | }) |
| 87 | @ApiNoContentResponse() |
| 88 | @ApiForbiddenResponse({ type |
| 89 | @ApiNotFoundResponse({ type |
| 90 | removeMember( |
| 91 | @Param('slug' |
| 92 | @Param('team' |
| 93 | @Param('username' |
| 94 | @Session() session |
| 95 | ): Promise<void |
| 96 | return this.teams |
| 97 | } |
| 98 | |
| 99 | @Put(':team/maintainers/:username' |
| 100 | @HttpCode(HttpStatus. |
| 101 | @ApiOperation({ |
| 102 | summary: 'Make a team member a maintainer', |
| 103 | description: "A maintainer manages the team's members. Admins only.", |
| 104 | }) |
| 105 | @ApiNoContentResponse() |
| 106 | @ApiBadRequestResponse({ type |
| 107 | @ApiForbiddenResponse({ type |
| 108 | @ApiNotFoundResponse({ type |
| 109 | appoint( |
| 110 | @Param('slug' |
| 111 | @Param('team' |
| 112 | @Param('username' |
| 113 | @Session() session |
| 114 | ): Promise<void |
| 115 | return this.teams |
| 116 | slug, |
| 117 | team, |
| 118 | username, |
| 119 | session.user.id |
| 120 | true, |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | @Delete(':team/maintainers/:username' |
| 125 | @HttpCode(HttpStatus. |
| 126 | @ApiOperation({ summary |
| 127 | @ApiNoContentResponse() |
| 128 | @ApiForbiddenResponse({ type |
| 129 | @ApiNotFoundResponse({ type |
| 130 | dismiss( |
| 131 | @Param('slug' |
| 132 | @Param('team' |
| 133 | @Param('username' |
| 134 | @Session() session |
| 135 | ): Promise<void |
| 136 | return this.teams |
| 137 | slug, |
| 138 | team, |
| 139 | username, |
| 140 | session.user.id |
| 141 | false, |
| 142 | ); |
| 143 | } |
| 144 | } |