fix all tables category adding#1612
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue with handling the "All Tables" category when creating or updating table categories. The "All Tables" category is a special virtual category with category_id: null that is not persisted to the database but should be included in the response.
Changes:
- Modified the
CreateOrUpdateTableCategoriesUseCaseto filter out the "All Tables" category (withcategory_id: null) before validation and database operations - Ensured the "All Tables" category is included in the response if it was provided in the input
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| backend/src/entities/table-categories/use-cases/create-or-update-table-categories.use.case.ts | Added logic to separate and handle the "All Tables" category, filter it from validation and DB operations, and include it in the response |
| backend/src/entities/table-categories/table-categories.controller.ts | Added empty line (appears unintentional) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const allTablesCategory = table_categories.find((category) => category.category_id === null); | ||
| const filteredCategories = table_categories.filter((category) => category.category_id !== null); |
There was a problem hiding this comment.
The code attempts to handle categories with category_id: null to support the "All Tables" category, but the CreateTableCategoryDto validation at the controller level requires category_id to be a non-empty string (with @IsString() and @IsNotEmpty() decorators). This means requests with category_id: null will be rejected by the validation pipe before reaching this use case. To fix this, update the CreateTableCategoryDto to make category_id optional and nullable by adding @IsOptional() and removing or conditionally applying the @IsNotEmpty() decorator, or alternatively use @ValidateIf to skip validation when category_id is null.
| @MasterPassword() masterPwd: string, | ||
| @Body() requestBody: CreateTableCategoryDto[], | ||
| ): Promise<Array<FoundTableCategoryRo>> { | ||
|
|
There was a problem hiding this comment.
This empty line appears to be unintentional whitespace. Consider removing it to maintain consistent code formatting.
No description provided.