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 | 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x | import {
Controller,
Get,
Post,
Body,
Param,
Put,
Delete,
ParseUUIDPipe,
HttpCode,
HttpStatus,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiParam,
ApiBody,
} from '@nestjs/swagger';
import { CustomVariablesService } from './custom-variables.service';
import {
CreateCustomVariableDto,
UpdateCustomVariableDto,
} from './dto/custom-variable.dto';
import { CustomVariable } from '../core-entities';
/**
* Custom variables are key-value pairs available in context templates.
*
* Access via it.variables.KEY in Eta templates.
* Use for frequently-changing values like author names, API endpoints, etc.
*
* Variables can be enabled/disabled and reordered by usage frequency.
*
* Example: A variable with key 'author' can be used as: <%= it.variables.author %>
*/
@ApiTags('custom-variables')
@Controller('custom-variables')
export class CustomVariablesController {
constructor(
private readonly customVariablesService: CustomVariablesService,
) {}
@Post()
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Create a custom variable' })
@ApiResponse({
status: 201,
description: 'Variable created',
type: CustomVariable,
})
async create(
@Body() createCustomVariableDto: CreateCustomVariableDto,
): Promise<CustomVariable> {
return this.customVariablesService.create(createCustomVariableDto);
}
@Get()
@ApiOperation({ summary: 'List all custom variables' })
@ApiResponse({
status: 200,
description: 'List of variables',
type: [CustomVariable],
})
async findAll(): Promise<CustomVariable[]> {
return this.customVariablesService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get a custom variable by ID' })
@ApiParam({ name: 'id', description: 'Variable UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'Variable found',
type: CustomVariable,
})
@ApiResponse({ status: 404, description: 'Variable not found' })
async findOne(
@Param('id', ParseUUIDPipe) id: string,
): Promise<CustomVariable> {
return this.customVariablesService.findOne(id);
}
@Put(':id')
@ApiOperation({ summary: 'Update a custom variable' })
@ApiParam({ name: 'id', description: 'Variable UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'Variable updated',
type: CustomVariable,
})
@ApiResponse({ status: 404, description: 'Variable not found' })
async update(
@Param('id', ParseUUIDPipe) id: string,
@Body() updateCustomVariableDto: UpdateCustomVariableDto,
): Promise<CustomVariable> {
return this.customVariablesService.update(id, updateCustomVariableDto);
}
@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
@ApiOperation({ summary: 'Delete a custom variable' })
@ApiParam({ name: 'id', description: 'Variable UUID', format: 'uuid' })
@ApiResponse({ status: 204, description: 'Variable deleted' })
@ApiResponse({ status: 404, description: 'Variable not found' })
async remove(@Param('id', ParseUUIDPipe) id: string): Promise<void> {
return this.customVariablesService.remove(id);
}
@Post('reorder')
@HttpCode(HttpStatus.NO_CONTENT)
@ApiOperation({
summary: 'Reorder variables',
description:
'Update the display order of variables. Pass an array of variable IDs in the desired order.',
})
@ApiBody({
description: 'Array of variable IDs in desired order',
type: [String],
examples: { default: { value: ['uuid-1', 'uuid-2', 'uuid-3'] } },
})
@ApiResponse({ status: 204, description: 'Variables reordered' })
async reorder(@Body() orderedIds: string[]): Promise<void> {
return this.customVariablesService.reorder(orderedIds);
}
}
|