Changes callApiPutAsync to return a success flag alongside the response data

This commit is contained in:
BinaryAlley committed 2026-08-12 08:14:50 -07:00
1 parent d78e553fe2
commit 95be37602a
3 files changed
+8 -7

No files matched your search

@@ -121,8 +121,8 @@
.map(checkbox => checkbox.value)
};
const data = await callApiPutAsync('@_urlService.GetAbsoluteUrl("UpdateUserAuthorization", "Admin")', formData);
if (data)
const result = await callApiPutAsync('@_urlService.GetAbsoluteUrl("UpdateUserAuthorization", "Admin")', formData);
if (result.success)
notificationService.show('@_localizer["UserAuthorizationUpdated"]', NotificationType.SUCCESS);
}
@@ -103,10 +103,10 @@
const isRoleSelected = formData.roleId !== '';
const data = isRoleSelected ?
const result = isRoleSelected ?
await callApiPutAsync('@_urlService.GetAbsoluteUrl("UpdateRole", "Admin")', formData) :
await callApiPostAsync('@_urlService.GetAbsoluteUrl("CreateRole", "Admin")', formData);
if (data) {
{ success: (await callApiPostAsync('@_urlService.GetAbsoluteUrl("CreateRole", "Admin")', formData)) !== undefined };
if (result.success) {
await fetchRolesAsync();
notificationService.show(isRoleSelected ? '@_localizer["RoleUpdated"]' : '@_localizer["RoleCreated"]', NotificationType.SUCCESS);
}
@@ -109,7 +109,7 @@ async function callApiPostAsync(url, data, options = {}) {
* @param {Object} [options] - Additional options for the request.
* @param {boolean} [options.useAntiForgery=true] - Whether to include anti-forgery token.
* @param {Object} [options.headers] - Additional headers to include.
* @returns {Promise<any>} The response data if successful, undefined otherwise.
* @returns {Promise<{success: boolean, data: any}>} The result of the request, containing the success flag and the response data.
*/
async function callApiPutAsync(url, data, options = {}) {
const defaultOptions = {
@@ -146,7 +146,7 @@ async function callApiPutAsync(url, data, options = {}) {
if (jsonResponse.success) {
if (jsonResponse.message)
notificationService.show(jsonResponse.message, NotificationType.SUCCESS);
return jsonResponse.data;
return { success: jsonResponse.success === true, data: jsonResponse.data };
}
else
notificationService.show(jsonResponse.errorMessage, NotificationType.ERROR);
@@ -155,6 +155,7 @@ async function callApiPutAsync(url, data, options = {}) {
console.error('Error:', error);
notificationService.show(error, NotificationType.ERROR);
}
return { success: false };
}
/**