Skip to content

Commit edfc8bf

Browse files
committed
Review Comments
1 parent c870916 commit edfc8bf

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

Diff for: sources/packages/backend/apps/api/src/route-controllers/user/user.aest.controller.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ export class UserAESTController extends BaseController {
5454
// If the user token is missing any of the primary user information to create a user
5555
// then throw an error.
5656
if (
57-
!!userToken.userName?.trim() ||
58-
!!userToken.email?.trim() ||
59-
!!userToken.lastName?.trim()
57+
!userToken.userName?.trim() ||
58+
!userToken.email?.trim() ||
59+
!userToken.lastName?.trim()
6060
) {
6161
throw new BadRequestException(
6262
new ApiProcessError(

Diff for: sources/packages/web/src/services/UserService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class UserService {
3737
* @returns true if the user was successfully created/updated or
3838
* false if the user do not have permission to access the system.
3939
*/
40-
async syncAESTUser(authHeader?: any): Promise<boolean> {
41-
return ApiClient.User.syncAESTUser(authHeader);
40+
async syncAESTUser(): Promise<boolean> {
41+
return ApiClient.User.syncAESTUser();
4242
}
4343
}

Diff for: sources/packages/web/src/services/http/UserApi.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
MISSING_USER_ACCOUNT,
1111
MISSING_USER_INFO,
1212
} from "@/constants";
13-
import { AxiosError } from "axios";
13+
import { ApiProcessError } from "@/types";
1414

1515
export class UserApi extends HttpBaseClient {
1616
async bceidAccount(): Promise<BCeIDDetailsAPIOutDTO> {
@@ -45,30 +45,21 @@ export class UserApi extends HttpBaseClient {
4545
* @returns true if the user was successfully created/updated or
4646
* false if the user do not have permission to access the system.
4747
*/
48-
async syncAESTUser(authHeader?: any): Promise<boolean> {
48+
async syncAESTUser(): Promise<boolean> {
4949
try {
50-
await this.apiClient.put(
51-
this.addClientRoot("user"),
52-
// The data to perform the create/update
53-
// will come from the authentication token.
54-
null,
55-
authHeader ?? this.addAuthHeader(),
56-
);
50+
await this.putCall(this.addClientRoot("user"), null);
5751
return true;
5852
} catch (error: unknown) {
5953
if (
60-
error instanceof AxiosError &&
61-
(error.response?.data.errorType === MISSING_USER_ACCOUNT ||
62-
error.response?.data.errorType === MISSING_GROUP_ACCESS ||
63-
error.response?.data.errorType === MISSING_USER_INFO)
54+
error instanceof ApiProcessError &&
55+
(error.errorType === MISSING_USER_ACCOUNT ||
56+
error.errorType === MISSING_GROUP_ACCESS ||
57+
error.errorType === MISSING_USER_INFO)
6458
) {
6559
// If the user do not have a proper authorization
6660
// an HTTP error will be raised.
6761
return false;
6862
}
69-
// If it is not an expected error,
70-
// handle it the default way.
71-
this.handleRequestError(error);
7263
throw error;
7364
}
7465
}

Diff for: sources/packages/web/src/services/http/common/HttpBaseClient.ts

+15
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ export default abstract class HttpBaseClient {
134134
}
135135
}
136136

137+
/**
138+
* Executes a HTTP request using a PUT verb including the authentication token.
139+
* @param url API endpoint URI.
140+
* @param payload data to be sent.
141+
* @param suppressErrorHandler optionally skip the global error handling.
142+
*/
143+
protected async putCall<T>(url: string, payload: T): Promise<void> {
144+
try {
145+
await this.apiClient.put(url, payload, this.addAuthHeader());
146+
} catch (error: unknown) {
147+
this.handleRequestError(error);
148+
throw error;
149+
}
150+
}
151+
137152
protected handleCustomError(error: any) {
138153
if (error.response) {
139154
this.handleRequestError(error.response.data?.message);

0 commit comments

Comments
 (0)