From 98c62ac4603fa6d7c97e1a439f613379db7a2587 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sat, 18 May 2024 16:35:42 +0200 Subject: [PATCH 1/4] fix!: ensure category, room and station names are unique --- .../migration.sql | 16 ++++++++++++++++ prisma/schema.prisma | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 prisma/migrations/20240518143538_unique_cat_room_station/migration.sql diff --git a/prisma/migrations/20240518143538_unique_cat_room_station/migration.sql b/prisma/migrations/20240518143538_unique_cat_room_station/migration.sql new file mode 100644 index 0000000..7686fa8 --- /dev/null +++ b/prisma/migrations/20240518143538_unique_cat_room_station/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - A unique constraint covering the columns `[name]` on the table `categories` will be added. If there are existing duplicate values, this will fail. + - A unique constraint covering the columns `[name]` on the table `rooms` will be added. If there are existing duplicate values, this will fail. + - A unique constraint covering the columns `[name]` on the table `stations` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX "categories_name_key" ON "categories"("name"); + +-- CreateIndex +CREATE UNIQUE INDEX "rooms_name_key" ON "rooms"("name"); + +-- CreateIndex +CREATE UNIQUE INDEX "stations_name_key" ON "stations"("name"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 633705d..bfc2700 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -50,7 +50,7 @@ model User { // Hospital station model Station { id Int @id @default(autoincrement()) - name String + name String @unique Room Room[] hidden Boolean @default(false) @@ -60,7 +60,7 @@ model Station { // Hospital room model Room { id Int @id @default(autoincrement()) - name String + name String @unique station Station @relation(fields: [station_id], references: [id], onDelete: Restrict) station_id Int Patient Patient[] @@ -90,7 +90,7 @@ model Patient { // Entry category (e.g. Blood test, Exams, ...) model Category { id Int @id @default(autoincrement()) - name String + name String @unique color String? description String? EntryVersion EntryVersion[] From 882ae66a6a137259388525df2c91b8e1ed924d86 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sat, 18 May 2024 19:10:17 +0200 Subject: [PATCH 2/4] chore: remove unused zod-form-data dependency --- package.json | 3 +-- pnpm-lock.yaml | 11 ----------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/package.json b/package.json index 722de0f..67220ca 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,7 @@ "qs": "^6.12.1", "set-cookie-parser": "^2.6.0", "svelte-floating-ui": "^1.5.8", - "zod": "^3.23.8", - "zod-form-data": "^2.0.2" + "zod": "^3.23.8" }, "devDependencies": { "@faker-js/faker": "^8.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8e977f6..c90e8bb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,9 +41,6 @@ dependencies: zod: specifier: ^3.23.8 version: 3.23.8 - zod-form-data: - specifier: ^2.0.2 - version: 2.0.2(zod@3.23.8) devDependencies: '@faker-js/faker': @@ -5961,14 +5958,6 @@ packages: dev: true optional: true - /zod-form-data@2.0.2(zod@3.23.8): - resolution: {integrity: sha512-sKTi+k0fvkxdakD0V5rq+9WVJA3cuTQUfEmNqvHrTzPLvjfLmkkBLfR0ed3qOi9MScJXTHIDH/jUNnEJ3CBX4g==} - peerDependencies: - zod: '>= 3.11.0' - dependencies: - zod: 3.23.8 - dev: false - /zod-to-json-schema@3.23.0(zod@3.23.8): resolution: {integrity: sha512-az0uJ243PxsRIa2x1WmNE/pnuA05gUq/JB8Lwe1EDCCL/Fz9MgjYQ0fPlyc2Tcv6aF2ZA7WM5TWaRZVEFaAIag==} requiresBuild: true From 2a4bda70c6cfd85b4a32989a2e19ba718cc7717e Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sun, 19 May 2024 15:36:59 +0200 Subject: [PATCH 3/4] fix: allow multiple date filters --- src/lib/server/query/entry.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib/server/query/entry.ts b/src/lib/server/query/entry.ts index 3dcfe7f..1ac5157 100644 --- a/src/lib/server/query/entry.ts +++ b/src/lib/server/query/entry.ts @@ -287,6 +287,25 @@ left join stations s on s.id = r.station_id`, qb.addFilterClause(`ev.date <= ${qb.pvar()}`, dateRange.end); } }); + + const dfClauses: string[] = []; + const dfParams: Date[] = []; + filterListToArray(filter.date).forEach((itm) => { + const dateRange = DateRange.parse(itm, true); + const cl = []; + if (dateRange?.start) { + cl.push(`ev.date >= ${qb.pvar()}`); + dfParams.push(dateRange.start); + } + if (dateRange?.end) { + cl.push(`ev.date <= ${qb.pvar()}`); + dfParams.push(dateRange.end); + } + dfClauses.push(cl.join(" and ")); + }); + if (dfClauses.length > 0) { + qb.addFilterClause(dfClauses.join(" or "), ...dfParams); + } } const SORT_FIELDS: Record = { From 47f0a08ea3dbd8b1721a11c52b36c42ad56e8e29 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Sun, 19 May 2024 15:45:21 +0200 Subject: [PATCH 4/4] fix: add dumb-init to docker image --- Dockerfile | 3 ++- run/entrypoint.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6adb62d..f0631df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ COPY package.json pnpm-lock.yaml run/entrypoint.sh ./ COPY prisma ./prisma # Setup pnpm, install Prisma CLI (for generating client) and install dependencies -RUN npm config set update-notifier false && \ +RUN apk add dumb-init && \ + npm config set update-notifier false && \ corepack enable && \ pnpm i --prod && \ pnpm audit fix && \ diff --git a/run/entrypoint.sh b/run/entrypoint.sh index c749cb0..f7ebe95 100755 --- a/run/entrypoint.sh +++ b/run/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/dumb-init /bin/sh set -e # Migrate database before starting server npx prisma migrate deploy