111 lines
3.4 KiB
TypeScript
111 lines
3.4 KiB
TypeScript
import { Controller, Get, Post, Patch, Param, Body, UseGuards, Req, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
|
|
import { ServicesService } from './services.service';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { CreateServiceDto, UpdateServiceStatusDto } from './dto/service.dto';
|
|
|
|
@ApiTags('Services')
|
|
@Controller('services')
|
|
export class ServicesController {
|
|
constructor(private services: ServicesService) {}
|
|
|
|
@Post()
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
create(@Req() req, @Body() dto: CreateServiceDto) {
|
|
return this.services.create({ ...dto, user_id: req.user.sub });
|
|
}
|
|
|
|
@Get()
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiQuery({ name: 'page', required: false })
|
|
@ApiQuery({ name: 'limit', required: false })
|
|
findAll(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.services.findAll(page, limit);
|
|
}
|
|
|
|
@Get('me')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiQuery({ name: 'page', required: false })
|
|
@ApiQuery({ name: 'limit', required: false })
|
|
findByMe(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.services.findByUser(req.user.sub, page, limit);
|
|
}
|
|
|
|
@Get('professional')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiQuery({ name: 'page', required: false })
|
|
@ApiQuery({ name: 'limit', required: false })
|
|
findByProfessional(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.services.findByProfessional(req.user.sub, page, limit);
|
|
}
|
|
|
|
@Get('professional/requests')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiQuery({ name: 'page', required: false })
|
|
@ApiQuery({ name: 'limit', required: false })
|
|
requestsByProfessional(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.services.findRequestsByProfessional(req.user.sub, page, limit);
|
|
}
|
|
|
|
@Get('professional/history')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiQuery({ name: 'page', required: false })
|
|
@ApiQuery({ name: 'limit', required: false })
|
|
historyByProfessional(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.services.getHistoryByProfessional(req.user.sub, page, limit);
|
|
}
|
|
|
|
@Get('me/history')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiQuery({ name: 'page', required: false })
|
|
@ApiQuery({ name: 'limit', required: false })
|
|
historyByUser(@Req() req) {
|
|
const page = +(req.query.page || 1);
|
|
const limit = +(req.query.limit || 20);
|
|
return this.services.getHistoryByUser(req.user.sub, page, limit);
|
|
}
|
|
|
|
@Get('professional/calendar')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
calendarByProfessional(@Req() req) {
|
|
return this.services.getCalendarByProfessional(req.user.sub);
|
|
}
|
|
|
|
@Get('public-calendar/:professionalId')
|
|
getPublicCalendar(@Param('professionalId') id: string) {
|
|
return this.services.getPublicCalendar(id);
|
|
}
|
|
|
|
@Get(':id')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
findById(@Param('id') id: string) {
|
|
return this.services.findById(id);
|
|
}
|
|
|
|
@Patch(':id/status')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
updateStatus(@Req() req, @Param('id') id: string, @Body() dto: UpdateServiceStatusDto) {
|
|
return this.services.updateStatus(id, dto.status, req.user.sub);
|
|
}
|
|
}
|