xpeditis2.0/apps/frontend/lib/api/users.ts
David 08787c89c8
Some checks failed
Dev CI / Unit Tests (${{ matrix.app }}) (backend) (push) Blocked by required conditions
Dev CI / Unit Tests (${{ matrix.app }}) (frontend) (push) Blocked by required conditions
Dev CI / Notify Failure (push) Blocked by required conditions
Dev CI / Quality (${{ matrix.app }}) (backend) (push) Has been cancelled
Dev CI / Quality (${{ matrix.app }}) (frontend) (push) Has been cancelled
chore: sync full codebase from cicd branch
Aligns dev with the complete application codebase (cicd branch).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 12:56:16 +02:00

110 lines
2.3 KiB
TypeScript

/**
* Users API
*
* User management API calls
*/
import { apiClient } from './client';
export interface User {
id: string;
organizationId: string;
email: string;
firstName: string;
lastName: string;
role: 'admin' | 'manager' | 'user' | 'viewer';
phoneNumber?: string;
isEmailVerified: boolean;
isActive: boolean;
lastLoginAt?: string;
createdAt: string;
updatedAt: string;
}
export interface CreateUserRequest {
organizationId: string;
email: string;
firstName: string;
lastName: string;
role: 'admin' | 'manager' | 'user' | 'viewer';
phoneNumber?: string;
password?: string;
}
export interface UpdateUserRequest {
firstName?: string;
lastName?: string;
phoneNumber?: string;
isActive?: boolean;
}
export interface ChangePasswordRequest {
currentPassword: string;
newPassword: string;
}
export const usersApi = {
/**
* Get users in current organization
*/
async list(): Promise<User[]> {
return apiClient.get<User[]>('/api/v1/users');
},
/**
* Get user by ID
*/
async getById(id: string): Promise<User> {
return apiClient.get<User>(`/api/v1/users/${id}`);
},
/**
* Create/invite user
*/
async create(data: CreateUserRequest): Promise<User> {
return apiClient.post<User>('/api/v1/users', data);
},
/**
* Update user
*/
async update(id: string, data: UpdateUserRequest): Promise<User> {
return apiClient.patch<User>(`/api/v1/users/${id}`, data);
},
/**
* Change user role
*/
async changeRole(id: string, role: 'admin' | 'manager' | 'user' | 'viewer'): Promise<User> {
return apiClient.patch<User>(`/api/v1/users/${id}/role`, { role });
},
/**
* Deactivate user
*/
async deactivate(id: string): Promise<void> {
return apiClient.patch<void>(`/api/v1/users/${id}`, { isActive: false });
},
/**
* Activate user
*/
async activate(id: string): Promise<void> {
return apiClient.patch<void>(`/api/v1/users/${id}`, { isActive: true });
},
/**
* Delete user
*/
async delete(id: string): Promise<void> {
return apiClient.delete<void>(`/api/v1/users/${id}`);
},
/**
* Change password
*/
async changePassword(data: ChangePasswordRequest): Promise<{ message: string }> {
return apiClient.patch<{ message: string }>('/api/v1/users/me/password', data);
},
};