feat: restructure backend with Elysia framework and add MQTT adapter
- Updated .gitignore to exclude generated files and database - Modified package.json to change dev script and add new dependencies - Removed src/index.ts and created app.ts for Elysia server initialization - Added environment variable configuration in config/env.ts - Implemented MQTT adapter in adapter/mqtt.ts for message handling - Created Prisma client in prisma/client.ts and defined schema in prisma/schema.prisma - Added seeding script in prisma/seed.ts for measurement points - Established logging utility in utils/logger.ts for structured logging - Created bed router in routes/bed.ts for handling bed-related routes
This commit is contained in:
parent
b76d6b99ee
commit
a767dc3635
14 changed files with 801 additions and 14 deletions
81
prisma/schema.prisma
Normal file
81
prisma/schema.prisma
Normal file
|
@ -0,0 +1,81 @@
|
|||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = "../generated/prisma"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model MeasurementPoint {
|
||||
id String @id @default(cuid())
|
||||
sensorId String @unique // e.g., "head-1", "back-2"
|
||||
label String // e.g., "Head Left", "Upper Back Center"
|
||||
zone String // e.g., "head", "back", "shoulders"
|
||||
x Int // X coordinate on bed layout
|
||||
y Int // Y coordinate on bed layout
|
||||
pin Int // Hardware pin number
|
||||
|
||||
// Threshold configuration
|
||||
warningThreshold Int // Pressure value that triggers warning
|
||||
alarmThreshold Int // Pressure value that triggers alarm
|
||||
warningDelayMs Int // Delay before warning escalates to alarm
|
||||
|
||||
// Timestamps
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
data MeasurementPointData[]
|
||||
alerts Alert[]
|
||||
}
|
||||
|
||||
model MeasurementPointData {
|
||||
id String @id @default(cuid())
|
||||
measurementPointId String
|
||||
|
||||
// Sensor reading data
|
||||
value Int // Analog sensor value (0-4095)
|
||||
|
||||
// Timestamps
|
||||
timestamp DateTime @default(now())
|
||||
time String // Formatted time string
|
||||
|
||||
// Relations
|
||||
measurementPoint MeasurementPoint @relation(fields: [measurementPointId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([measurementPointId, timestamp])
|
||||
}
|
||||
|
||||
enum AlertType {
|
||||
WARNING
|
||||
ALARM
|
||||
}
|
||||
|
||||
model Alert {
|
||||
id String @id @default(cuid())
|
||||
measurementPointId String
|
||||
|
||||
// Alert details
|
||||
type AlertType
|
||||
value Int // Sensor value that triggered alert
|
||||
threshold Int // Threshold that was exceeded
|
||||
|
||||
// Alert state
|
||||
acknowledged Boolean @default(false)
|
||||
silenced Boolean @default(false)
|
||||
|
||||
// Timing
|
||||
startTime DateTime @default(now())
|
||||
endTime DateTime?
|
||||
|
||||
// Relations
|
||||
measurementPoint MeasurementPoint @relation(fields: [measurementPointId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([measurementPointId, startTime])
|
||||
@@index([type, acknowledged])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue