Files
web-cad/backend/src/database/DatabaseInterface.ts
T

237 lines
6.2 KiB
TypeScript
Raw Normal View History

/**
* Database Interface abstract DB layer for Web CAD
*/
export interface DBProject {
id: string;
name: string;
description: string | null;
owner_id: string;
folder_id: string | null;
created_at: string;
updated_at: string;
}
export interface DBProjectFolder {
id: string;
name: string;
parent_id: string | null;
owner_id: string;
created_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;
}
export interface DBSession {
token: string;
user_id: string;
expires_at: number;
created_at: string;
}
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;
}
export interface DBGlobalBlockFolder {
id: string;
name: string;
parent_id: string | null;
created_at: string;
}
export interface DBGlobalBlock {
id: string;
folder_id: string | null;
name: string;
block_data: string;
svg_data: string | null;
is_favorite: boolean;
created_at: string;
updated_at: string;
}
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(ownerId?: string, folderId?: string | null): DBProject[];
getProject(id: string): DBProject | null;
createProject(data: Partial<DBProject>): DBProject;
updateProject(id: string, data: Partial<DBProject>): DBProject | null;
deleteProject(id: string): boolean;
moveProjectToFolder(projectId: string, folderId: string | null): DBProject | null;
// Project Folders
listProjectFolders(ownerId: string): DBProjectFolder[];
getProjectFolder(id: string): DBProjectFolder | null;
createProjectFolder(data: Partial<DBProjectFolder>): DBProjectFolder;
updateProjectFolder(id: string, data: Partial<DBProjectFolder>): DBProjectFolder | null;
deleteProjectFolder(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;
// Sessions
createSession(data: Partial<DBSession>): DBSession;
getSession(token: string): DBSession | null;
deleteSession(token: string): boolean;
deleteExpiredSessions(): void;
// 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;
// Global Block Folders
listGlobalFolders(parentId?: string | null): DBGlobalBlockFolder[];
getGlobalFolder(id: string): DBGlobalBlockFolder | null;
createGlobalFolder(data: Partial<DBGlobalBlockFolder>): DBGlobalBlockFolder;
updateGlobalFolder(id: string, data: Partial<DBGlobalBlockFolder>): DBGlobalBlockFolder | null;
deleteGlobalFolder(id: string): boolean;
// Global Blocks
listGlobalBlocks(folderId?: string | null): DBGlobalBlock[];
getGlobalBlock(id: string): DBGlobalBlock | null;
createGlobalBlock(data: Partial<DBGlobalBlock>): DBGlobalBlock;
updateGlobalBlock(id: string, data: Partial<DBGlobalBlock>): DBGlobalBlock | null;
deleteGlobalBlock(id: string): boolean;
// Guests (Task E6)
listGuests(drawingId: string): DBGuest[];
getGuest(id: string): DBGuest | null;
createGuest(data: Partial<DBGuest>): DBGuest;
updateGuest(id: string, data: Partial<DBGuest>): DBGuest | null;
deleteGuest(id: string): boolean;
}
// ─── Guests (Task E6) ──────────────────────────────────
export interface DBGuest {
id: string;
drawing_id: string;
name: string;
email?: string;
category: string; // 'standard' | 'vip' | 'staff'
seat_element_id?: string; // Verknüpfung zu einem chair-Element
notes?: string;
created_at: string;
}