mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 08:24:27 +00:00
Refactor admin API types and add validation functions for WorkspaceStats and FileCountStats
This commit is contained in:
@@ -208,12 +208,46 @@ export interface WorkspaceStats {
|
||||
fileCountStats?: FileCountStats;
|
||||
}
|
||||
|
||||
// isWorkspaceStats checks if the given object is a valid WorkspaceStats object
|
||||
export function isWorkspaceStats(obj: unknown): obj is WorkspaceStats {
|
||||
return (
|
||||
typeof obj === 'object' &&
|
||||
obj !== null &&
|
||||
'userID' in obj &&
|
||||
typeof (obj as WorkspaceStats).userID === 'number' &&
|
||||
'userEmail' in obj &&
|
||||
typeof (obj as WorkspaceStats).userEmail === 'string' &&
|
||||
'workspaceID' in obj &&
|
||||
typeof (obj as WorkspaceStats).workspaceID === 'number' &&
|
||||
'workspaceName' in obj &&
|
||||
typeof (obj as WorkspaceStats).workspaceName === 'string' &&
|
||||
'workspaceCreatedAt' in obj &&
|
||||
typeof (obj as WorkspaceStats).workspaceCreatedAt === 'string' &&
|
||||
(!('fileCountStats' in obj) ||
|
||||
(obj as WorkspaceStats).fileCountStats === undefined ||
|
||||
(obj as WorkspaceStats).fileCountStats === null ||
|
||||
isFileCountStats((obj as WorkspaceStats).fileCountStats))
|
||||
);
|
||||
}
|
||||
|
||||
// Define FileCountStats based on the Go struct definition of storage.FileCountStats
|
||||
export interface FileCountStats {
|
||||
totalFiles: number;
|
||||
totalSize: number;
|
||||
}
|
||||
|
||||
// isFileCountStats checks if the given object is a valid FileCountStats object
|
||||
export function isFileCountStats(obj: unknown): obj is FileCountStats {
|
||||
return (
|
||||
typeof obj === 'object' &&
|
||||
obj !== null &&
|
||||
'totalFiles' in obj &&
|
||||
typeof (obj as FileCountStats).totalFiles === 'number' &&
|
||||
'totalSize' in obj &&
|
||||
typeof (obj as FileCountStats).totalSize === 'number'
|
||||
);
|
||||
}
|
||||
|
||||
export interface UserStats {
|
||||
totalUsers: number;
|
||||
totalWorkspaces: number;
|
||||
|
||||
Reference in New Issue
Block a user