82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { Controller, Get, Post, Patch, Param, Body, UseGuards, Req, HttpCode, HttpStatus, NotFoundException } from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { ProfessionalsService } from './professionals.service';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { CreateProfessionalDto, UpdateProfessionalDto, UpdateSchedulesDto } from './dto/professional.dto';
|
|
import { AuthService } from '../auth/auth.service';
|
|
|
|
@ApiTags('Professionals')
|
|
@Controller('professionals')
|
|
export class ProfessionalsController {
|
|
constructor(
|
|
private pros: ProfessionalsService,
|
|
private auth: AuthService,
|
|
) {}
|
|
|
|
@Get()
|
|
findAllActive(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.pros.findAllActive(page, limit);
|
|
}
|
|
|
|
@Get('pending')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
findPending(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.pros.findPendingApprovals(page, limit);
|
|
}
|
|
|
|
@Post(':id/approve')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
approve(@Param('id') id: string) {
|
|
return this.pros.approve(id);
|
|
}
|
|
|
|
@Post(':id/deny')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
deny(@Param('id') id: string) {
|
|
return this.pros.deny(id);
|
|
}
|
|
|
|
@Get('me')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
async findByMe(@Req() req) {
|
|
const profId = await this.auth.getProfessionalId(req.user.sub);
|
|
if (!profId) throw new NotFoundException('No eres un profesional');
|
|
return this.pros.findByUserId(req.user.sub);
|
|
}
|
|
|
|
@Get(':id')
|
|
findById(@Param('id') id: string) {
|
|
return this.pros.findById(id);
|
|
}
|
|
|
|
@Post('request')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
request(@Req() req, @Body() dto: CreateProfessionalDto) {
|
|
return this.pros.requestProfessional(req.user.sub, dto);
|
|
}
|
|
|
|
@Patch('me')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
async update(@Req() req, @Body() dto: UpdateProfessionalDto) {
|
|
return this.pros.upsert(req.user.sub, dto);
|
|
}
|
|
|
|
@Patch('me/schedules')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
async updateSchedules(@Req() req, @Body() dto: UpdateSchedulesDto) {
|
|
const prof = await this.pros.findByUserId(req.user.sub);
|
|
return this.pros.updateSchedules(prof.id, dto.schedules);
|
|
}
|
|
}
|