Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
132 lines
3.8 KiB
TypeScript
132 lines
3.8 KiB
TypeScript
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
|
import { getWebsiteServerEnv } from '@/lib/config/env';
|
|
import { Result } from '@/lib/contracts/Result';
|
|
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
|
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
|
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
|
import type { DashboardStatsResponseDTO } from '@/lib/types/generated/DashboardStatsResponseDTO';
|
|
import type { UserDto, UserListResponse } from '@/lib/types/admin';
|
|
import { injectable } from 'inversify';
|
|
|
|
/**
|
|
* Admin Service - DTO Only
|
|
*
|
|
* Returns raw API DTOs. No ViewModels or UX logic.
|
|
* All client-side presentation logic must be handled by presenters/templates.
|
|
* @server-safe
|
|
*/
|
|
@injectable()
|
|
export class AdminService implements Service {
|
|
|
|
constructor() {
|
|
const baseUrl = getWebsiteApiBaseUrl();
|
|
const logger = new ConsoleLogger();
|
|
const { NODE_ENV } = getWebsiteServerEnv();
|
|
const errorReporter = new EnhancedErrorReporter(logger, {
|
|
showUserNotifications: false,
|
|
logToConsole: true,
|
|
reportToExternal: NODE_ENV === 'production',
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get dashboard statistics
|
|
*/
|
|
async getDashboardStats(): Promise<Result<DashboardStatsResponseDTO, DomainError>> {
|
|
// Mock data until API is implemented
|
|
const mockStats: DashboardStatsResponseDTO = {
|
|
totalUsers: 1250,
|
|
activeUsers: 1100,
|
|
suspendedUsers: 50,
|
|
deletedUsers: 100,
|
|
systemAdmins: 5,
|
|
recentLogins: 450,
|
|
newUsersToday: 12,
|
|
userGrowth: {},
|
|
roleDistribution: {},
|
|
statusDistribution: {
|
|
active: 1100,
|
|
suspended: 50,
|
|
deleted: 100,
|
|
},
|
|
activityTimeline: {},
|
|
label: 'Growth',
|
|
value: 45,
|
|
color: '#10b981',
|
|
active: 1100,
|
|
suspended: 50,
|
|
deleted: 100,
|
|
date: '2024-01-01',
|
|
newUsers: 10,
|
|
logins: 200,
|
|
};
|
|
return Result.ok(mockStats);
|
|
}
|
|
|
|
/**
|
|
* List users with filtering and pagination
|
|
*/
|
|
async listUsers(): Promise<Result<UserListResponse, DomainError>> {
|
|
// Mock data until API is implemented
|
|
const mockUsers: UserDto[] = [
|
|
{
|
|
id: '1',
|
|
email: 'admin@example.com',
|
|
displayName: 'Admin User',
|
|
roles: ['owner', 'admin'],
|
|
status: 'active',
|
|
isSystemAdmin: true,
|
|
createdAt: '2024-01-01T00:00:00.000Z',
|
|
updatedAt: '2024-01-01T00:00:00.000Z',
|
|
lastLoginAt: '2024-01-15T10:00:00.000Z',
|
|
primaryDriverId: 'driver-1',
|
|
},
|
|
{
|
|
id: '2',
|
|
email: 'user@example.com',
|
|
displayName: 'Regular User',
|
|
roles: ['user'],
|
|
status: 'active',
|
|
isSystemAdmin: false,
|
|
createdAt: '2024-01-02T00:00:00.000Z',
|
|
updatedAt: '2024-01-02T00:00:00.000Z',
|
|
lastLoginAt: '2024-01-14T15:00:00.000Z',
|
|
},
|
|
];
|
|
|
|
const mockResponse: UserListResponse = {
|
|
users: mockUsers,
|
|
total: 2,
|
|
page: 1,
|
|
limit: 50,
|
|
totalPages: 1,
|
|
};
|
|
|
|
return Result.ok(mockResponse);
|
|
}
|
|
|
|
/**
|
|
* Update user status
|
|
*/
|
|
async updateUserStatus(userId: string, status: string): Promise<Result<UserDto, DomainError>> {
|
|
// Mock success until API is implemented
|
|
return Result.ok({
|
|
id: userId,
|
|
email: 'mock@example.com',
|
|
displayName: 'Mock User',
|
|
roles: ['user'],
|
|
status,
|
|
isSystemAdmin: false,
|
|
createdAt: '2024-01-01T00:00:00.000Z',
|
|
updatedAt: '2024-01-01T00:00:00.000Z',
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Delete a user (soft delete)
|
|
*/
|
|
async deleteUser(): Promise<Result<void, DomainError>> {
|
|
// Mock success until API is implemented
|
|
return Result.ok(undefined);
|
|
}
|
|
} |