feat(api): Enhance study creation and user management with improved error handling and logging

- Updated the study creation endpoint to return JSON responses for errors and success.
- Added user existence verification before creating a study.
- Enhanced error logging for better debugging.
- Refactored user creation in webhooks to use transactions for atomicity.
- Improved response structure for webhook processing.
- Updated the seed script to streamline role and permission insertion.
- Added new permissions for editing studies and participants.
This commit is contained in:
2024-12-03 15:42:43 -05:00
parent 09b24a0e74
commit 3a955a0568
7 changed files with 291 additions and 183 deletions

View File

@@ -47,6 +47,11 @@ export default function Studies() {
const createStudy = async (e: React.FormEvent) => {
e.preventDefault();
try {
console.log("Sending study data:", {
title: newStudyTitle,
description: newStudyDescription
});
const response = await fetch('/api/studies', {
method: 'POST',
headers: {
@@ -57,12 +62,20 @@ export default function Studies() {
description: newStudyDescription,
}),
});
if (!response.ok) {
const errorData = await response.json();
console.error("Server response:", errorData);
throw new Error(errorData.error || 'Failed to create study');
}
const newStudy = await response.json();
setStudies([...studies, newStudy]);
setNewStudyTitle("");
setNewStudyDescription("");
} catch (error) {
console.error('Error creating study:', error);
alert(error instanceof Error ? error.message : 'Failed to create study');
}
};