-
Notifications
You must be signed in to change notification settings - Fork 20
Provide name field in user list api response #151
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
base: release-1.0.0
Are you sure you want to change the base?
Conversation
WalkthroughThis change introduces a new method in the PostgresFieldsService to retrieve and process custom field data for a specific user by joining multiple database tables. The method includes conditional processing based on the source of field values, error handling, and logging. In addition, the PostgresUserService's findAllUserDetails method is updated to include a new property ('name') for each custom field in the returned user details. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User/Caller
participant S as PostgresFieldsService
participant DB as Database
U->>S: call getUserCustomFieldDetails(userId, fieldOption)
S->>DB: Execute SQL join across Users, FieldValues, Fields
DB-->>S: Return raw field data
alt Source is "fieldparams"
S->>S: Map value to label using field options
else Source is "table"
S->>S: Fetch dynamic option label based on value
end
S-->>U: Return array of processed field data
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
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.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
src/adapters/postgres/fields-adapter.ts (2)
1695-1698: Remove unused parameterfieldOption.The
fieldOptionparameter is declared but never used in the method implementation. Consider removing it to maintain clean and maintainable code.- public async getUserCustomFieldDetails( - userId: string, - fieldOption?: boolean - ) { + public async getUserCustomFieldDetails(userId: string) {
1717-1752: Add error handling and optimize async operations.The data processing logic has several areas for improvement:
- Missing error handling for database operations
- Inefficient async/await usage inside map
- Direct mutation of the data object
Consider refactoring the code as follows:
- let result = await this.fieldsRepository.query(query, [userId]); - result = result.map(async (data) => { + try { + let result = await this.fieldsRepository.query(query, [userId]); + const processedResults = await Promise.all(result.map(async (data) => { + const { fieldParams, sourceDetails, ...rest } = data; + const originalValue = data.value; + let processedValue = data.value; + + if (sourceDetails) { + try { + if (sourceDetails.source === "fieldparams") { + const matchingOption = fieldParams.options.find( + option => data.value === option.value + ); + if (matchingOption) { + processedValue = matchingOption.label; + } + } else if (sourceDetails.source === "table") { + const labels = await this.findDynamicOptions( + sourceDetails.table, + `value='${data.value}'` + ); + if (labels?.[0]?.name) { + processedValue = labels[0].name; + } + } + } catch (error) { + LoggerUtil.error( + "Error processing field value", + `Error: ${error.message}` + ); + } + } + + return { + ...rest, + value: processedValue, + code: originalValue, + }; + })); + + return processedResults; + } catch (error) { + LoggerUtil.error( + "Error fetching user custom field details", + `Error: ${error.message}` + ); + throw error; + }🧰 Tools
🪛 Biome (1.9.4)
[error] 1740-1740: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
[error] 1741-1741: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
🧹 Nitpick comments (1)
src/adapters/postgres/fields-adapter.ts (1)
1699-1715: Improve SQL query readability with consistent indentation.While the query logic is sound, the readability can be improved with consistent indentation. Consider reformatting the query for better maintainability.
const query = ` - SELECT DISTINCT - f."fieldId", - f."name", - f."label", - fv."value", - f."type", - f."fieldParams", - f."sourceDetails" - FROM public."Users" u - LEFT JOIN ( - SELECT DISTINCT ON (fv."fieldId", fv."itemId") fv.* - FROM public."FieldValues" fv - ) fv ON fv."itemId" = u."userId" - INNER JOIN public."Fields" f ON fv."fieldId" = f."fieldId" - WHERE u."userId" = $1; + SELECT DISTINCT + f."fieldId", + f."name", + f."label", + fv."value", + f."type", + f."fieldParams", + f."sourceDetails" + FROM public."Users" u + LEFT JOIN ( + SELECT DISTINCT ON (fv."fieldId", fv."itemId") fv.* + FROM public."FieldValues" fv + ) fv ON fv."itemId" = u."userId" + INNER JOIN public."Fields" f ON fv."fieldId" = f."fieldId" + WHERE u."userId" = $1;
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/adapters/postgres/fields-adapter.ts(1 hunks)src/adapters/postgres/user-adapter.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/adapters/postgres/user-adapter.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.ts`: "Review the JavaScript code for conformity with t...
**/*.ts: "Review the JavaScript code for conformity with the Google JavaScript style guide, highlighting any deviations. Ensure that:
- The code adheres to best practices associated with nodejs.
- The code adheres to best practices associated with nestjs framework.
- The code adheres to best practices recommended for performance.
- The code adheres to similar naming conventions for controllers, models, services, methods, variables."
src/adapters/postgres/fields-adapter.ts



Summary by CodeRabbit