UNPKG

@dbs-portal/module-identity

Version:

Identity management module for user and role management

122 lines 3.27 kB
/** * User management service */ import { HttpClient } from '@dbs-portal/core-api'; export class UserService { httpClient; constructor() { this.httpClient = new HttpClient({ baseURL: '/api/identity/users' }); } /** * Get paginated list of users */ async getUsers(filters = {}) { const response = await this.httpClient.get('/', { params: filters }); return response.data; } /** * Get user by ID */ async getUser(id) { const response = await this.httpClient.get(`/${id}`); return response.data; } /** * Create new user */ async createUser(user) { const response = await this.httpClient.post('/', user); return response.data; } /** * Update existing user */ async updateUser(user) { const { id, ...updateData } = user; const response = await this.httpClient.put(`/${id}`, updateData); return response.data; } /** * Delete user */ async deleteUser(id) { await this.httpClient.delete(`/${id}`); } /** * Change user password */ async changePassword(request) { const { userId, ...passwordData } = request; await this.httpClient.post(`/${userId}/change-password`, passwordData); } /** * Lock user account */ async lockUser(request) { const { userId, ...lockData } = request; await this.httpClient.post(`/${userId}/lock`, lockData); } /** * Unlock user account */ async unlockUser(userId) { await this.httpClient.post(`/${userId}/unlock`); } /** * Setup two-factor authentication for user */ async setupTwoFactor(userId) { const response = await this.httpClient.post(`/${userId}/two-factor/setup`); return response.data; } /** * Verify two-factor authentication setup */ async verifyTwoFactor(request) { const { userId, ...verifyData } = request; await this.httpClient.post(`/${userId}/two-factor/verify`, verifyData); } /** * Disable two-factor authentication */ async disableTwoFactor(userId) { await this.httpClient.post(`/${userId}/two-factor/disable`); } /** * Get user roles */ async getUserRoles(userId) { const response = await this.httpClient.get(`/${userId}/roles`); return response.data; } /** * Assign roles to user */ async assignRoles(userId, roleNames) { await this.httpClient.post(`/${userId}/roles`, { roleNames }); } /** * Get user permissions */ async getUserPermissions(userId) { const response = await this.httpClient.get(`/${userId}/permissions`); return response.data; } /** * Grant permission to user */ async grantPermission(userId, permissionName) { await this.httpClient.post(`/${userId}/permissions/${permissionName}`); } /** * Revoke permission from user */ async revokePermission(userId, permissionName) { await this.httpClient.delete(`/${userId}/permissions/${permissionName}`); } } //# sourceMappingURL=user-service.js.map