fix(timesheet): never reuse a soft-deleted timesheet under MikroORM

Merged
CE
7d ago
+97-0

Problem

With MikroORM, TimesheetFirstOrCreateHandler looks up the employee's timesheet of the week with raw knex, which skips the soft-delete filter. A soft-deleted timesheet of that week was returned, and new time logs were attached to it instead of a new timesheet.

Fix

whereNull('deletedAt') on the knex lookup; a deleted timesheet is no longer matched and the existing TimesheetCreateCommand path runs. The TypeORM branch already excludes deleted rows.

Tests

New timesheet-first-or-create.handler.spec.ts on an in-memory SQLite store through knex: only a deleted timesheet โ†’ one TimesheetCreateCommand; a deleted and a live one โ†’ the live one, nothing created.

Notes

Not built or run locally.


Summary by cubic

Fixes TimesheetFirstOrCreateHandler reusing a soft-deleted timesheet under MikroORM. The raw knex lookup skipped the soft-delete filter, so new time logs were attached to a deleted timesheet of the week instead of a new one. The lookup now excludes rows with a deletedAt value, and the TypeORM branch already excluded them.

Adds an in-memory SQLite spec covering two cases: only a deleted timesheet for the week (triggers a TimesheetCreateCommand) and a deleted plus a live one (reuses the live one, creates nothing). The spec's knex config carries the userParams.schema the handler reads from the MikroORM knex; it is cast to Knex.Config because knex 3.3 types userParams only on TransactionConfig (TS2353).