Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x | import {
Controller,
Get,
Post,
Body,
Put,
Param,
Delete,
HttpCode,
Query,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiParam,
ApiQuery,
ApiBody,
} from '@nestjs/swagger';
import { ToolHooksService } from './tool-hooks.service';
import { CreateToolHookDto } from './dto/create-tool-hook.dto';
import { UpdateToolHookDto } from './dto/update-tool-hook.dto';
@ApiTags('tool-hooks')
@Controller('tool-hooks')
export class ToolHooksController {
constructor(private readonly toolHooksService: ToolHooksService) {}
@Get()
@ApiOperation({ summary: 'List all tool hooks' })
@ApiResponse({ status: 200, description: 'List of tool hooks' })
findAll() {
return this.toolHooksService.findAll();
}
@Get('scripts')
@ApiOperation({ summary: 'List available hook scripts' })
@ApiResponse({ status: 200, description: 'List of script filenames' })
listScripts() {
return this.toolHooksService.listScripts();
}
@Get('template/:toolName')
@ApiOperation({ summary: 'Get template for a new hook script' })
@ApiParam({ name: 'toolName', description: 'Name of the tool' })
@ApiResponse({
status: 200,
description: 'Template content',
schema: { properties: { content: { type: 'string' } } },
})
getTemplate(@Param('toolName') toolName: string) {
return { content: this.toolHooksService.generateTemplate(toolName) };
}
@Get('sample-payload')
@ApiOperation({ summary: 'Get sample payload for testing' })
@ApiQuery({ name: 'toolName', description: 'Name of the tool' })
@ApiQuery({
name: 'timing',
description: 'Hook timing',
enum: ['before', 'after'],
})
@ApiResponse({ status: 200, description: 'Sample payload object' })
getSamplePayload(
@Query('toolName') toolName: string,
@Query('timing') timing: 'before' | 'after',
) {
return this.toolHooksService.generateSamplePayload(toolName, timing);
}
@Post('test')
@HttpCode(200)
@ApiOperation({ summary: 'Test a hook script with payload' })
@ApiBody({
schema: {
properties: {
script_filename: { type: 'string' },
payload: { type: 'object' },
},
},
})
@ApiResponse({ status: 200, description: 'Test result' })
testHook(@Body() body: { script_filename: string; payload: any }) {
return this.toolHooksService.testHook(body.script_filename, body.payload);
}
@Post('scripts')
@HttpCode(204)
@ApiOperation({ summary: 'Create a new hook script file' })
@ApiBody({
schema: {
properties: {
filename: { type: 'string', example: 'my-hook.ts' },
content: { type: 'string', description: 'Script content' },
},
},
})
@ApiResponse({ status: 204, description: 'Script created' })
createScript(@Body() body: { filename: string; content: string }) {
return this.toolHooksService.createScript(body.filename, body.content);
}
@Post()
@HttpCode(201)
@ApiOperation({ summary: 'Create a tool hook configuration' })
@ApiResponse({ status: 201, description: 'Tool hook created' })
create(@Body() createToolHookDto: CreateToolHookDto) {
return this.toolHooksService.create(createToolHookDto);
}
@Put(':id')
@ApiOperation({ summary: 'Update a tool hook' })
@ApiParam({ name: 'id', description: 'Tool hook UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Tool hook updated' })
@ApiResponse({ status: 404, description: 'Tool hook not found' })
update(
@Param('id') id: string,
@Body() updateToolHookDto: UpdateToolHookDto,
) {
return this.toolHooksService.update(id, updateToolHookDto);
}
@Delete(':id')
@HttpCode(204)
@ApiOperation({ summary: 'Delete a tool hook' })
@ApiParam({ name: 'id', description: 'Tool hook UUID', format: 'uuid' })
@ApiResponse({ status: 204, description: 'Tool hook deleted' })
@ApiResponse({ status: 404, description: 'Tool hook not found' })
remove(@Param('id') id: string) {
return this.toolHooksService.remove(id);
}
}
|