src/module/sheet/sheet.controller.ts
sheet
Methods |
|
Async createSheet | ||||||
createSheet(dto: SheetDTO)
|
||||||
Decorators :
@Post()
|
||||||
Defined in src/module/sheet/sheet.controller.ts:39
|
||||||
Parameters :
Returns :
Promise<ISheet>
|
Async deleteSheet | ||||||
deleteSheet(id: string)
|
||||||
Decorators :
@Delete('/:id')
|
||||||
Defined in src/module/sheet/sheet.controller.ts:67
|
||||||
Parameters :
Returns :
Promise<void>
|
Async getAllSheets |
getAllSheets()
|
Decorators :
@Get()
|
Defined in src/module/sheet/sheet.controller.ts:29
|
Returns :
Promise<ISheet[]>
|
Async getSheet | ||||||
getSheet(id: string)
|
||||||
Decorators :
@Get('/:id')
|
||||||
Defined in src/module/sheet/sheet.controller.ts:47
|
||||||
Parameters :
Returns :
Promise<ISheet>
|
Async updateSheet |
updateSheet(id: string, dto: SheetDTO)
|
Decorators :
@Patch('/:id')
|
Defined in src/module/sheet/sheet.controller.ts:57
|
Returns :
Promise<ISheet>
|
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Patch,
Post,
UseGuards,
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import { AuthenticatedGuard } from '../../guards/authenticated.guard';
import { Roles } from '../../guards/decorators/roles.decorator';
import { HasRoleGuard } from '../../guards/has-role.guard';
import { Role } from '../../shared/model/Role';
import { ISheet } from '../../shared/model/Sheet';
import { SheetDTO } from './sheet.dto';
import { SheetService } from './sheet.service';
@Controller('sheet')
export class SheetController {
constructor(private readonly sheetService: SheetService) {}
@Get()
@UseGuards(AuthenticatedGuard)
async getAllSheets(): Promise<ISheet[]> {
const sheets = await this.sheetService.findAll();
return sheets.map((sheet) => sheet.toDTO());
}
@Post()
@UseGuards(HasRoleGuard)
@Roles(Role.ADMIN, Role.EMPLOYEE)
@UsePipes(ValidationPipe)
async createSheet(@Body() dto: SheetDTO): Promise<ISheet> {
const sheet = await this.sheetService.create(dto);
return sheet;
}
@Get('/:id')
@UseGuards(AuthenticatedGuard)
async getSheet(@Param('id') id: string): Promise<ISheet> {
const sheet = await this.sheetService.findById(id);
return sheet.toDTO();
}
@Patch('/:id')
@UseGuards(HasRoleGuard)
@Roles(Role.ADMIN, Role.EMPLOYEE)
@UsePipes(ValidationPipe)
async updateSheet(@Param('id') id: string, @Body() dto: SheetDTO): Promise<ISheet> {
const sheet = await this.sheetService.update(id, dto);
return sheet;
}
@Delete('/:id')
@HttpCode(HttpStatus.NO_CONTENT)
@UseGuards(HasRoleGuard)
@Roles(Role.ADMIN, Role.EMPLOYEE)
async deleteSheet(@Param('id') id: string): Promise<void> {
await this.sheetService.delete(id);
}
}