Skip to content

fix: accept numeric teacherId in lesson bulk upload - #189

Closed
buzz-code wants to merge 1 commit into
mainfrom
claude/lessons-bulk-upload
Closed

buzz-code wants to merge 1 commit into
mainfrom
claude/lessons-bulk-upload

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

Summary

  • Bulk upload of lessons via the existing Excel import button failed validation for every row: Excel numeric cells arrive as JSON numbers, but Lesson.teacherId has @IsDigitsOnly(10) (string-only validator) and was missing the @StringType transform. Added @StringType (Type(() => String)) — same pattern as Student.tz — so class-transformer coerces the number to a digits string during both the CREATE-group ValidationPipe and prepareEntityBeforeSave.
  • New regression spec server/src/db/entities/__tests__/Lesson.entity.spec.ts: validates a row exactly as the client parses it from the lessons Excel (numeric teacherId/klasses, 'YYYY-MM-DD' dates, empty year) — asserts the transform, CREATE-group validation, and fillFields (klass/teacher reference resolution + Hebrew-year default). Verified it fails without the fix.

Verified end-to-end (lessons_kodesh.xlsx, 65 rows, school year 5787 / 2026-27)

  • Client import wiring already complete: client/src/entities/lesson.jsx importer → ResourceImportButton → readAsExcel + date fix → preview → per-row create; no client changes needed.
  • Parsed the actual Excel: 65 rows, dates resolve to 2026-09-01 / 2027-08-31 under UTC, Asia/Jerusalem and Europe/Berlin TZs; empty year defaults to current Hebrew year (5787) via fillDefaultYearValue; unique (userId, key, year) enforced by IsUniqueCombination.
  • Teacher/klass business keys resolve in @BeforeInsert fillFields (tz / key+year lookups).

Data prerequisites (not code)

Klasses (71100…72300) and teacher tzs must already exist for year 5787 in the target environment, or those rows save without the reference.

Tests

  • server: new spec + lesson.config.spec pass. Pre-existing failures unchanged (yemot e2e/scenario suites, year.util.behavior, attendance-cleanup-sweep, yemot-handler — date/env-dependent, fail identically with the change stashed).
  • client: no client code changed; client suite untouched.

Excel cells arrive as JSON numbers, but Lesson.teacherId only had
@IsDigitsOnly (a string validator), so every row of the lessons
bulk-upload failed validation with 'teacherId must contain digits
only'. Add @StringType (Type(() => String)) like Student.tz, so
class-transformer coerces the number to a digits string before both
the CREATE-group ValidationPipe and the entity save.

Covered by a new Lesson.entity.spec.ts that validates a row exactly
as the client parses it from the lessons_kodesh Excel (numeric
teacherId/klasses, date strings, empty year) and asserts the
@StringType transform, CREATE-group validation, and fillFields
reference resolution.
Copilot AI lite review requested due to automatic review settings September 16, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix and regression coverage address the import validation failure with no unresolved blocking issues.

Pull request overview

Fixes lesson bulk Excel imports by converting numeric teacherId values to strings before validation.

Changes:

  • Adds @StringType to Lesson.teacherId.
  • Adds regression coverage for validation and reference resolution.
File summaries
File Summary
server/src/db/entities/Lesson.entity.ts Coerces numeric teacher IDs to strings.
server/src/db/entities/__tests__/Lesson.entity.spec.ts Covers Excel-style lesson import behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@buzz-code

Copy link
Copy Markdown
Owner Author

Superseded by nra-server #58: IsDigitsOnly now coerces numeric values to strings centrally, making the per-field @StringType here redundant. The Lesson.entity.spec.ts test case is valuable — merged its intent into #58's coverage.

@buzz-code buzz-code closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants