Migrate admin API to typescript

This commit is contained in:
2025-05-05 21:28:29 +02:00
parent 043eab423f
commit 8849deec21
4 changed files with 242 additions and 49 deletions

60
app/src/types/adminApi.ts Normal file
View File

@@ -0,0 +1,60 @@
import { UserRole } from './authApi';
// CreateUserRequest holds the request fields for creating a new user
export interface CreateUserRequest {
email: string;
displayName: string;
password: string;
role: UserRole;
}
// UpdateUserRequest holds the request fields for updating a user
export interface UpdateUserRequest {
email?: string;
displayName?: string;
password?: string;
role?: UserRole;
}
// WorkspaceStats holds workspace statistics
export interface WorkspaceStats {
userID: number;
userEmail: string;
workspaceID: number;
workspaceName: string;
workspaceCreatedAt: string; // Using ISO string format for time.Time
fileCountStats?: FileCountStats;
}
// Define FileCountStats based on the Go struct definition of storage.FileCountStats
export interface FileCountStats {
totalFiles: number;
totalSize: number;
}
export interface UserStats {
totalUsers: number;
totalWorkspaces: number;
activeUsers: number; // Users with activity in last 30 days
}
// SystemStats holds system-wide statistics
export interface SystemStats extends FileCountStats, UserStats {}
// isSystemStats checks if the given object is a valid SystemStats object
export function isSystemStats(obj: unknown): obj is SystemStats {
return (
typeof obj === 'object' &&
obj !== null &&
'totalUsers' in obj &&
typeof (obj as SystemStats).totalUsers === 'number' &&
'totalWorkspaces' in obj &&
typeof (obj as SystemStats).totalWorkspaces === 'number' &&
'activeUsers' in obj &&
typeof (obj as SystemStats).activeUsers === 'number' &&
'totalFiles' in obj &&
typeof (obj as SystemStats).totalFiles === 'number' &&
'totalSize' in obj &&
typeof (obj as SystemStats).totalSize === 'number'
);
}

View File

@@ -30,3 +30,28 @@ export const DEFAULT_WORKSPACE: Workspace = {
name: '',
...DEFAULT_WORKSPACE_SETTINGS,
};
export function isWorkspace(obj: unknown): obj is Workspace {
return (
typeof obj === 'object' &&
obj !== null &&
'name' in obj &&
typeof (obj as Workspace).name === 'string' &&
'theme' in obj &&
typeof (obj as Workspace).theme === 'string' &&
'autoSave' in obj &&
typeof (obj as Workspace).autoSave === 'boolean' &&
'gitEnabled' in obj &&
typeof (obj as Workspace).gitEnabled === 'boolean' &&
'gitUrl' in obj &&
typeof (obj as Workspace).gitUrl === 'string' &&
'gitUser' in obj &&
typeof (obj as Workspace).gitUser === 'string' &&
'gitToken' in obj &&
typeof (obj as Workspace).gitToken === 'string' &&
'gitAutoCommit' in obj &&
typeof (obj as Workspace).gitAutoCommit === 'boolean' &&
'gitCommitMsgTemplate' in obj &&
typeof (obj as Workspace).gitCommitMsgTemplate === 'string'
);
}