Open yogesh1801 opened 3 days ago
β±οΈ Estimated effort to review [1-5] | 3 |
π§ͺ Relevant tests | Yes |
π Security concerns | No |
β‘ Key issues to review | None |
Category | Suggestion | Score |
Enhancement |
Add validation for pagination parameters to ensure they are non-negative and within a reasonable range___ **Consider validating thepage and limit query parameters to ensure they are non-negative integers. This prevents potential issues with pagination logic where negative values could lead to unexpected behavior or errors.** [apps/api/src/variable/controller/variable.controller.ts [109-110]](https://github.com/keyshade-xyz/keyshade/pull/304/files#diff-7639f037978995ad2ebde29feddffad312b5f7f22625024df30c59d3c0b7927aR109-R110) ```diff -@Query('page') page: number = 0, -@Query('limit') limit: number = 10 +@Query('page', new ParseIntPipe({ min: 0 })) page: number = 0, +@Query('limit', new ParseIntPipe({ min: 1, max: 100 })) limit: number = 10 ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 9Why: This suggestion improves the robustness of the API by ensuring that pagination parameters are within a valid range, preventing potential issues with negative values or excessively large limits. | 9 |
Error handling |
Handle the case where no revisions are found by throwing a NotFoundException___ **Implement error handling for the scenario where no revisions are found for the givenvariable and environment IDs. This could involve returning a specific message or an empty array, depending on the desired API behavior.** [apps/api/src/variable/service/variable.service.ts [628-635]](https://github.com/keyshade-xyz/keyshade/pull/304/files#diff-db1895137a9c036373abefb8c924150d4f2022fd6d4f5271cc6c95c443bf01cfR628-R635) ```diff const revisions = await this.prisma.variableVersion.findMany({ where: { variableId: variableId, environmentId: environmentId }, skip: page * limit, take: limit }) +if (revisions.length === 0) { + throw new NotFoundException(`No revisions found for variable ID ${variableId} in environment ID ${environmentId}.`); +} ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 8Why: Implementing error handling for cases where no revisions are found improves the API's clarity and user experience by providing specific feedback when no data is available. | 8 |
Performance |
Suggest adding a database index to improve query performance for fetching variable revisions___ **To optimize database queries, consider adding an index on thevariableId and environmentId columns in the variableVersion table if not already present. This can significantly improve the performance of the query fetching variable revisions.** [apps/api/src/variable/service/variable.service.ts [628-635]](https://github.com/keyshade-xyz/keyshade/pull/304/files#diff-db1895137a9c036373abefb8c924150d4f2022fd6d4f5271cc6c95c443bf01cfR628-R635) ```diff +// Ensure your database has an index on `variableId` and `environmentId` for the `variableVersion` table. const revisions = await this.prisma.variableVersion.findMany({ where: { variableId: variableId, environmentId: environmentId }, skip: page * limit, take: limit }) ``` - [ ] **Apply this suggestion** Suggestion importance[1-10]: 7Why: Adding an index can significantly improve query performance, especially for large datasets. However, this suggestion is more of a general optimization tip and may not be directly applicable to the PR code diff. | 7 |
Maintainability |
Enhance method signature by adding explicit return type annotations___ **Add explicit type annotations for the parameters in thegetRevisionsOfVariable method to enhance code readability and maintainability.** [apps/api/src/variable/controller/variable.controller.ts [105-110]](https://github.com/keyshade-xyz/keyshade/pull/304/files#diff-7639f037978995ad2ebde29feddffad312b5f7f22625024df30c59d3c0b7927aR105-R110) ```diff async getRevisionsOfVariable( @CurrentUser() user: User, @Param('variableId') variableId: string, @Param('environmentId') environmentId: string, @Query('page') page: number = 0, @Query('limit') limit: number = 10 -) +): Promise Suggestion importance[1-10]: 6Why: Adding explicit return type annotations improves code readability and maintainability, but it is a minor enhancement compared to functional improvements or bug fixes. | 6 |
User description
Description
Adds a getRevisionsOfVariable method to get revisions of a variable
Fixes #271
Dependencies
Mention any dependencies/packages used
Future Improvements
Mention any improvements to be done in future related to any file/feature
Mentions
Mention and tag the people
Screenshots of relevant screens
Add screenshots of relevant screens
Developer's checklist
If changes are made in the code:
Documentation Update
PR Type
Enhancement, Tests
Description
getRevisionsOfVariable
to fetch revisions of a variable with pagination support.Changes walkthrough π
variable.controller.ts
Add endpoint to fetch variable revisions with pagination
apps/api/src/variable/controller/variable.controller.ts
getRevisionsOfVariable
endpoint to fetch variable revisions.variable.service.ts
Implement method to retrieve variable revisions with authority checks
apps/api/src/variable/service/variable.service.ts
getRevisionsOfVariable
method to retrieve variable revisions.variable.e2e.spec.ts
Add tests for getRevisionsOfVariable endpoint
apps/api/src/variable/variable.e2e.spec.ts
getRevisionsOfVariable
endpoint.variable/environment, and access control.