Repository: PF-UTN/ManagementPortal-BE
Pull request #23: [MP-25] Add DTO validation & Debug configuration
Author: login: MartinLambrecht
Created: 2025-03-19T00:08:41Z | Merged: 2025-03-20T14:20:15Z



Diff:
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 00000000..aca06b44
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,20 @@
+{
+  "version": "0.2.0",
+  "configurations": [
+    {
+      "type": "node",
+      "request": "launch",
+      "name": "Debug NestJS Application",
+      "runtimeExecutable": "node",
+      "skipFiles": ["<node_internals>/**"],
+      "program": "${workspaceFolder}/dist/main.js", 
+      "preLaunchTask": "tsc: build - tsconfig.json", 
+      "outFiles": ["${workspaceFolder}/dist/**/*.js"],
+      "sourceMaps": true, 
+      "cwd": "${workspaceFolder}",
+      "console": "integratedTerminal",
+      "restart": true, 
+      "smartStep": true
+    }
+  ]
+}
\ No newline at end of file
diff --git a/libs/common/src/dtos/index.ts b/libs/common/src/dtos/index.ts
index f76cf719..fe96de3b 100644
--- a/libs/common/src/dtos/index.ts
+++ b/libs/common/src/dtos/index.ts
@@ -2,7 +2,7 @@ export * from './partially-initializable';
 export * from './registration-request/registration-request.dto';
 export * from './registration-request/registration-request-creation.dto';
 export * from './registration-request/search-registration-request-filters.dto';
-export * from './registration-request/search-registration-request.request';
-export * from './registration-request/search-registration-request.response';
+export * from './registration-request/search-registration-request.request.dto';
+export * from './registration-request/search-registration-request.response.dto';
 export * from './user-creation.dto';
 export * from './user-sign-in.dto';
diff --git a/libs/common/src/dtos/registration-request/index.ts b/libs/common/src/dtos/registration-request/index.ts
index 94e0a6a7..6626c565 100644
--- a/libs/common/src/dtos/registration-request/index.ts
+++ b/libs/common/src/dtos/registration-request/index.ts
@@ -1,5 +1,5 @@
 export * from './registration-request.dto';
 export * from './registration-request-creation.dto';
 export * from './search-registration-request-filters.dto';
-export * from './search-registration-request.request';
-export * from './search-registration-request.response';
+export * from './search-registration-request.request.dto';
+export * from './search-registration-request.response.dto';
diff --git a/libs/common/src/dtos/registration-request/search-registration-request-filters.dto.ts b/libs/common/src/dtos/registration-request/search-registration-request-filters.dto.ts
index 319226b8..89716628 100644
--- a/libs/common/src/dtos/registration-request/search-registration-request-filters.dto.ts
+++ b/libs/common/src/dtos/registration-request/search-registration-request-filters.dto.ts
@@ -1,3 +1,14 @@
+import { RegistrationRequestStatus } from '@mp/common/constants';
+import { ApiProperty } from '@nestjs/swagger';
+import { IsEnum, IsNotEmpty } from 'class-validator';
+
 export class SearchRegistrationRequestFiltersDto {
+  @ApiProperty({
+    example: ['Pending'],
+    description: 'Filter by the status of the registration requests',
+    required: false,
+  })
+  @IsEnum(RegistrationRequestStatus)
+  @IsNotEmpty()
   status?: string[];
 }
diff --git a/libs/common/src/dtos/registration-request/search-registration-request.request.ts b/libs/common/src/dtos/registration-request/search-registration-request.request.dto.ts
similarity index 53%
rename from libs/common/src/dtos/registration-request/search-registration-request.request.ts
rename to libs/common/src/dtos/registration-request/search-registration-request.request.dto.ts
index 6588d96f..f41fdb56 100644
--- a/libs/common/src/dtos/registration-request/search-registration-request.request.ts
+++ b/libs/common/src/dtos/registration-request/search-registration-request.request.dto.ts
@@ -1,22 +1,38 @@
 import { ApiProperty } from '@nestjs/swagger';
 import { SearchRegistrationRequestFiltersDto } from './search-registration-request-filters.dto';
+import { IsDefined, IsNumber, IsString, MaxLength } from 'class-validator';
 
 export class SearchRegistrationRequestRequest {
   @ApiProperty({
-    example: 'search text',
+    example: '',
     description: 'The text to search for',
+    required: true,
   })
+  @IsDefined()
+  @IsString()
+  @MaxLength(50)
   searchText: string;
 
-  @ApiProperty({ example: 1, description: 'The page number for pagination' })
+  @ApiProperty({
+    example: 1,
+    description: 'The page number for pagination',
+    required: false,
+  })
+  @IsNumber()
   page: number;
 
-  @ApiProperty({ example: 10, description: 'The number of items per page' })
+  @ApiProperty({
+    example: 10,
+    description: 'The number of items per page',
+    required: false,
+  })
+  @IsNumber()
   pageSize: number;
 
   @ApiProperty({
     type: SearchRegistrationRequestFiltersDto,
     description: 'The filters to apply to the search',
+    required: false,
   })
   filters: SearchRegistrationRequestFiltersDto;
 }
diff --git a/libs/common/src/dtos/registration-request/search-registration-request.response.ts b/libs/common/src/dtos/registration-request/search-registration-request.response.dto.ts
similarity index 100%
rename from libs/common/src/dtos/registration-request/search-registration-request.response.ts
rename to libs/common/src/dtos/registration-request/search-registration-request.response.dto.ts
diff --git a/package.json b/package.json
index f1412338..0c4445ad 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
     "build": "nest build",
     "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
     "start": "nest start",
-    "start:dev": "nest start --watch",
+    "start:dev": "nest start --watch --debug",
     "start:local": "dotenv -e .local.env nest start --watch",
     "start:prod-local": "dotenv -e .production.env nest start",
     "start:debug": "nest start --debug --watch",
diff --git a/prisma/schema/registration-request-status.prisma b/prisma/schema/registration-request-status.prisma
index 7a412f06..27c97c6e 100644
--- a/prisma/schema/registration-request-status.prisma
+++ b/prisma/schema/registration-request-status.prisma
@@ -1,6 +1,5 @@
 model RegistrationRequestStatus {
-  id     Int    @id @unique
-  code   String @unique @db.VarChar(8)
-
+  id                  Int                   @id @unique
+  code                String                @unique @db.VarChar(8)
   RegistrationRequest RegistrationRequest[]
 }
diff --git a/prisma/schema/registration-request.prisma b/prisma/schema/registration-request.prisma
index 3ae2129e..70279e77 100644
--- a/prisma/schema/registration-request.prisma
+++ b/prisma/schema/registration-request.prisma
@@ -1,10 +1,9 @@
 model RegistrationRequest {
-  id          Int      @id @default(autoincrement())
-  note        String   @db.VarChar(50)
-  requestDate DateTime @default(now())
-
+  id          Int                       @id @default(autoincrement())
   statusId    Int
-  status      RegistrationRequestStatus @relation(fields: [statusId], references: [id])
   userId      Int                       @unique
+  note        String                    @db.VarChar(50)
+  requestDate DateTime                  @default(now())
+  status      RegistrationRequestStatus @relation(fields: [statusId], references: [id])
   user        User                      @relation(fields: [userId], references: [id])
 }
diff --git a/prisma/schema/user.prisma b/prisma/schema/user.prisma
index b96bf24d..af8c15a3 100644
--- a/prisma/schema/user.prisma
+++ b/prisma/schema/user.prisma
@@ -1,12 +1,11 @@
 model User {
-  id                    Int    @id @default(autoincrement())
-  firstName             String @db.VarChar(50)
-  lastName              String @db.VarChar(50)
-  email                 String @unique @db.VarChar(250)
-  password              String @db.VarChar(255)
-  phone                 String @db.VarChar(20)
-  documentType          String @db.VarChar(4)
-  documentNumber        String @db.VarChar(11)
-  
-  registrationRequest   RegistrationRequest?
+  id                  Int                  @id @default(autoincrement())
+  firstName           String               @db.VarChar(50)
+  lastName            String               @db.VarChar(50)
+  email               String               @unique @db.VarChar(250)
+  password            String               @db.VarChar(255)
+  phone               String               @db.VarChar(20)
+  documentType        String               @db.VarChar(4)
+  documentNumber      String               @db.VarChar(11)
+  registrationRequest RegistrationRequest?
 }


Reviews:
user: login: tomasamori
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T10:16:17Z
user: login: MartinLambrecht
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T14:15:21Z
user: login: MartinLambrecht
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-20T14:16:21Z

Review comments:
path: .vscode/launch.json
user: login: tomasamori
body: Este archivo no debería ignorarse al ser configuración local de tu IDE?
created_at: 2025-03-20T09:16:08Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,14 @@
+import { RegistrationRequestStatus } from '@mp/common/constants';
+import { ApiProperty } from '@nestjs/swagger';
+import { IsEnum, IsNotEmpty } from 'class-validator';
+
 export class SearchRegistrationRequestFiltersDto {
+  @ApiProperty({
+    example: ['Pending'],
+    description: 'Filter by the status of the registration requests',
+    required: false,
+  })
+  @IsEnum(RegistrationRequestStatus)
+  @IsNotEmpty()
path: libs/common/src/dtos/registration-request/search-registration-request-filters.dto.ts
user: login: tomasamori
body: Es correcto validar que no esté vacío si el campo no es requerido?
created_at: 2025-03-20T10:09:55Z
author_association: CONTRIBUTOR
path: libs/common/src/dtos/registration-request/search-registration-request.request.ts
user: login: tomasamori
body: Sufijo .dto.ts al nombre del archivo
created_at: 2025-03-20T10:15:59Z
author_association: CONTRIBUTOR
path: .vscode/launch.json
user: login: MartinLambrecht
body: Lo deje para que ustedes lo bajen y les enseño como debuggear en la prox metting, pero esta bien el comentario
created_at: 2025-03-20T14:15:21Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,14 @@
+import { RegistrationRequestStatus } from '@mp/common/constants';
+import { ApiProperty } from '@nestjs/swagger';
+import { IsEnum, IsNotEmpty } from 'class-validator';
+
 export class SearchRegistrationRequestFiltersDto {
+  @ApiProperty({
+    example: ['Pending'],
+    description: 'Filter by the status of the registration requests',
+    required: false,
+  })
+  @IsEnum(RegistrationRequestStatus)
+  @IsNotEmpty()
path: libs/common/src/dtos/registration-request/search-registration-request-filters.dto.ts
user: login: MartinLambrecht
body: Sip, en caso de que no este no filtra por nada, en caso de que este debe tener un valor porque sino no devuelve ningún resultado
created_at: 2025-03-20T14:16:21Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-03-20T14:19:26Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=PF-UTN_ManagementPortal-BE&pullRequest=23) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [3 New issues](https://sonarcloud.io/project/issues?id=PF-UTN_ManagementPortal-BE&pullRequest=23&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=PF-UTN_ManagementPortal-BE&pullRequest=23&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=PF-UTN_ManagementPortal-BE&pullRequest=23&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [81.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=PF-UTN_ManagementPortal-BE&pullRequest=23&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=PF-UTN_ManagementPortal-BE&pullRequest=23&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=PF-UTN_ManagementPortal-BE&pullRequest=23)


author_association: NONE