From f1c8b8ea819791184ea436ca1bd802cf7a8697ad Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 05:35:21 +0000 Subject: [PATCH] feat(database): add DatabaseInterface.ts with abstract class for CRUD operations --- backend/src/database/DatabaseInterface.ts | 290 ++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 backend/src/database/DatabaseInterface.ts diff --git a/backend/src/database/DatabaseInterface.ts b/backend/src/database/DatabaseInterface.ts new file mode 100644 index 0000000..6c4521e --- /dev/null +++ b/backend/src/database/DatabaseInterface.ts @@ -0,0 +1,290 @@ +export type User = { + id: string; + email: string; + password_hash: string; + display_name: string; + role: string; + is_active: number; + created_at?: string; + updated_at?: string; +}; + +export type Session = { + id: string; + user_id: string; + token_hash: string; + expires_at: string; + created_at?: string; + ip_address?: string; + user_agent?: string; +}; + +export type Project = { + id: string; + name: string; + description?: string; + owner_id: string; + units: string; + created_at: string; + updated_at: string; + thumbnail_path?: string; +}; + +export type ProjectMember = { + id: string; + project_id: string; + user_id: string; + role: string; + invited_at?: string; + accepted_at?: string; +}; + +export type Layer = { + id: string; + project_id: string; + name: string; + visible: number; + locked: number; + color?: string; + line_type?: string; + transparency: number; + sort_order: number; + created_at?: string; +}; + +export type Element = { + id: string; + project_id: string; + layer_id?: string; + element_type: string; + geometry: string; + style?: string; + metadata?: string; + created_at?: string; + updated_at?: string; +}; + +export type Block = { + id: string; + project_id: string; + name: string; + base_element_ids: string; + created_at?: string; +}; + +export type BlockInstance = { + id: string; + project_id: string; + block_id: string; + layer_id?: string; + position_x: number; + position_y: number; + rotation: number; + scale_x: number; + scale_y: number; + created_at?: string; +}; + +export type BackgroundImage = { + id: string; + project_id: string; + file_path: string; + position_x: number; + position_y: number; + scale: number; + rotation: number; + opacity: number; + created_at?: string; +}; + +export type Version = { + id: string; + project_id: string; + label?: string; + description?: string; + snapshot_data: Buffer; + created_by?: string; + created_at?: string; +}; + +export type Plugin = { + id: string; + name: string; + version: string; + display_name: string; + description?: string; + manifest: string; + is_active: number; + installed_at?: string; + activated_at?: string; +}; + +export type Setting = { + id: string; + user_id?: string; + key: string; + value: string; + updated_at?: string; +}; + +export type AIConfig = { + id: string; + scope: string; + project_id?: string; + api_base_url?: string; + api_key_encrypted?: string; + model: string; + created_at?: string; + updated_at?: string; +}; + +export type Webhook = { + id: string; + project_id: string; + url: string; + event: string; + is_active: number; + created_at?: string; +}; + +export type AuditLog = { + id: string; + user_id?: string; + project_id?: string; + action: string; + details?: string; + ip_address?: string; + created_at?: string; +}; + +export interface DatabaseInterface { + // Users + createUser(user: Omit): Promise; + getUserById(id: string): Promise; + getUserByEmail(email: string): Promise; + updateUser(id: string, updates: Partial): Promise; + deleteUser(id: string): Promise; + getAllUsers(): Promise; + + // Sessions + createSession(session: Omit): Promise; + getSessionById(id: string): Promise; + getSessionByToken(token_hash: string): Promise; + updateSession(id: string, updates: Partial): Promise; + deleteSession(id: string): Promise; + deleteExpiredSessions(): Promise; + + // Projects + createProject(project: Omit): Promise; + getProjectById(id: string): Promise; + getProjectsByOwner(owner_id: string): Promise; + updateProject(id: string, updates: Partial): Promise; + deleteProject(id: string): Promise; + getAllProjects(): Promise; + + // Project Members + createProjectMember(member: Omit): Promise; + getProjectMemberById(id: string): Promise; + getProjectMembers(project_id: string): Promise; + updateProjectMember(id: string, updates: Partial): Promise; + deleteProjectMember(id: string): Promise; + isProjectMember(project_id: string, user_id: string): Promise; + + // Layers + createLayer(layer: Omit): Promise; + getLayerById(id: string): Promise; + getLayersByProject(project_id: string): Promise; + updateLayer(id: string, updates: Partial): Promise; + deleteLayer(id: string): Promise; + getAllLayers(): Promise; + + // Elements + createElement(element: Omit): Promise; + getElementById(id: string): Promise; + getElementsByProject(project_id: string): Promise; + getElementsByLayer(layer_id: string): Promise; + updateElement(id: string, updates: Partial): Promise; + deleteElement(id: string): Promise; + getAllElements(): Promise; + + // Blocks + createBlock(block: Omit): Promise; + getBlockById(id: string): Promise; + getBlocksByProject(project_id: string): Promise; + updateBlock(id: string, updates: Partial): Promise; + deleteBlock(id: string): Promise; + getAllBlocks(): Promise; + + // Block Instances + createBlockInstance(instance: Omit): Promise; + getBlockInstanceById(id: string): Promise; + getBlockInstancesByProject(project_id: string): Promise; + getBlockInstancesByBlock(block_id: string): Promise; + updateBlockInstance(id: string, updates: Partial): Promise; + deleteBlockInstance(id: string): Promise; + getAllBlockInstances(): Promise; + + // Background Images + createBackgroundImage(image: Omit): Promise; + getBackgroundImageById(id: string): Promise; + getBackgroundImagesByProject(project_id: string): Promise; + updateBackgroundImage(id: string, updates: Partial): Promise; + deleteBackgroundImage(id: string): Promise; + getAllBackgroundImages(): Promise; + + // Versions + createVersion(version: Omit): Promise; + getVersionById(id: string): Promise; + getVersionsByProject(project_id: string): Promise; + updateVersion(id: string, updates: Partial): Promise; + deleteVersion(id: string): Promise; + getAllVersions(): Promise; + + // Plugins + createPlugin(plugin: Omit): Promise; + getPluginById(id: string): Promise; + getPluginByName(name: string): Promise; + updatePlugin(id: string, updates: Partial): Promise; + deletePlugin(id: string): Promise; + getAllPlugins(): Promise; + getActivePlugins(): Promise; + + // Settings + createSetting(setting: Omit): Promise; + getSettingById(id: string): Promise; + getSettingByKey(key: string, user_id?: string): Promise; + updateSetting(id: string, updates: Partial): Promise; + deleteSetting(id: string): Promise; + getAllSettings(): Promise; + + // AI Config + createAIConfig(config: Omit): Promise; + getAIConfigById(id: string): Promise; + getAIConfigByProject(project_id: string): Promise; + updateAIConfig(id: string, updates: Partial): Promise; + deleteAIConfig(id: string): Promise; + getAllAIConfigs(): Promise; + + // Webhooks + createWebhook(webhook: Omit): Promise; + getWebhookById(id: string): Promise; + getWebhooksByProject(project_id: string): Promise; + updateWebhook(id: string, updates: Partial): Promise; + deleteWebhook(id: string): Promise; + getAllWebhooks(): Promise; + + // Audit Log + createAuditLog(log: Omit): Promise; + getAuditLogById(id: string): Promise; + getAuditLogsByUser(user_id: string): Promise; + getAuditLogsByProject(project_id: string): Promise; + getAllAuditLogs(): Promise; + + // Migration + runMigration(migrationScript: string): Promise; + getMigrationVersion(): Promise; + setMigrationVersion(version: number): Promise; + + // Utility + close(): Promise; +} \ No newline at end of file