Skip to content

Commit

Permalink
[IOPID-1052] Align backend to UpdateProfile (Return 412 error on emai…
Browse files Browse the repository at this point in the history
…l already taken) (#1083)

* return precondition failed in update profile

* [#IOPID-1052] bump fn-app-sdk package

---------

Co-authored-by: arcogabbo <arcogabbo@gmail.com>
  • Loading branch information
lucacavallaro and arcogabbo authored Dec 19, 2023
1 parent b047af0 commit e7c77d8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@pagopa/io-functions-commons": "28.9.0",
"@pagopa/io-functions-eucovidcerts-sdk": "x",
"@pagopa/io-spid-commons": "^13.3.0",
"@pagopa/ts-commons": "^12.3.0",
"@pagopa/ts-commons": "^12.4.0",
"@pagopa/winston-ts": "^2.2.0",
"applicationinsights": "^1.8.10",
"body-parser": "^1.19.2",
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/profileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IResponseErrorConflict,
IResponseErrorInternal,
IResponseErrorNotFound,
IResponseErrorPreconditionFailed,
IResponseErrorTooManyRequests,
IResponseErrorValidation,
IResponseSuccessAccepted,
Expand Down Expand Up @@ -76,6 +77,7 @@ export default class ProfileController {
| IResponseErrorInternal
| IResponseErrorConflict
| IResponseErrorTooManyRequests
| IResponseErrorPreconditionFailed
| IResponseSuccessJson<InitializedProfile>
> =>
withUserFromRequest(req, async (user) =>
Expand Down
36 changes: 24 additions & 12 deletions src/services/profileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
IResponseErrorConflict,
IResponseErrorInternal,
IResponseErrorNotFound,
IResponseErrorPreconditionFailed,
IResponseErrorTooManyRequests,
IResponseSuccessAccepted,
IResponseSuccessJson,
ResponseErrorConflict,
ResponseErrorInternal,
ResponseErrorNotFound,
ResponseErrorPreconditionFailed,
ResponseErrorTooManyRequests,
ResponseSuccessAccepted,
ResponseSuccessJson,
Expand Down Expand Up @@ -174,6 +176,7 @@ export default class ProfileService {
| IResponseErrorNotFound
| IResponseErrorConflict
| IResponseErrorTooManyRequests
| IResponseErrorPreconditionFailed
| IResponseSuccessJson<InitializedProfile>
> => {
const client = this.apiClient.getClient();
Expand All @@ -189,19 +192,28 @@ export default class ProfileService {
fiscal_code: user.fiscal_code,
});

return withValidatedOrInternalError(validated, (response) =>
response.status === 200
? ResponseSuccessJson(toInitializedProfile(response.value, user))
: response.status === 404
? ResponseErrorNotFound("Not found", "User not found")
: response.status === 409
? ResponseErrorConflict(
return withValidatedOrInternalError(validated, (response) => {
switch (response.status) {
case 200:
return ResponseSuccessJson(
toInitializedProfile(response.value, user)
);
case 404:
return ResponseErrorNotFound("Not found", "User not found");
case 409:
return ResponseErrorConflict(
response.value || "Cannot update profile with wrong version"
)
: response.status === 429
? ResponseErrorTooManyRequests()
: unhandledResponseStatus(response.status)
);
);
case 412:
return ResponseErrorPreconditionFailed(
"The provided e-mail address is not unique"
);
case 429:
return ResponseErrorTooManyRequests();
default:
return unhandledResponseStatus(response.status);
}
});
})
);
};
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,9 @@
prettier "^2.6.2"

"@pagopa/io-functions-app-sdk@x":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@pagopa/io-functions-app-sdk/-/io-functions-app-sdk-5.6.0.tgz#fb32f1127bc1c52bce365a5c900cc38c5f665563"
integrity sha512-dXPvUp66aqF53XXBl30SnMgxgA/fdZAbC9oEHyQsWXaqjoCWgoGN2i5218zbXwfCFO/VB2NJddgqgioEtJVGOQ==
version "5.7.0"
resolved "https://registry.yarnpkg.com/@pagopa/io-functions-app-sdk/-/io-functions-app-sdk-5.7.0.tgz#3493b0730a1fa71ee75ffb95db71408fb626e481"
integrity sha512-KJ3OGiMP0+qUP/JIcxxb6fImtOJap3tIAncvp3Wh6Wn/ZRo0LPaDOq1ea4vbICcPZ6RjePlwL5Rovdy3mx26Tg==
dependencies:
"@pagopa/ts-commons" "^10.0.0"
fp-ts "^2.10.5"
Expand Down Expand Up @@ -1123,10 +1123,10 @@
semver "^7.3.7"
validator "^13.7.0"

"@pagopa/ts-commons@^12.3.0":
version "12.3.0"
resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-12.3.0.tgz#54e661b71ef3b80e9a8474ba90088ffafb2c06c0"
integrity sha512-7fwd2EEhac6bmmfGdWYr5EGRjF1AwzaH3DHyg/jLcoKnQcHPWbt7tsvO0zSD/mxAbHZBrZ24zut0IK3eD3qNag==
"@pagopa/ts-commons@^12.4.0":
version "12.4.0"
resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-12.4.0.tgz#58b46bd485ff0be7649cf662d9ebf0be38d8a6ff"
integrity sha512-eFDjCHmwepYPAR1+Hnm0BbXploOquZ20mnu0kKAmwLGE9Grr6WAPbjmf/5bheNWPDeD5rGUTv8ENoB2KJWOGbw==
dependencies:
abort-controller "^3.0.0"
agentkeepalive "^4.1.4"
Expand Down

0 comments on commit e7c77d8

Please sign in to comment.