@abcagency/hire-control-sdk 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/babel.config.json +6 -0
  2. package/constants/config.ts +1 -0
  3. package/controllers/accountsController.ts +54 -0
  4. package/controllers/authController.ts +159 -0
  5. package/controllers/clientAuthConfigController.ts +69 -0
  6. package/controllers/eventsController.ts +58 -0
  7. package/controllers/listingsController.ts +41 -0
  8. package/controllers/mapConfigController.ts +43 -0
  9. package/controllers/permissionsController.ts +17 -0
  10. package/controllers/rolesController.ts +49 -0
  11. package/controllers/usersController.ts +98 -0
  12. package/dist/constants/config.d.ts +1 -0
  13. package/dist/controllers/accountsController.d.ts +26 -0
  14. package/dist/controllers/authController.d.ts +75 -0
  15. package/dist/controllers/clientAuthConfigController.d.ts +40 -0
  16. package/dist/controllers/eventsController.d.ts +39 -0
  17. package/dist/controllers/listingsController.d.ts +19 -0
  18. package/dist/controllers/mapConfigController.d.ts +25 -0
  19. package/dist/controllers/permissionsController.d.ts +10 -0
  20. package/dist/controllers/rolesController.d.ts +33 -0
  21. package/dist/controllers/usersController.d.ts +49 -0
  22. package/dist/handlers/fetchHandler.d.ts +13 -0
  23. package/dist/index.cjs.js +2 -0
  24. package/dist/index.d.ts +110 -0
  25. package/dist/types/account/forgotPasswordRequest.d.ts +3 -0
  26. package/dist/types/account/resetPasswordRequest.d.ts +5 -0
  27. package/dist/types/account/resetPasswordWithTokenRequest.d.ts +6 -0
  28. package/dist/types/authResponse.d.ts +6 -0
  29. package/dist/types/changeCompanyRequest.d.ts +4 -0
  30. package/dist/types/clientAuthConfig.d.ts +6 -0
  31. package/dist/types/clientLoginRequest.d.ts +4 -0
  32. package/dist/types/company.d.ts +5 -0
  33. package/dist/types/controllers/listingsControllerType.d.ts +6 -0
  34. package/dist/types/controllers/usersControllerType.d.ts +11 -0
  35. package/dist/types/credentials.d.ts +5 -0
  36. package/dist/types/event.d.ts +7 -0
  37. package/dist/types/hireControlConfig.d.ts +51 -0
  38. package/dist/types/listing.d.ts +111 -0
  39. package/dist/types/refreshTokenRequest.d.ts +5 -0
  40. package/dist/types/register.d.ts +12 -0
  41. package/dist/types/role.d.ts +6 -0
  42. package/dist/types/user.d.ts +11 -0
  43. package/handlers/fetchHandler.ts +120 -0
  44. package/index.ts +93 -0
  45. package/package.json +29 -0
  46. package/tsconfig.json +22 -0
  47. package/types/account/forgotPasswordRequest.ts +3 -0
  48. package/types/account/resetPasswordRequest.ts +6 -0
  49. package/types/account/resetPasswordWithTokenRequest.ts +7 -0
  50. package/types/authResponse.ts +7 -0
  51. package/types/changeCompanyRequest.ts +5 -0
  52. package/types/clientAuthConfig.ts +9 -0
  53. package/types/clientLoginRequest.ts +5 -0
  54. package/types/company.ts +6 -0
  55. package/types/controllers/listingsControllerType.ts +11 -0
  56. package/types/controllers/usersControllerType.ts +13 -0
  57. package/types/credentials.ts +6 -0
  58. package/types/event.ts +6 -0
  59. package/types/hireControlConfig.ts +59 -0
  60. package/types/listing.ts +125 -0
  61. package/types/refreshTokenRequest.ts +6 -0
  62. package/types/register.ts +13 -0
  63. package/types/role.ts +7 -0
  64. package/types/user.ts +12 -0
@@ -0,0 +1,6 @@
1
+ {
2
+ "presets": [
3
+ ["@babel/preset-env", { "modules": false }],
4
+ "@babel/preset-typescript"
5
+ ]
6
+ }
@@ -0,0 +1 @@
1
+ export const API_URL = 'http://localhost:5108';
@@ -0,0 +1,54 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import ForgotPasswordRequest from '../types/account/forgotPasswordRequest';
3
+ import ResetPasswordWithTokenRequest from '../types/account/resetPasswordWithTokenRequest';
4
+ import ResetPasswordRequest from '../types/account/resetPasswordRequest';
5
+ import { API_URL } from '../constants/config';
6
+
7
+ const fetchHandler = new FetchHandler(API_URL);
8
+
9
+ class AccountController {
10
+ /**
11
+ * Sends a password reset link to the user's email address.
12
+ * @param {ForgotPasswordRequest} model - The email of the user.
13
+ * @returns {Promise<void>} - No return value.
14
+ */
15
+ async forgotPassword(model: ForgotPasswordRequest): Promise<void> {
16
+ try {
17
+ const response = await fetchHandler.post<ForgotPasswordRequest, void>('/account/forgotPassword', model, false);
18
+ return response;
19
+ } catch (error) {
20
+ throw error;
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Resets the password for a non-authenticated user using a token.
26
+ * @param {ResetPasswordWithTokenRequest} model - The email, token, and new password.
27
+ * @returns {Promise<void>} - No return value.
28
+ */
29
+ async resetPasswordWithToken(model: ResetPasswordWithTokenRequest): Promise<void> {
30
+ try {
31
+ const response = await fetchHandler.post<ResetPasswordWithTokenRequest, void>('/account/resetPasswordWithToken', model, false);
32
+ return response;
33
+ } catch (error) {
34
+ throw error;
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Resets the password for an authenticated user.
40
+ * @param {ResetPasswordRequest} model - The current and new password.
41
+ * @param {string | null} authToken - The authorization token.
42
+ * @returns {Promise<void>} - No return value.
43
+ */
44
+ async resetPassword(model: ResetPasswordRequest, authToken: string | null = null): Promise<void> {
45
+ try {
46
+ const response = await fetchHandler.post<ResetPasswordRequest, void>('/account/resetPassword', model, true, authToken);
47
+ return response;
48
+ } catch (error) {
49
+ throw error;
50
+ }
51
+ }
52
+ }
53
+
54
+ export default new AccountController();
@@ -0,0 +1,159 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import ClientLogInRequest from '../types/clientLoginRequest';
3
+ import Credentials from '../types/credentials';
4
+ import RefreshTokenRequest from '../types/refreshTokenRequest';
5
+ import ChangeCompanyRequest from '../types/changeCompanyRequest';
6
+ import AuthResponse from '../types/authResponse';
7
+ import Register from '../types/register';
8
+ import User from '../types/user';
9
+ import { API_URL } from '../constants/config';
10
+
11
+ const fetchHandler = new FetchHandler(API_URL);
12
+
13
+ /**
14
+ * AuthController class that handles all the authentication API calls.
15
+ */
16
+ class AuthController {
17
+ /**
18
+ * Login using client authentication key.
19
+ * @param {ClientLogInRequest} clientLogInRequest - The login request object containing the client auth key.
20
+ * @returns {Promise<any>} - The response from the server.
21
+ */
22
+ async login(clientLogInRequest: ClientLogInRequest): Promise<any> {
23
+ return fetchHandler.post<ClientLogInRequest, any>('/auth/login', clientLogInRequest, false);
24
+ }
25
+
26
+ /**
27
+ * Login for existing users with username and password.
28
+ * @param {Credentials} credentials - The credentials object containing username and password.
29
+ * @returns {Promise<any>} - The response containing the authentication token.
30
+ */
31
+ async nextLogin(credentials: Credentials): Promise<any> {
32
+ const response = await fetchHandler.post<Credentials, AuthResponse>('/auth/nextLogin', credentials, false);
33
+
34
+ // if (response) {
35
+ // sessionStorage.setItem('token', response.token);
36
+ // sessionStorage.setItem('refreshToken', response.refreshToken);
37
+ // sessionStorage.setItem('expiration', response.expiration);
38
+ // }
39
+
40
+ return response;
41
+ }
42
+
43
+ /**
44
+ * Refresh the access token using the refresh token.
45
+ * @param {RefreshTokenRequest} refreshTokenRequest - The refresh token request object containing the refresh token and companyId.
46
+ * @returns {Promise<any>} - The response with the new token.
47
+ */
48
+ async refreshToken(refreshTokenRequest: RefreshTokenRequest): Promise<any> {
49
+ const response = await fetchHandler.post<RefreshTokenRequest, AuthResponse>('/auth/refresh', refreshTokenRequest, false);
50
+
51
+ if (response) {
52
+ sessionStorage.setItem('token', response.token);
53
+ sessionStorage.setItem('refreshToken', response.refreshToken);
54
+ sessionStorage.setItem('expiration', response.expiration);
55
+ }
56
+
57
+ return response;
58
+ }
59
+
60
+ /**
61
+ * Change the company for the current authenticated user.
62
+ * @param {ChangeCompanyRequest} changeCompanyRequest - The request object containing the new company ID.
63
+ * @returns {Promise<any>} - The response from the server.
64
+ */
65
+ async changeCompany(changeCompanyRequest: ChangeCompanyRequest): Promise<any> {
66
+ return fetchHandler.post<ChangeCompanyRequest, any>('/auth/changeCompany', changeCompanyRequest, true);
67
+ }
68
+
69
+ /**
70
+ * Register a new user.
71
+ * @param {Register} register - The register request object containing user details.
72
+ * @returns {Promise<any>} - The response after registering the user.
73
+ */
74
+ async register(register: Register): Promise<any> {
75
+ return fetchHandler.post<Register, any>('/auth/register', register, false);
76
+ }
77
+
78
+ /**
79
+ * Fetch the authorized companies for the current user.
80
+ * @returns {Promise<any>} - The response containing the list of companies.
81
+ */
82
+ async getCompanies(): Promise<any> {
83
+ return fetchHandler.get<any>('/auth/companies', true); // 'true' for authenticated endpoint
84
+ }
85
+
86
+ /**
87
+ * Get the current company details for the authenticated user.
88
+ * @returns {Promise<any>} - The response containing the company name and company ID.
89
+ */
90
+ async getCompany(): Promise<any> {
91
+ return fetchHandler.get<any>('/auth/company', true); // 'true' for authenticated endpoint
92
+ }
93
+
94
+ /**
95
+ * Get the roles for the authenticated user.
96
+ * @returns {Promise<any>} - The response containing the list of roles.
97
+ */
98
+ async getRoles(): Promise<any> {
99
+ return fetchHandler.get<any>('/auth/roles', true); // 'true' for authenticated endpoint
100
+ }
101
+
102
+ /**
103
+ * Check if the user is authenticated.
104
+ * @returns {Promise<boolean>} - True if the user is authenticated, false otherwise.
105
+ */
106
+ async isAuthenticated(): Promise<boolean> {
107
+ try {
108
+ const response = await fetchHandler.get<boolean>('/auth/authenticated', true);
109
+ return response; // Return the boolean response directly from the API
110
+ } catch (error) {
111
+ return false; // Return false if there's an error (e.g., unauthorized)
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Get logged in user.
117
+ * @param {string | null} authToken - Optional auth token.
118
+ * @returns {Promise<User | null>} - The user data or null if not found.
119
+ */
120
+ async getUser(authToken: string | null = null): Promise<User | null> {
121
+ try {
122
+ const response = await fetchHandler.get<User>(`/auth/user`, true, authToken);
123
+ return response;
124
+ } catch (error) {
125
+ throw error;
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Logout the authenticated user.
131
+ * @returns {Promise<any>} - The response from the server.
132
+ */
133
+ async logout(): Promise<any> {
134
+ try {
135
+ const response = await fetchHandler.post<any, any>('/auth/logout', {}, true); // Assuming auth token is handled in fetchHandler
136
+ // Clear tokens or session storage
137
+ sessionStorage.removeItem('token');
138
+ sessionStorage.removeItem('refreshToken');
139
+ sessionStorage.removeItem('expiration');
140
+
141
+ return response;
142
+ } catch (error) {
143
+ throw error;
144
+ }
145
+ }
146
+
147
+ async getPermissions(authToken: string | null = null): Promise<string[]> {
148
+ try {
149
+ const response = await fetchHandler.get<string[]>('/auth/permissions', true, authToken);
150
+ return response;
151
+ } catch (error) {
152
+ throw error;
153
+ }
154
+ }
155
+ }
156
+
157
+
158
+
159
+ export default new AuthController();
@@ -0,0 +1,69 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import ClientAuthConfig from '../types/clientAuthConfig';
3
+ import { API_URL } from '../constants/config';
4
+
5
+ const fetchHandler = new FetchHandler(API_URL);
6
+
7
+ class ClientAuthConfigController {
8
+ /**
9
+ * Get the client auth configuration by its ID.
10
+ * @param {string} id - The ID of the client auth configuration.
11
+ * @param {string | null} authToken - Optional auth token.
12
+ * @returns {Promise<ClientAuthConfig | null>} - The client auth configuration or null if not found.
13
+ */
14
+ async getClientAuthConfigById(id: string, authToken: string | null = null): Promise<ClientAuthConfig | null> {
15
+ try {
16
+ const response = await fetchHandler.get<ClientAuthConfig>(`/clientAuthConfig/${id}`, true, authToken);
17
+ return response;
18
+ } catch (error) {
19
+ throw error;
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Get all client auth configurations.
25
+ * @param {string | null} authToken - Optional auth token.
26
+ * @returns {Promise<ClientAuthConfig[] | null>} - The list of client auth configurations or null if not found.
27
+ */
28
+ async getAllClientAuthConfigs(authToken: string | null = null): Promise<ClientAuthConfig[] | null> {
29
+ try {
30
+ const response = await fetchHandler.get<ClientAuthConfig[]>('/clientAuthConfig', true, authToken);
31
+ return response;
32
+ } catch (error) {
33
+ throw error;
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Create a new client auth configuration.
39
+ * @param {ClientAuthConfig} clientAuthConfig - The new client auth configuration to create.
40
+ * @param {string | null} authToken - Optional auth token.
41
+ * @returns {Promise<void>} - No return value.
42
+ */
43
+ async createClientAuthConfig(clientAuthConfig: ClientAuthConfig, authToken: string | null = null): Promise<void> {
44
+ return fetchHandler.post<ClientAuthConfig, void>('/clientAuthConfig', clientAuthConfig, true, authToken);
45
+ }
46
+
47
+ /**
48
+ * Update an existing client auth configuration by its ID.
49
+ * @param {string} id - The ID of the client auth configuration to update.
50
+ * @param {ClientAuthConfig} clientAuthConfig - The updated client auth configuration data.
51
+ * @param {string | null} authToken - Optional auth token.
52
+ * @returns {Promise<void>} - No return value.
53
+ */
54
+ async updateClientAuthConfig(id: string, clientAuthConfig: ClientAuthConfig, authToken: string | null = null): Promise<void> {
55
+ return fetchHandler.put<ClientAuthConfig, void>(`/clientAuthConfig/${id}`, clientAuthConfig, true, authToken);
56
+ }
57
+
58
+ /**
59
+ * Delete a client auth configuration by its ID.
60
+ * @param {string} id - The ID of the client auth configuration to delete.
61
+ * @param {string | null} authToken - Optional auth token.
62
+ * @returns {Promise<void>} - No return value.
63
+ */
64
+ async deleteClientAuthConfig(id: string, authToken: string | null = null): Promise<void> {
65
+ return fetchHandler.delete<void>(`/clientAuthConfig/${id}`, true, authToken);
66
+ }
67
+ }
68
+
69
+ export default new ClientAuthConfigController();
@@ -0,0 +1,58 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import Event from '../types/event';
3
+ import { API_URL } from '../constants/config';
4
+
5
+ const fetchHandler = new FetchHandler(API_URL);
6
+
7
+ class EventsController {
8
+ /**
9
+ * Get all events for the authenticated user’s company.
10
+ * @returns {Promise<Event[]>} - A list of events.
11
+ */
12
+ async getEvents(authToken: string | null = null): Promise<Event[]> {
13
+ return fetchHandler.get<Event[]>('/events', true, authToken);
14
+ }
15
+
16
+ /**
17
+ * Get a specific event by ID.
18
+ * @param {string} id - The event ID.
19
+ * @param {string | null} authToken - Optional auth token.
20
+ * @returns {Promise<Event>} - The event data.
21
+ */
22
+ async getEvent(id: string, authToken: string | null = null): Promise<Event> {
23
+ return fetchHandler.get<Event>(`/events/${id}`, true, authToken);
24
+ }
25
+
26
+ /**
27
+ * Create a new event (only for SuperAdmin/Admin roles).
28
+ * @param {Event} Event - The event data to create.
29
+ * @param {string | null} authToken - Optional auth token.
30
+ * @returns {Promise<Event>} - The newly created event data.
31
+ */
32
+ async createEvent(Event: any, authToken: string | null = null): Promise<any> {
33
+ return fetchHandler.post<any, any>('/events', Event, true, authToken);
34
+ }
35
+
36
+ /**
37
+ * Update an existing event (only for SuperAdmin/Admin roles).
38
+ * @param {string} id - The event ID to update.
39
+ * @param {Event} Event - The updated event data.
40
+ * @param {string | null} authToken - Optional auth token.
41
+ * @returns {Promise<void>} - No return value.
42
+ */
43
+ async updateEvent(id: string, Event: Event, authToken: string | null = null): Promise<void> {
44
+ return fetchHandler.put<Event, void>(`/events/${id}`, Event, true, authToken);
45
+ }
46
+
47
+ /**
48
+ * Delete an existing event (only for SuperAdmin/Admin roles).
49
+ * @param {string} id - The event ID to delete.
50
+ * @param {string | null} authToken - Optional auth token.
51
+ * @returns {Promise<void>} - No return value.
52
+ */
53
+ async deleteEvent(id: string, authToken: string | null = null): Promise<void> {
54
+ return fetchHandler.delete(`/events/${id}`, true, authToken);
55
+ }
56
+ }
57
+
58
+ export default new EventsController();
@@ -0,0 +1,41 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import { Listing } from '../types/listing';
3
+ import { API_URL } from '../constants/config';
4
+ import ListingsControllerType from '../types/controllers/listingsControllerType';
5
+
6
+ const fetchHandler = new FetchHandler(API_URL);
7
+
8
+ class ListingsController implements ListingsControllerType {
9
+ /**
10
+ * Get all listings with optional filters.
11
+ * @param {string | null} authToken - Optional auth token.
12
+ * @returns {Promise<Listing[]>} - A list of filtered listings.
13
+ */
14
+ async getListings(
15
+ authToken: string | null = null
16
+ ): Promise<Listing[]> {
17
+ try {
18
+ const response = await fetchHandler.get<Listing[]>('/listings', true, authToken);
19
+ return response;
20
+ } catch (error) {
21
+ throw error;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Get the details of a specific listing.
27
+ * @param {number} listingId - The ID of the listing to retrieve.
28
+ * @param {string | null} authToken - Optional auth token.
29
+ * @returns {Promise<Listing | null>} - The listing details or null if not found.
30
+ */
31
+ async getListingDetails(listingId: number, authToken: string | null = null): Promise<Listing | null> {
32
+ try {
33
+ const response = await fetchHandler.get<Listing>(`/listings/${listingId}`, true, authToken);
34
+ return response;
35
+ } catch (error) {
36
+ throw error;
37
+ }
38
+ }
39
+ }
40
+
41
+ export default new ListingsController();
@@ -0,0 +1,43 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import HireControlConfig from '../types/hireControlConfig';
3
+ import { API_URL } from '../constants/config';
4
+
5
+ const fetchHandler = new FetchHandler(API_URL);
6
+
7
+ class MapConfigController {
8
+ /**
9
+ * Get the map configuration for the current company.
10
+ * @param {string | null} authToken - Optional auth token.
11
+ * @returns {Promise<HireControlConfig | null>} - The map configuration or null if not found.
12
+ */
13
+ async getMapConfig(authToken: string | null = null): Promise<HireControlConfig | null> {
14
+ try {
15
+ const response = await fetchHandler.get<HireControlConfig>('/mapconfig', true, authToken);
16
+ return response;
17
+ } catch (error) {
18
+ throw error;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Update the map configuration for the current company.
24
+ * @param {HireControlConfig} hireControlConfig - The new map configuration data.
25
+ * @param {string | null} authToken - Optional auth token.
26
+ * @returns {Promise<void>} - No return value.
27
+ */
28
+ async updateMapConfig(hireControlConfig: HireControlConfig, authToken: string | null = null): Promise<void> {
29
+ return fetchHandler.put<HireControlConfig, void>('/mapconfig', hireControlConfig, true, authToken);
30
+ }
31
+
32
+ /**
33
+ * Create a new map configuration for the current company.
34
+ * @param {HireControlConfig} hireControlConfig - The new map configuration to create.
35
+ * @param {string | null} authToken - Optional auth token.
36
+ * @returns {Promise<void>} - No return value.
37
+ */
38
+ async createMapConfig(hireControlConfig: HireControlConfig, authToken: string | null = null): Promise<void> {
39
+ return fetchHandler.post<HireControlConfig, void>('/mapconfig', hireControlConfig, true, authToken);
40
+ }
41
+ }
42
+
43
+ export default new MapConfigController();
@@ -0,0 +1,17 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import { API_URL } from '../constants/config';
3
+
4
+ const fetchHandler = new FetchHandler(API_URL);
5
+
6
+ class PermissionsController {
7
+ /**
8
+ * Get all available permissions.
9
+ * @param {string | null} authToken - Optional auth token.
10
+ * @returns {Promise<string[]>} - A list of available permissions.
11
+ */
12
+ async getAllPermissions(authToken: string | null = null): Promise<string[]> {
13
+ return fetchHandler.get<string[]>('/permissions', true, authToken);
14
+ }
15
+ }
16
+
17
+ export default new PermissionsController();
@@ -0,0 +1,49 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import RoleRequest from '../types/role';
3
+ import { API_URL } from '../constants/config';
4
+
5
+ const fetchHandler = new FetchHandler(API_URL);
6
+
7
+ class RolesController {
8
+ /**
9
+ * Get all roles with claims for the authenticated user’s company.
10
+ * @param {string | null} authToken - Optional auth token.
11
+ * @returns {Promise<any[]>} - A list of roles with claims.
12
+ */
13
+ async getAllRolesWithClaims(authToken: string | null = null): Promise<any[]> {
14
+ return fetchHandler.get<any[]>('/roles', true, authToken);
15
+ }
16
+
17
+ /**
18
+ * Create a new role and optionally assign claims to it.
19
+ * @param {RoleRequest} roleRequest - The data to create the role.
20
+ * @param {string | null} authToken - Optional auth token.
21
+ * @returns {Promise<void>} - No return value.
22
+ */
23
+ async addRole(roleRequest: RoleRequest, authToken: string | null = null): Promise<void> {
24
+ return fetchHandler.post<RoleRequest, void>('/roles', roleRequest, true, authToken);
25
+ }
26
+
27
+ /**
28
+ * Update an existing role by ID.
29
+ * @param {string} roleId - The role ID.
30
+ * @param {RoleRequest} roleRequest - The updated role data.
31
+ * @param {string | null} authToken - Optional auth token.
32
+ * @returns {Promise<void>} - No return value.
33
+ */
34
+ async updateRole(roleId: string, roleRequest: RoleRequest, authToken: string | null = null): Promise<void> {
35
+ return fetchHandler.put<RoleRequest, void>(`/roles/${roleId}`, roleRequest, true, authToken);
36
+ }
37
+
38
+ /**
39
+ * Delete an existing role by ID.
40
+ * @param {string} roleId - The role ID.
41
+ * @param {string | null} authToken - Optional auth token.
42
+ * @returns {Promise<void>} - No return value.
43
+ */
44
+ async deleteRole(roleId: string, authToken: string | null = null): Promise<void> {
45
+ return fetchHandler.delete<void>(`/roles/${roleId}`, true, authToken);
46
+ }
47
+ }
48
+
49
+ export default new RolesController();
@@ -0,0 +1,98 @@
1
+ import FetchHandler from '../handlers/fetchHandler';
2
+ import User from '../types/user';
3
+ import Register from '../types/register';
4
+ import { API_URL } from '../constants/config';
5
+ import UsersControllerType from '../types/controllers/usersControllerType';
6
+
7
+ const fetchHandler = new FetchHandler(API_URL);
8
+
9
+ class UsersController implements UsersControllerType {
10
+ /**
11
+ * Get all users in the system.
12
+ * @param {string | null} authToken - Optional auth token.
13
+ * @returns {Promise<User[]>} - The list of users with roles and permissions.
14
+ */
15
+ async getAllUsers(authToken: string | null = null): Promise<User[]> {
16
+ try {
17
+ const response = await fetchHandler.get<User[]>('/users', true, authToken);
18
+ return response;
19
+ } catch (error) {
20
+ throw error;
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Get a single user by ID.
26
+ * @param {string} id - The ID of the user to retrieve.
27
+ * @param {string | null} authToken - Optional auth token.
28
+ * @returns {Promise<User | null>} - The user data or null if not found.
29
+ */
30
+ async getUser(id: string, authToken: string | null = null): Promise<User | null> {
31
+ try {
32
+ const response = await fetchHandler.get<User>(`/users/${id}`, true, authToken);
33
+ return response;
34
+ } catch (error) {
35
+ throw error;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Create a new user in the system.
41
+ * @param {Register} Register - The data for creating a new user.
42
+ * @param {string | null} authToken - Optional auth token.
43
+ * @returns {Promise<User | null>} - The created user data or null if creation fails.
44
+ */
45
+ async createUser(Register: Register, authToken: string | null = null): Promise<User | null> {
46
+ try {
47
+ const response = await fetchHandler.post<Register, User>('/users', Register, true, authToken);
48
+ return response;
49
+ } catch (error) {
50
+ throw error;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Update an existing user by ID.
56
+ * @param {string} id - The ID of the user to update.
57
+ * @param {Register} Register - The updated user data.
58
+ * @param {string | null} authToken - Optional auth token.
59
+ * @returns {Promise<void>} - No return value.
60
+ */
61
+ async updateUser(id: string, Register: Register, authToken: string | null = null): Promise<void> {
62
+ try {
63
+ await fetchHandler.put<Register, void>(`/users/${id}`, Register, true, authToken);
64
+ } catch (error) {
65
+ throw error;
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Update a loggedIn user.
71
+ * @param {Register} Register - The updated user data.
72
+ * @param {string | null} authToken - Optional auth token.
73
+ * @returns {Promise<void>} - No return value.
74
+ */
75
+ async updateLoggedInUser(Register: Register, authToken: string | null = null): Promise<void> {
76
+ try {
77
+ await fetchHandler.put<Register, void>(`/users`, Register, true, authToken);
78
+ } catch (error) {
79
+ throw error;
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Delete a user by ID.
85
+ * @param {string} id - The ID of the user to delete.
86
+ * @param {string | null} authToken - Optional auth token.
87
+ * @returns {Promise<void>} - No return value.
88
+ */
89
+ async deleteUser(id: string, authToken: string | null = null): Promise<void> {
90
+ try {
91
+ await fetchHandler.delete<void>(`/users/${id}`, true, authToken);
92
+ } catch (error) {
93
+ throw error;
94
+ }
95
+ }
96
+ }
97
+
98
+ export default new UsersController();
@@ -0,0 +1 @@
1
+ export declare const API_URL = "http://localhost:5108";
@@ -0,0 +1,26 @@
1
+ import ForgotPasswordRequest from '../types/account/forgotPasswordRequest';
2
+ import ResetPasswordWithTokenRequest from '../types/account/resetPasswordWithTokenRequest';
3
+ import ResetPasswordRequest from '../types/account/resetPasswordRequest';
4
+ declare class AccountController {
5
+ /**
6
+ * Sends a password reset link to the user's email address.
7
+ * @param {ForgotPasswordRequest} model - The email of the user.
8
+ * @returns {Promise<void>} - No return value.
9
+ */
10
+ forgotPassword(model: ForgotPasswordRequest): Promise<void>;
11
+ /**
12
+ * Resets the password for a non-authenticated user using a token.
13
+ * @param {ResetPasswordWithTokenRequest} model - The email, token, and new password.
14
+ * @returns {Promise<void>} - No return value.
15
+ */
16
+ resetPasswordWithToken(model: ResetPasswordWithTokenRequest): Promise<void>;
17
+ /**
18
+ * Resets the password for an authenticated user.
19
+ * @param {ResetPasswordRequest} model - The current and new password.
20
+ * @param {string | null} authToken - The authorization token.
21
+ * @returns {Promise<void>} - No return value.
22
+ */
23
+ resetPassword(model: ResetPasswordRequest, authToken?: string | null): Promise<void>;
24
+ }
25
+ declare const _default: AccountController;
26
+ export default _default;