-
Notifications
You must be signed in to change notification settings - Fork 0
adding in rules endpoint to api #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8c82c98
f7add07
af9a1ba
1471efe
86b7dae
b27c4ac
b333e70
7e4878a
9d68dd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "node", | ||
| "request": "launch", | ||
| "name": "Debug NestJS (start:debug)", | ||
| "runtimeExecutable": "pnpm", | ||
| "runtimeArgs": ["run", "start:debug"], | ||
| "cwd": "${workspaceFolder}", | ||
| "console": "integratedTerminal", | ||
| "sourceMaps": true, | ||
| "autoAttachChildProcesses": true, | ||
| "envFile": "${workspaceFolder}/.env", | ||
| "skipFiles": ["<node_internals>/**"] | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { Database } from '../../../database.types'; | ||
|
|
||
| type RuleInsert = Database['public']['Tables']['cw_rules']['Insert']; | ||
|
|
||
| export class CreateRuleDto implements RuleInsert { | ||
| @ApiProperty() | ||
| action_recipient: string; | ||
|
|
||
| @ApiProperty() | ||
| name: string; | ||
|
|
||
| @ApiProperty() | ||
| notifier_type: number; | ||
|
|
||
| @ApiProperty() | ||
| ruleGroupId: string; | ||
|
|
||
| @ApiProperty({ required: false }) | ||
| created_at?: string; | ||
|
|
||
| @ApiProperty({ required: false, nullable: true }) | ||
| dev_eui?: string | null; | ||
|
|
||
| @ApiProperty({ required: false }) | ||
| id?: number; | ||
|
|
||
| @ApiProperty({ required: false }) | ||
| is_triggered?: boolean; | ||
|
|
||
| @ApiProperty({ required: false, nullable: true }) | ||
| last_triggered?: string | null; | ||
|
|
||
| @ApiProperty({ required: false }) | ||
| profile_id?: string; | ||
|
|
||
| @ApiProperty({ required: false, nullable: true }) | ||
| send_using?: string | null; | ||
|
|
||
| @ApiProperty({ required: false }) | ||
| trigger_count?: number; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { Database } from '../../../database.types'; | ||
|
|
||
| type RuleRow = Database['public']['Tables']['cw_rules']['Row']; | ||
|
|
||
| export class RuleDto implements RuleRow { | ||
| @ApiProperty() | ||
| id: number; | ||
|
|
||
| @ApiProperty() | ||
| name: string; | ||
|
|
||
| @ApiProperty() | ||
| action_recipient: string; | ||
|
|
||
| @ApiProperty() | ||
| notifier_type: number; | ||
|
|
||
| @ApiProperty() | ||
| ruleGroupId: string; | ||
|
|
||
| @ApiProperty() | ||
| profile_id: string; | ||
|
|
||
| @ApiProperty({ nullable: true, required: false }) | ||
| dev_eui: string | null; | ||
|
|
||
| @ApiProperty({ nullable: true, required: false }) | ||
| send_using: string | null; | ||
|
|
||
| @ApiProperty() | ||
| is_triggered: boolean; | ||
|
|
||
| @ApiProperty() | ||
| trigger_count: number; | ||
|
|
||
| @ApiProperty({ format: 'date-time' }) | ||
| created_at: string; | ||
|
|
||
| @ApiProperty({ nullable: true, required: false, format: 'date-time' }) | ||
| last_triggered: string | null; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { PartialType } from '@nestjs/swagger'; | ||
| import { Database } from '../../../database.types'; | ||
| import { CreateRuleDto } from './create-rule.dto'; | ||
|
|
||
| type RuleUpdate = Database['public']['Tables']['cw_rules']['Update']; | ||
|
|
||
| export class UpdateRuleDto | ||
| extends PartialType(CreateRuleDto) | ||
| implements RuleUpdate {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export class Rule {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { RulesController } from './rules.controller'; | ||
| import { RulesService } from './rules.service'; | ||
|
|
||
| describe('RulesController', () => { | ||
| let controller: RulesController; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [RulesController], | ||
| providers: [ | ||
| { | ||
| provide: RulesService, | ||
| useValue: {}, | ||
| }, | ||
| ], | ||
| }).compile(); | ||
|
|
||
| controller = module.get<RulesController>(RulesController); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(controller).toBeDefined(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||
| import { Controller, Get, Post, Body, Patch, Param, Delete, Req, UseGuards } from '@nestjs/common'; | ||||||
| import { RulesService } from './rules.service'; | ||||||
| import { CreateRuleDto } from './dto/create-rule.dto'; | ||||||
| import { UpdateRuleDto } from './dto/update-rule.dto'; | ||||||
| import { ApiBearerAuth, ApiOkResponse, ApiSecurity } from '@nestjs/swagger'; | ||||||
| import { JwtAuthGuard } from '../auth/guards/jwt.auth.guard'; | ||||||
| import { RuleDto } from './dto/rule.dto'; | ||||||
|
|
||||||
| @ApiBearerAuth('bearerAuth') | ||||||
| @ApiSecurity('apiKey') | ||||||
| @Controller('rules') | ||||||
| export class RulesController { | ||||||
| constructor(private readonly rulesService: RulesService) { } | ||||||
|
|
||||||
| @UseGuards(JwtAuthGuard) | ||||||
| @ApiOkResponse({ | ||||||
| description: | ||||||
| "Create a new rule configuration. Only the fields included in the request body will be used.", | ||||||
| type: RuleDto, | ||||||
| isArray: false, | ||||||
| }) | ||||||
| @Post() | ||||||
| create(@Body() createRuleDto: CreateRuleDto, @Req() req) { | ||||||
| const authHeader = req.headers?.authorization; | ||||||
| if (!authHeader) { | ||||||
| throw new Error('Authorization header is required'); | ||||||
|
||||||
| } | ||||||
| return this.rulesService.create(createRuleDto, req.user, authHeader); | ||||||
| } | ||||||
|
|
||||||
| @UseGuards(JwtAuthGuard) | ||||||
| @ApiOkResponse({ | ||||||
| description: | ||||||
| "Current all of the user's rules configurations.", | ||||||
|
||||||
| "Current all of the user's rules configurations.", | |
| "Returns all of the user's rules configurations.", |
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing API error response decorators. Following the pattern established in other controllers, this endpoint should include @ApiUnauthorizedResponse and @ApiInternalServerErrorResponse decorators.
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing API error response decorators. Following the pattern established in other controllers, this endpoint should include @ApiUnauthorizedResponse, @ApiBadRequestResponse (since dev_eui validation can fail), and @ApiInternalServerErrorResponse decorators.
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing API error response decorators. Following the pattern established in other controllers, this endpoint should include @ApiUnauthorizedResponse and @ApiInternalServerErrorResponse decorators.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { RulesService } from './rules.service'; | ||
| import { RulesController } from './rules.controller'; | ||
| import { SupabaseModule } from '../supabase/supabase.module'; | ||
|
|
||
| @Module({ | ||
| imports: [SupabaseModule], | ||
| controllers: [RulesController], | ||
| providers: [RulesService], | ||
| }) | ||
| export class RulesModule { } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Test, TestingModule } from '@nestjs/testing'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { RulesService } from './rules.service'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('RulesService', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let service: RulesService; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| beforeEach(async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const module: TestingModule = await Test.createTestingModule({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| providers: [RulesService], | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+9
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('RulesService', () => { | |
| let service: RulesService; | |
| beforeEach(async () => { | |
| const module: TestingModule = await Test.createTestingModule({ | |
| providers: [RulesService], | |
| import { SupabaseService } from '../../supabase/supabase.service'; | |
| describe('RulesService', () => { | |
| let service: RulesService; | |
| beforeEach(async () => { | |
| const module: TestingModule = await Test.createTestingModule({ | |
| providers: [ | |
| RulesService, | |
| { | |
| provide: SupabaseService, | |
| useValue: { | |
| getClient: jest.fn(), | |
| getAdminClient: jest.fn(), | |
| }, | |
| }, | |
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API documentation is missing several standard error response decorators that are consistently used throughout the codebase for protected endpoints. Based on the pattern in other controllers (devices, auth, air, etc.), this endpoint should include: @ApiUnauthorizedResponse, @ApiBadRequestResponse, and @ApiInternalServerErrorResponse decorators with appropriate error examples matching the ErrorResponseDto type.