adding in rules endpoint to api#10
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This pull request adds a new rules management endpoint to the API, allowing users to create, read, update, and delete rule configurations associated with devices and locations. The implementation includes permission checking to ensure users can only manage rules for devices and locations they have access to. Additionally, it modifies the SupabaseService to support per-request authentication tokens and adds Swagger UI persistence for authorization.
Changes:
- Added complete CRUD endpoints for rules management with JWT authentication and permission validation
- Enhanced SupabaseService to support creating authenticated Supabase clients with user access tokens
- Added Swagger UI authorization persistence for improved developer experience
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 22 comments.
Show a summary per file
| File | Description |
|---|---|
| src/rules/rules.controller.ts | New controller implementing CRUD endpoints for rules with JWT authentication guards |
| src/rules/rules.service.ts | Service layer implementing business logic, permission checks, and database operations for rules |
| src/rules/rules.module.ts | Module configuration importing SupabaseModule and declaring controller and service |
| src/rules/dto/create-rule.dto.ts | DTO defining the structure for creating new rules |
| src/rules/dto/update-rule.dto.ts | DTO extending CreateRuleDto for partial updates |
| src/rules/dto/rule.dto.ts | DTO defining the complete rule structure for API responses |
| src/rules/entities/rule.entity.ts | Empty entity class placeholder |
| src/rules/rules.controller.spec.ts | Basic test setup for the rules controller |
| src/rules/rules.service.spec.ts | Basic test setup for the rules service |
| src/supabase/supabase.service.ts | Enhanced to accept optional access tokens and create authenticated clients dynamically |
| src/app.module.ts | Added RulesModule to the application imports |
| src/main.ts | Added Swagger UI option to persist authorization tokens |
| .vscode/launch.json | Added VS Code debug configuration for NestJS |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| create(@Body() createRuleDto: CreateRuleDto, @Req() req) { | ||
| const authHeader = req.headers?.authorization; | ||
| if (!authHeader) { | ||
| throw new Error('Authorization header is required'); |
There was a problem hiding this comment.
Using generic 'throw new Error' is inconsistent with error handling in the rest of the controller layer. All other controllers in the codebase use NestJS exception classes (BadRequestException, UnauthorizedException, etc.). Since the JwtAuthGuard should already handle authentication, this check may be redundant. However, if it's necessary, it should throw 'new UnauthorizedException('Authorization header is required')' to match the error handling pattern used elsewhere.
| @UseGuards(JwtAuthGuard) | ||
| @ApiOkResponse({ | ||
| description: | ||
| "Gets a user's rule configuration by ID.", | ||
| type: RuleDto, | ||
| isArray: false, | ||
| }) |
There was a problem hiding this comment.
Missing API error response decorators. Following the pattern established in other controllers, this endpoint should include @ApiUnauthorizedResponse, @ApiInternalServerErrorResponse, and @ApiNotFoundResponse decorators (since the service can throw NotFoundException).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.