| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Get, |
| 5 | Param, |
| 6 | ParseIntPipe, |
| 7 | Put, |
| 8 | Session, |
| 9 | } from '@nestjs/common'; |
| 10 | import { |
| 11 | ApiNotFoundResponse, |
| 12 | ApiOkResponse, |
| 13 | ApiOperation, |
| 14 | ApiTags, |
| 15 | } from '@nestjs/swagger'; |
| 16 | import type { UserSession |
| 17 | |
| 18 | import { ErrorResponseDTO } |
| 19 | import { |
| 20 | IssueSubscriptionDTO, |
| 21 | RepositoryWatchDTO, |
| 22 | } from './dto/notification.dto.js'; |
| 23 | import { NotificationsService } |
| 24 | |
| 25 | @Controller('repositories/:username/:repo') |
| 26 | @ApiTags('Notifications') |
| 27 | export class SubscriptionsController |
| 28 | constructor(private readonly |
| 29 | |
| 30 | @Get('subscription' |
| 31 | @ApiOperation({ summary |
| 32 | @ApiOkResponse({ type |
| 33 | @ApiNotFoundResponse({ type |
| 34 | getWatch( |
| 35 | @Param('username' |
| 36 | @Param('repo' |
| 37 | @Session() session |
| 38 | ): Promise<RepositoryWatchDTO |
| 39 | return this.notifications |
| 40 | username, |
| 41 | repo, |
| 42 | requesterId: session.user |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | @Put('subscription' |
| 47 | @ApiOperation({ summary |
| 48 | @ApiOkResponse({ type |
| 49 | @ApiNotFoundResponse({ type |
| 50 | setWatch( |
| 51 | @Param('username' |
| 52 | @Param('repo' |
| 53 | @Body() body |
| 54 | @Session() session |
| 55 | ): Promise<RepositoryWatchDTO |
| 56 | return this.notifications |
| 57 | username, |
| 58 | repo, |
| 59 | requesterId: session.user |
| 60 | level: body.level |
| 61 | }); |
| 62 | } |
| 63 | |
| 64 | @Get('issues/:number/subscription' |
| 65 | @ApiOperation({ |
| 66 | summary: |
| 67 | 'Read whether the viewer is subscribed to an issue or pull request', |
| 68 | }) |
| 69 | @ApiOkResponse({ type |
| 70 | @ApiNotFoundResponse({ type |
| 71 | getSubscription( |
| 72 | @Param('username' |
| 73 | @Param('repo' |
| 74 | @Param('number' |
| 75 | @Session() session |
| 76 | ): Promise<IssueSubscriptionDTO |
| 77 | return this.notifications |
| 78 | username, |
| 79 | repo, |
| 80 | number, |
| 81 | requesterId: session.user |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | @Put('issues/:number/subscription' |
| 86 | @ApiOperation({ |
| 87 | summary: 'Subscribe to or unsubscribe from an issue or pull request', |
| 88 | description: |
| 89 | 'Unsubscribing outlasts the automatic subscription that commenting adds. Mentions and assignments still notify.', |
| 90 | }) |
| 91 | @ApiOkResponse({ type |
| 92 | @ApiNotFoundResponse({ type |
| 93 | setSubscription( |
| 94 | @Param('username' |
| 95 | @Param('repo' |
| 96 | @Param('number' |
| 97 | @Body() body |
| 98 | @Session() session |
| 99 | ): Promise<IssueSubscriptionDTO |
| 100 | return this.notifications |
| 101 | username, |
| 102 | repo, |
| 103 | number, |
| 104 | requesterId: session.user |
| 105 | subscribed: body.subscribed |
| 106 | }); |
| 107 | } |
| 108 | } |