-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcolumn.controller.ts
More file actions
65 lines (60 loc) · 1.89 KB
/
column.controller.ts
File metadata and controls
65 lines (60 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ApiTags, ApiBody, ApiOperation, ApiSecurity } from '@nestjs/swagger';
import { Controller, Put, Param, Body, UseGuards, Post, Delete } from '@nestjs/common';
import { ValidateMongoId } from '@shared/validations/valid-mongo-id.validation';
import { ACCESS_KEY_NAME } from '@impler/shared';
import { JwtAuthGuard } from '@shared/framework/auth.guard';
import { ColumnRequestDto } from './dtos/column-request.dto';
import { ColumnResponseDto } from './dtos/column-response.dto';
import { AddColumn, UpdateColumn, DeleteColumn } from './usecases';
import { UpdateColumnCommand } from './commands/update-column.command';
@Controller('/column')
@ApiTags('Column')
@UseGuards(JwtAuthGuard)
@ApiSecurity(ACCESS_KEY_NAME)
export class ColumnController {
constructor(
private addColumn: AddColumn,
private updateColumn: UpdateColumn,
private deleteColumn: DeleteColumn
) {}
@Post(':templateId')
@ApiOperation({
summary: 'Add column to template',
})
@ApiBody({ type: ColumnRequestDto })
async addColumnToTemplate(
@Param('templateId', ValidateMongoId) _templateId: string,
@Body() body: ColumnRequestDto
): Promise<ColumnResponseDto> {
return this.addColumn.execute(
{
...body,
_templateId,
},
_templateId
);
}
@Put(':columnId')
@ApiOperation({
summary: 'Update column',
})
@ApiBody({ type: ColumnRequestDto })
async updateColumnRoute(
@Param('columnId', ValidateMongoId) _columnId: string,
@Body() body: ColumnRequestDto
): Promise<ColumnResponseDto> {
return this.updateColumn.execute(
UpdateColumnCommand.create({
...body,
}),
_columnId
);
}
@Delete(':columnId')
@ApiOperation({
summary: 'Delete column',
})
async deleteColumnRoute(@Param('columnId', ValidateMongoId) _columnId: string): Promise<ColumnResponseDto> {
return this.deleteColumn.execute(_columnId);
}
}