157 lines
4.7 KiB
TypeScript
157 lines
4.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import { Public } from '../auth/decorators/public.decorator';
|
|
import { Permissions } from '../auth/decorators/permissions.decorator';
|
|
import { Roles } from '../auth/decorators/roles.decorator';
|
|
import { PermissionsGuard } from '../auth/guards/permissions.guard';
|
|
import { RolesGuard } from '../auth/guards/roles.guard';
|
|
import { AuthUser } from '../auth/interfaces/auth-user.interface';
|
|
import { PermissionCode } from '../authorization/enums/permission-code.enum';
|
|
import { UserRole } from '../users/enums/user-role.enum';
|
|
import { CreateStylistDto } from './dto/create-stylist.dto';
|
|
import {
|
|
CreateSalonStylistDto,
|
|
FindSalonStylistsQueryDto,
|
|
UpdateSalonStylistDto,
|
|
} from './dto/salon-stylist.dto';
|
|
import { UpdateStylistDto } from './dto/update-stylist.dto';
|
|
import { StylistsService } from './stylists.service';
|
|
import { ApiPublicEndpoint } from '../swagger/decorators/swagger-auth.decorator';
|
|
import { SWAGGER_JWT_AUTH } from '../swagger/swagger.setup';
|
|
import {
|
|
ApiStandardController,
|
|
ApiStandardEmptyResponse,
|
|
ApiStandardOkResponse,
|
|
} from '../swagger/decorators/swagger-response.decorator';
|
|
import { Stylist } from './entities/stylist.entity';
|
|
|
|
@ApiTags('Stylists')
|
|
@ApiBearerAuth(SWAGGER_JWT_AUTH)
|
|
@ApiStandardController()
|
|
@Controller('stylists')
|
|
@UseGuards(RolesGuard, PermissionsGuard)
|
|
export class StylistsController {
|
|
constructor(private readonly stylistsService: StylistsService) {}
|
|
|
|
@Roles(UserRole.ADMIN, UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_WRITE)
|
|
@ApiStandardOkResponse(Stylist)
|
|
@Post()
|
|
create(
|
|
@Body() createStylistDto: CreateStylistDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.stylistsService.create(createStylistDto, user);
|
|
}
|
|
|
|
@Roles(UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_READ)
|
|
@ApiStandardOkResponse(Stylist, { isArray: true })
|
|
@Get('salon')
|
|
findAllForSalon(
|
|
@CurrentUser() user: AuthUser,
|
|
@Query() query: FindSalonStylistsQueryDto,
|
|
) {
|
|
return this.stylistsService.findAllForSalon(user, query);
|
|
}
|
|
|
|
@Roles(UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_WRITE)
|
|
@ApiStandardOkResponse(Stylist)
|
|
@Post('salon')
|
|
createForSalon(
|
|
@Body() createSalonStylistDto: CreateSalonStylistDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.stylistsService.createForSalon(createSalonStylistDto, user);
|
|
}
|
|
|
|
@Roles(UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_READ)
|
|
@ApiStandardOkResponse(Stylist)
|
|
@Get('salon/:id')
|
|
findOneForSalon(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.stylistsService.findOneForSalon(id, user);
|
|
}
|
|
|
|
@Roles(UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_WRITE)
|
|
@ApiStandardOkResponse(Stylist)
|
|
@Patch('salon/:id')
|
|
updateForSalon(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() updateSalonStylistDto: UpdateSalonStylistDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.stylistsService.updateForSalon(id, updateSalonStylistDto, user);
|
|
}
|
|
|
|
@Roles(UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_DELETE)
|
|
@ApiStandardEmptyResponse()
|
|
@Delete('salon/:id')
|
|
removeForSalon(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.stylistsService.removeForSalon(id, user);
|
|
}
|
|
|
|
@Public()
|
|
@ApiPublicEndpoint('List stylists, optionally filtered by salon')
|
|
@ApiQuery({ name: 'salonId', required: false, type: String, format: 'uuid' })
|
|
@ApiStandardOkResponse(Stylist, { isArray: true })
|
|
@Get()
|
|
findAll(
|
|
@Query('salonId', new ParseUUIDPipe({ optional: true })) salonId?: string,
|
|
) {
|
|
return this.stylistsService.findAll(salonId);
|
|
}
|
|
|
|
@Public()
|
|
@ApiPublicEndpoint('Get stylist by ID')
|
|
@ApiStandardOkResponse(Stylist)
|
|
@Get(':id')
|
|
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.stylistsService.findOne(id);
|
|
}
|
|
|
|
@Roles(UserRole.ADMIN, UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_WRITE)
|
|
@ApiStandardOkResponse(Stylist)
|
|
@Patch(':id')
|
|
update(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() updateStylistDto: UpdateStylistDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.stylistsService.update(id, updateStylistDto, user);
|
|
}
|
|
|
|
@Roles(UserRole.ADMIN, UserRole.SALON)
|
|
@Permissions(PermissionCode.STYLISTS_DELETE)
|
|
@ApiStandardEmptyResponse()
|
|
@Delete(':id')
|
|
remove(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.stylistsService.remove(id, user);
|
|
}
|
|
}
|