Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/database/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const runs = pgTable("runs", {
location: varchar("location", { length: 255 }), // place or tag for run
profile: integer("profile").references(() => profiles.id), // associated profile
lower_bound_idx: integer("lower_bound_idx").notNull().default(0), // inclusive trim start index (default: 0)
upper_bound_idx: integer("upper_bound_idx").notNull(), // inclusive trim end index (set by service layer to length-1)
upper_bound_idx: integer("upper_bound_idx"), // inclusive trim end index (set by service layer to length-1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While making upper_bound_idx nullable in the database schema is necessary to allow it to be set to blank, the current backend implementation will prevent this from working as expected:

  1. DTO Validation Failure: In apps/backend/src/runs/dto/update-run.dto.ts, upper_bound_idx is decorated with @IsInt() and @Min(0). If a client sends null, validation will fail with a 400 Bad Request. You should update the DTO to allow null, for example:
    @IsOptional()
    @IsInt()
    @Min(0)
    @ValidateIf((object, value) => value !== null)
    upper_bound_idx?: number | null;
  2. Service Type Mismatch: In RunsService (runs.service.ts), the updates parameter type for updateRun and data for createRun define upper_bound_idx?: number, which does not permit null. These should be updated to number | null.
  3. Nullish Coalescing Logic: In RunsService.updateRun, the line:
    const effectiveUpperBound = updates.upper_bound_idx ?? currentRun.upper_bound_idx ?? Math.max(effectiveLength - 1, 0);
    uses the nullish coalescing operator (??). If updates.upper_bound_idx is passed as null to clear the bound, updates.upper_bound_idx ?? ... will fall back to currentRun.upper_bound_idx (the old non-null value), preventing the field from ever being cleared/set to null in the database. You will need to adjust this logic to distinguish between undefined (no update) and null (explicitly clearing the bound).

front_freq: integer("front_freq"), // front suspension sample frequency
rear_freq: integer("rear_freq"), // rear suspension sample frequency
createdAt: timestamp("created_at").defaultNow(),
Expand Down
Loading