mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 08:24:27 +00:00
Migrate admin API to typescript
This commit is contained in:
60
app/src/types/adminApi.ts
Normal file
60
app/src/types/adminApi.ts
Normal 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'
|
||||
);
|
||||
}
|
||||
@@ -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'
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user