diff --git a/backend/src/services/current-stock.ts b/backend/src/services/current-stock.ts index 6e16cb3..96b68de 100644 --- a/backend/src/services/current-stock.ts +++ b/backend/src/services/current-stock.ts @@ -99,9 +99,16 @@ export function computeMedicationCurrentStock(options: { const match = doseIdPattern.exec(dose.doseId); if (!match) continue; + const parsedMedicationId = Number.parseInt(match[1], 10); const parsedIntakeIndex = Number.parseInt(match[2], 10); const doseDateOnlyMs = Number.parseInt(match[3], 10); - if (Number.isNaN(parsedIntakeIndex) || Number.isNaN(doseDateOnlyMs) || parsedIntakeIndex !== intakeIndex) { + if ( + Number.isNaN(parsedMedicationId) || + Number.isNaN(parsedIntakeIndex) || + Number.isNaN(doseDateOnlyMs) || + parsedMedicationId !== medication.id || + parsedIntakeIndex !== intakeIndex + ) { continue; } @@ -125,9 +132,16 @@ export function computeMedicationCurrentStock(options: { const match = doseIdPattern.exec(dose.doseId); if (!match) continue; + const parsedMedicationId = Number.parseInt(match[1], 10); const parsedIntakeIndex = Number.parseInt(match[2], 10); const doseDateOnlyMs = Number.parseInt(match[3], 10); - if (Number.isNaN(parsedIntakeIndex) || Number.isNaN(doseDateOnlyMs) || parsedIntakeIndex !== intakeIndex) { + if ( + Number.isNaN(parsedMedicationId) || + Number.isNaN(parsedIntakeIndex) || + Number.isNaN(doseDateOnlyMs) || + parsedMedicationId !== medication.id || + parsedIntakeIndex !== intakeIndex + ) { continue; } diff --git a/backend/src/test/e2e-routes.test.ts b/backend/src/test/e2e-routes.test.ts index dfe8312..849b4d0 100644 --- a/backend/src/test/e2e-routes.test.ts +++ b/backend/src/test/e2e-routes.test.ts @@ -123,6 +123,7 @@ async function createSchema(client: Client) { `CREATE TABLE IF NOT EXISTS user_settings ( id integer PRIMARY KEY AUTOINCREMENT, user_id integer NOT NULL UNIQUE, + timezone text NOT NULL DEFAULT '', email_enabled integer NOT NULL DEFAULT 0, notification_email text, email_stock_reminders integer NOT NULL DEFAULT 1, diff --git a/backend/src/test/integration.test.ts b/backend/src/test/integration.test.ts index 599a139..13172c2 100644 --- a/backend/src/test/integration.test.ts +++ b/backend/src/test/integration.test.ts @@ -117,6 +117,7 @@ async function createSchema(client: Client) { `CREATE TABLE IF NOT EXISTS user_settings ( id integer PRIMARY KEY AUTOINCREMENT, user_id integer NOT NULL UNIQUE, + timezone text NOT NULL DEFAULT '', email_enabled integer NOT NULL DEFAULT 0, notification_email text, email_stock_reminders integer NOT NULL DEFAULT 1, diff --git a/backend/src/test/planner.test.ts b/backend/src/test/planner.test.ts index 9282e73..e02e690 100644 --- a/backend/src/test/planner.test.ts +++ b/backend/src/test/planner.test.ts @@ -134,6 +134,7 @@ async function createSchema(client: Client) { `CREATE TABLE IF NOT EXISTS user_settings ( id integer PRIMARY KEY AUTOINCREMENT, user_id integer NOT NULL UNIQUE, + timezone text NOT NULL DEFAULT '', email_enabled integer NOT NULL DEFAULT 0, notification_email text, email_stock_reminders integer NOT NULL DEFAULT 1,