94 lines
3.0 KiB
TypeScript
94 lines
3.0 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 { 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);
|
|
}
|
|
|
|
@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);
|
|
}
|
|
}
|