97 lines
2.9 KiB
TypeScript
97 lines
2.9 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { ChecklistsService } from './checklists.service';
|
|
import { CreateChecklistDto, CreateChecklistItemDto } from './dto/create-checklist.dto';
|
|
import { UpdateChecklistDto } from './dto/update-checklist.dto';
|
|
import { UpdateChecklistItemDto } from './dto/update-checklist-item.dto';
|
|
import { Checklist } from './entities/checklist.entity';
|
|
import { ChecklistItem } from './entities/checklist-item.entity';
|
|
|
|
@ApiTags('Checklists')
|
|
@Controller('checklists')
|
|
export class ChecklistsController {
|
|
constructor(private readonly checklistsService: ChecklistsService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List all checklists with optional filters' })
|
|
findAll(
|
|
@Query('domainId') domainId?: string,
|
|
@Query('status') status?: string,
|
|
): Promise<Checklist[]> {
|
|
return this.checklistsService.findAll({ domainId, status });
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create a checklist' })
|
|
create(@Body() dto: CreateChecklistDto): Promise<Checklist> {
|
|
return this.checklistsService.create(dto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get checklist by ID' })
|
|
findOne(@Param('id') id: string): Promise<Checklist> {
|
|
return this.checklistsService.findOne(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update checklist' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateChecklistDto): Promise<Checklist> {
|
|
return this.checklistsService.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
@ApiOperation({ summary: 'Soft delete checklist' })
|
|
remove(@Param('id') id: string): Promise<void> {
|
|
return this.checklistsService.remove(id);
|
|
}
|
|
|
|
@Post(':id/items')
|
|
@ApiOperation({ summary: 'Add item to checklist' })
|
|
addItem(
|
|
@Param('id') checklistId: string,
|
|
@Body() dto: CreateChecklistItemDto,
|
|
): Promise<ChecklistItem> {
|
|
return this.checklistsService.addItem(checklistId, dto);
|
|
}
|
|
|
|
@Patch(':id/items/:itemId')
|
|
@ApiOperation({ summary: 'Update checklist item' })
|
|
updateItem(
|
|
@Param('id') checklistId: string,
|
|
@Param('itemId') itemId: string,
|
|
@Body() dto: UpdateChecklistItemDto,
|
|
): Promise<ChecklistItem> {
|
|
return this.checklistsService.updateItem(checklistId, itemId, dto);
|
|
}
|
|
|
|
@Delete(':id/items/:itemId')
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
@ApiOperation({ summary: 'Remove checklist item' })
|
|
removeItem(
|
|
@Param('id') checklistId: string,
|
|
@Param('itemId') itemId: string,
|
|
): Promise<void> {
|
|
return this.checklistsService.removeItem(checklistId, itemId);
|
|
}
|
|
|
|
@Post(':id/items/:itemId/toggle')
|
|
@ApiOperation({ summary: 'Toggle checklist item checked state' })
|
|
toggleItem(
|
|
@Param('id') checklistId: string,
|
|
@Param('itemId') itemId: string,
|
|
): Promise<ChecklistItem> {
|
|
return this.checklistsService.toggleItem(checklistId, itemId);
|
|
}
|
|
}
|