fix(dataset): make api fields optional and add guards to prevent null fields#2847
Open
belfhi wants to merge 2 commits into
Open
fix(dataset): make api fields optional and add guards to prevent null fields#2847belfhi wants to merge 2 commits into
belfhi wants to merge 2 commits into
Conversation
added null check for attachments include to prevent http 400 for empty attachments. add include fields to DTO add defaults to fields to prevent null in API response.
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/common/utils.ts" line_range="1343-1350" />
<code_context>
return keys.map((key) => decodeURIComponentExtended(key));
}
+export function filterNullFromArray<T>(
+ value: (T | null | undefined)[] | undefined,
+): T[] | undefined {
+ if (!value) return undefined;
+ const filtered = value.filter(
+ (item): item is T => item !== null && item !== undefined,
+ );
+ return filtered.length > 0 ? filtered : undefined;
+}
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider whether converting empty arrays to `undefined` is desirable for DTO transformations
Because this helper returns `undefined` for empty arrays, DTO fields using `@Transform(({ value }) => filterNullFromArray<string>(value))` (e.g. `keywords`, `proposalIds`) will emit `undefined` instead of `[]` when stored arrays are empty. This changes the API surface and may break consumers that expect these properties to always exist (even when empty), especially given the new Mongoose defaults to `[]`. If callers rely on that stability, consider returning `filtered` even when empty.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #2386
Description
Motivation
Fixes
Changes:
Tests included
Documentation
official documentation info
Summary by Sourcery
Make dataset-related API response fields safer by allowing optional version metadata, preventing null array values, and improving include-parameter handling and relation loading.
Bug Fixes:
Enhancements: