File size: 1,588 Bytes
86063f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Body, Controller, Get, Patch, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { IsIn } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import type { Request } from 'express';
import { CampaignsService } from './campaigns.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

export class SetAvailabilityDto {
  @ApiProperty({ enum: ['looking', 'suspended'] })
  @IsIn(['looking', 'suspended'])
  availability!: 'looking' | 'suspended';
}

/**
 * The candidate's own job-seeking status.
 *
 * Deliberately NOT under /admin. A suspension exists to ask one question - "are
 * you still looking?" - and only the person can answer it. An operator who could
 * clear it for them would be answering on their behalf, which is how you end up
 * putting a no-show in front of a fourth company.
 */
@ApiTags('Availability')
@ApiBearerAuth()
@Controller('me/availability')
@UseGuards(JwtAuthGuard)
export class AvailabilityController {
  constructor(private readonly campaigns: CampaignsService) {}

  @Get()
  @ApiOperation({ summary: 'My job-seeking status, and the history behind it' })
  async get(@Req() req: Request) {
    const user = req.user as { id: string };
    return this.campaigns.availabilityFor(user.id);
  }

  @Patch()
  @ApiOperation({ summary: 'Set my job-seeking status' })
  async set(@Req() req: Request, @Body() dto: SetAvailabilityDto) {
    const user = req.user as { id: string };
    return this.campaigns.setAvailability(user.id, dto.availability);
  }
}