2026-06-26 10:50:24 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Database Interface – abstract DB layer for Web CAD
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBProject {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
description: string | null;
|
|
|
|
|
|
owner_id: string;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
updated_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBDrawing {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
project_id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
data_json: string;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
updated_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBLayer {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
drawing_id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
visible: number;
|
|
|
|
|
|
locked: number;
|
|
|
|
|
|
color: string;
|
|
|
|
|
|
line_type: string;
|
|
|
|
|
|
transparency: number;
|
|
|
|
|
|
sort_order: number;
|
|
|
|
|
|
parent_id: string | null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBElement {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
drawing_id: string;
|
|
|
|
|
|
layer_id: string;
|
|
|
|
|
|
type: string;
|
|
|
|
|
|
x: number;
|
|
|
|
|
|
y: number;
|
|
|
|
|
|
width: number;
|
|
|
|
|
|
height: number;
|
|
|
|
|
|
properties_json: string;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBBlock {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
drawing_id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
description: string | null;
|
|
|
|
|
|
category: string;
|
|
|
|
|
|
elements_json: string;
|
|
|
|
|
|
thumbnail: string | null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBSetting {
|
|
|
|
|
|
key: string;
|
|
|
|
|
|
value: string;
|
|
|
|
|
|
updated_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBUser {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
email: string;
|
|
|
|
|
|
password_hash: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
role: string;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
updated_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-26 14:55:38 +02:00
|
|
|
|
export interface DBSession {
|
|
|
|
|
|
token: string;
|
|
|
|
|
|
user_id: string;
|
|
|
|
|
|
expires_at: number;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-04 16:08:51 +02:00
|
|
|
|
export interface DBNotification {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
user_id: string;
|
|
|
|
|
|
type: string;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
read: number;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DBProjectShare {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
project_id: string;
|
|
|
|
|
|
shared_with_email: string;
|
|
|
|
|
|
shared_by: string;
|
|
|
|
|
|
permission: string;
|
|
|
|
|
|
share_token: string | null;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-26 10:50:24 +02:00
|
|
|
|
export interface DatabaseInterface {
|
|
|
|
|
|
init(): Promise<void>;
|
|
|
|
|
|
close(): void;
|
|
|
|
|
|
|
|
|
|
|
|
// Users
|
|
|
|
|
|
getUser(id: string): DBUser | null;
|
|
|
|
|
|
getUserByEmail(email: string): DBUser | null;
|
|
|
|
|
|
createUser(data: Partial<DBUser>): DBUser;
|
|
|
|
|
|
updateUser(id: string, data: Partial<DBUser>): DBUser | null;
|
|
|
|
|
|
deleteUser(id: string): boolean;
|
|
|
|
|
|
listUsers(): DBUser[];
|
|
|
|
|
|
|
|
|
|
|
|
// Projects
|
|
|
|
|
|
listProjects(): DBProject[];
|
|
|
|
|
|
getProject(id: string): DBProject | null;
|
|
|
|
|
|
createProject(data: Partial<DBProject>): DBProject;
|
|
|
|
|
|
updateProject(id: string, data: Partial<DBProject>): DBProject | null;
|
|
|
|
|
|
deleteProject(id: string): boolean;
|
|
|
|
|
|
|
|
|
|
|
|
// Drawings
|
|
|
|
|
|
listDrawings(projectId: string): DBDrawing[];
|
|
|
|
|
|
getDrawing(id: string): DBDrawing | null;
|
|
|
|
|
|
createDrawing(data: Partial<DBDrawing>): DBDrawing;
|
|
|
|
|
|
updateDrawing(id: string, data: Partial<DBDrawing>): DBDrawing | null;
|
|
|
|
|
|
deleteDrawing(id: string): boolean;
|
|
|
|
|
|
|
|
|
|
|
|
// Layers
|
|
|
|
|
|
listLayers(drawingId: string): DBLayer[];
|
|
|
|
|
|
createLayer(data: Partial<DBLayer>): DBLayer;
|
|
|
|
|
|
updateLayer(id: string, data: Partial<DBLayer>): DBLayer | null;
|
|
|
|
|
|
deleteLayer(id: string): boolean;
|
|
|
|
|
|
|
|
|
|
|
|
// Elements
|
|
|
|
|
|
listElements(drawingId: string): DBElement[];
|
|
|
|
|
|
createElement(data: Partial<DBElement>): DBElement;
|
|
|
|
|
|
updateElement(id: string, data: Partial<DBElement>): DBElement | null;
|
|
|
|
|
|
deleteElement(id: string): boolean;
|
|
|
|
|
|
|
|
|
|
|
|
// Blocks
|
|
|
|
|
|
listBlocks(drawingId: string): DBBlock[];
|
|
|
|
|
|
createBlock(data: Partial<DBBlock>): DBBlock;
|
|
|
|
|
|
updateBlock(id: string, data: Partial<DBBlock>): DBBlock | null;
|
|
|
|
|
|
deleteBlock(id: string): boolean;
|
|
|
|
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
|
|
getSetting(key: string): DBSetting | null;
|
|
|
|
|
|
setSetting(key: string, value: string): void;
|
2026-06-26 14:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
// Sessions
|
|
|
|
|
|
createSession(data: Partial<DBSession>): DBSession;
|
|
|
|
|
|
getSession(token: string): DBSession | null;
|
|
|
|
|
|
deleteSession(token: string): boolean;
|
|
|
|
|
|
deleteExpiredSessions(): void;
|
2026-07-04 16:08:51 +02:00
|
|
|
|
|
|
|
|
|
|
// Notifications
|
|
|
|
|
|
listNotifications(userId: string): DBNotification[];
|
|
|
|
|
|
getNotification(id: string): DBNotification | null;
|
|
|
|
|
|
createNotification(data: Partial<DBNotification>): DBNotification;
|
|
|
|
|
|
markNotificationRead(id: string): boolean;
|
|
|
|
|
|
deleteNotification(id: string): boolean;
|
|
|
|
|
|
|
|
|
|
|
|
// Project Shares
|
|
|
|
|
|
listProjectShares(projectId: string): DBProjectShare[];
|
|
|
|
|
|
getProjectShare(id: string): DBProjectShare | null;
|
|
|
|
|
|
createProjectShare(data: Partial<DBProjectShare>): DBProjectShare;
|
|
|
|
|
|
deleteProjectShare(id: string): boolean;
|
2026-06-26 10:50:24 +02:00
|
|
|
|
}
|