User API
Endpoints for user profile, preferences, activity, and statistics.
User API
The User API provides endpoints for managing user profiles, preferences, activity tracking, and user-related statistics.
Endpoints
Get User Profile
GET /api/user/profile
Query Parameters:
- counts (boolean, optional) — Include activity counts
Response:
{
"data": {
"id": "user_123",
"name": "John Doe",
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"image": "https://example.com/avatar.jpg",
"role": "ADMIN",
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z",
"preferences": {"theme": "dark", "notifications": true, "timezone": "UTC"},
"counts": {"projects": 5, "tickets": 23, "comments": 45}
}
}
Update User Profile
PUT /api/user/profile
Request Body:
{
"name": "John Doe",
"firstName": "John",
"lastName": "Doe",
"image": "https://example.com/new-avatar.jpg"
}
Response:
{
"data": {
"id": "user_123",
"name": "John Doe",
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"image": "https://example.com/new-avatar.jpg",
"updatedAt": "2024-01-01T00:00:00Z"
}
}
Get User Activity
GET /api/user/activity
Query Parameters:
- page (number) — default 1
- limit (number) — default 20, max 100
- type (string) —
ticket
,project
,comment
Response:
{
"data": [
{
"id": "activity_123",
"type": "ticket",
"action": "created",
"entityId": "ticket_456",
"entityTitle": "Fix login bug",
"description": "Created ticket: Fix login bug",
"createdAt": "2024-01-01T00:00:00Z",
"metadata": {"projectId": "project_789", "projectName": "Web App"}
}
],
"pagination": {"page": 1, "limit": 20, "total": 150, "totalPages": 8}
}
Update User Preferences
PUT /api/user/preferences
Request Body:
{
"theme": "dark",
"notifications": true,
"timezone": "America/New_York",
"language": "en",
"emailNotifications": {
"ticketAssigned": true,
"ticketUpdated": false,
"projectInvites": true
}
}
Response:
{
"data": {
"id": "pref_123",
"userId": "user_123",
"theme": "dark",
"notifications": true,
"timezone": "America/New_York",
"language": "en",
"emailNotifications": {"ticketAssigned": true, "ticketUpdated": false, "projectInvites": true},
"updatedAt": "2024-01-01T00:00:00Z"
}
}
Get User Statistics
GET /api/user/stats
Query Parameters:
- period (string) —
week
,month
,quarter
,year
(defaultmonth
)
Response:
{
"data": {
"period": "month",
"startDate": "2024-01-01T00:00:00Z",
"endDate": "2024-01-31T23:59:59Z",
"tickets": {"created": 15, "completed": 12, "assigned": 8, "overdue": 2},
"projects": {"owned": 3, "member": 7, "active": 5},
"activity": {"comments": 45, "commits": 23, "reviews": 8},
"productivity": {"averageCompletionTime": "2.5 days", "completionRate": 0.8, "activeHours": 120}
}
}
Data Models
interface UserProfile { id: string; name?: string; firstName?: string; lastName?: string; email?: string; image?: string; role: 'ADMIN' | 'USER' | 'VIEWER'; createdAt: Date; updatedAt: Date; preferences?: UserPreferences; counts?: UserCounts }
interface UserPreferences { id: string; userId: string; theme?: 'light' | 'dark' | 'system'; notifications?: boolean; timezone?: string; language?: string; emailNotifications?: { ticketAssigned?: boolean; ticketUpdated?: boolean; projectInvites?: boolean; weeklyDigest?: boolean }; createdAt: Date; updatedAt: Date }
interface UserActivity { id: string; type: 'ticket' | 'project' | 'comment' | 'review'; action: string; entityId: string; entityTitle?: string; description: string; createdAt: Date; metadata?: Record<string, unknown> }
interface UserStats { period: 'week' | 'month' | 'quarter' | 'year'; startDate: Date; endDate: Date; tickets: { created: number; completed: number; assigned: number; overdue: number }; projects: { owned: number; member: number; active: number }; activity: { comments: number; commits: number; reviews: number }; productivity: { averageCompletionTime: string; completionRate: number; activeHours: number } }
Error Responses
{"error": {"code": "UNAUTHORIZED", "message": "Authentication required"}}
Examples
curl -X GET "https://codimir.com/api/user/profile?counts=true" -H "Cookie: next-auth.session-token=..."
curl -X PUT "https://codimir.com/api/user/preferences" -H "Content-Type: application/json" -H "Cookie: next-auth.session-token=..." -d '{"theme":"dark","notifications":true,"timezone":"America/New_York"}'