From b063f9ab33030378a589523dc3befcf4d3ffb412 Mon Sep 17 00:00:00 2001 From: CodedSakura Date: Mon, 2 Nov 2026 16:52:07 +0200 Subject: [PATCH] split movement into movement_components, some more work on html --- shared/types.ts | 18 ++++++--- src/main.ts | 23 +++++++++--- web/index.html | 98 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 123 insertions(+), 16 deletions(-) diff --git a/shared/types.ts b/shared/types.ts index 17b5028..eae34b1 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -61,18 +61,24 @@ export const projectComponentColumns = [ export interface Movement { id: number, // integer - component: number, // integer - quantity: number, // integer date: number | null, // integer reason: string | null, project: number | null, // integer - price: number | null, // integer } export const movementColumns = [ - "component", - "quantity", "date", "reason", "project", - "price", ] as const satisfies (keyof Movement)[]; + +export interface MovementComponent { + movement: number, // integer + component: number, // integer + quantity: number, // integer + price: number | null, // integer +} +export const movementComponentColumns = [ + "component", + "quantity", + "price", +] as const satisfies (keyof MovementComponent)[]; diff --git a/src/main.ts b/src/main.ts index 8505e7b..99e8092 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,10 @@ import { serve } from "@hono/node-server"; import { Hono } from "hono"; import { showRoutes } from "hono/dev"; import { DatabaseSync, SQLInputValue } from "node:sqlite"; -import { componentColumns, locationColumns, movementColumns, projectColumns, projectComponentColumns } from "../shared/types"; +import { + componentColumns, locationColumns, movementColumns, + movementComponentColumns, projectColumns, projectComponentColumns +} from "../shared/types"; const app = new Hono(); const api = new Hono().basePath("/api"); @@ -44,6 +47,7 @@ const tables: [string, string[]][] = [ [ "project", projectColumns ], [ "project_component", projectComponentColumns ], [ "movement", movementColumns ], + [ "movement_component", movementComponentColumns ], ]; for (const [ tableName, columns ] of tables) { const path = `/${tableName.replace(/_(.)/g, (_, v) => v.toUpperCase())}`; @@ -128,18 +132,25 @@ for (const [ tableName, columns ] of tables) { sql.run`CREATE TABLE movement ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - component INTEGER NOT NULL, - quantity INTEGER NOT NULL, date INTEGER, reason TEXT, project INTEGER, - price INTEGER, - FOREIGN KEY (component) REFERENCES component(id), FOREIGN KEY (project) REFERENCES project(id) ) STRICT`; - sql.run`CREATE INDEX movement_component_idx ON movement(component)`; sql.run`CREATE INDEX movement_project_idx ON movement(project)`; + sql.run`CREATE TABLE movement_component ( + movement INTEGER NOT NULL, + component INTEGER NOT NULL, + quantity INTEGER NOT NULL, + price INTEGER, + PRIMARY KEY (movement, component), + FOREIGN KEY (movement) REFERENCES movement(id), + FOREIGN KEY (component) REFERENCES component(id) + ) STRICT`; + sql.run`CREATE INDEX movement_component_component_idx ON movement_component(component)`; + sql.run`CREATE INDEX movement_component_movement_idx ON movement_component(movement)`; + // language=SQLite - no idea why it's not doing that automatically here sql.run`INSERT INTO version (version) VALUES (1)`; console.log("initialized database to version 1"); diff --git a/web/index.html b/web/index.html index 2724c13..1a6a3dc 100644 --- a/web/index.html +++ b/web/index.html @@ -9,7 +9,7 @@
Components: - +
@@ -26,7 +26,7 @@ -
ID