-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSCKAN-323 feat: Update origins changes
- Loading branch information
1 parent
7186834
commit caf19d8
Showing
7 changed files
with
71 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import statementService from "../services/StatementService"; | ||
import {userProfile} from "../services/UserService"; | ||
|
||
export const checkOwnership = ( | ||
id: number, | ||
onSave: (fetchedData: any, userId: number) => Promise<any>, | ||
onCancel: (fetchedData: any, userId: number) => void, | ||
alertMessage: (owner: any) => string | ||
) => { | ||
const userId = userProfile.getUser().id; | ||
// Fetch the latest data to check for ownership | ||
statementService.getObject(id.toString()) | ||
.then((fetchedData: any) => { | ||
// Check if the fetched data has an owner and if the current user is not the owner | ||
if (fetchedData.owner && fetchedData.owner.id !== userProfile.getUser().id) { | ||
const userConfirmed = window.confirm(alertMessage(fetchedData.owner)); | ||
|
||
if (userConfirmed) { | ||
|
||
// Reassign ownership and save the data | ||
statementService.assignOwner(fetchedData.id, { | ||
...fetchedData, | ||
owner_id: userId, // Assign ownership to the current user | ||
}) | ||
.then(() => { | ||
// Call the merged save action | ||
return onSave(fetchedData, userId) | ||
}) | ||
.catch((error) => { | ||
console.error("Failed to reassign ownership", error); | ||
onCancel(fetchedData, userId); | ||
}); | ||
} else { | ||
onCancel(fetchedData, userId); | ||
} | ||
} | ||
}) | ||
.catch((fetchError) => { | ||
console.error("Failed to fetch the data", fetchError); | ||
onCancel(null, userId); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters