mirror of
https://github.com/vee1e/bulk-questionnaire-upload.git
synced 2026-09-01 17:57:10 +00:00
feat: add update form API endpoint and export JSON endpoint
This commit is contained in:
parent
a531879416
commit
6ac9fdeae4
4 changed files with 152 additions and 4 deletions
|
|
@ -129,4 +129,34 @@ class DatabaseService:
|
|||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error deleting all forms: {e}")
|
||||
return False
|
||||
|
||||
async def update_form(self, form_id: str, form_data: Dict[str, Any], questions: List[Dict[str, Any]], options: List[Dict[str, Any]]) -> bool:
|
||||
"""Update form metadata, questions, and options by form_id"""
|
||||
try:
|
||||
# Update form metadata
|
||||
if 'id' in form_data:
|
||||
del form_data['id']
|
||||
await forms_collection.update_one({"_id": ObjectId(form_id)}, {"$set": form_data})
|
||||
|
||||
# Delete old questions and options
|
||||
await questions_collection.delete_many({"form_id": form_id})
|
||||
await options_collection.delete_many({"form_id": form_id})
|
||||
|
||||
# Insert new questions
|
||||
for question in questions:
|
||||
question['form_id'] = form_id
|
||||
question['_id'] = ObjectId()
|
||||
await questions_collection.insert_one(question)
|
||||
|
||||
# Insert new options
|
||||
for option in options:
|
||||
option['form_id'] = form_id
|
||||
option['_id'] = ObjectId()
|
||||
await options_collection.insert_one(option)
|
||||
|
||||
logger.info(f"Updated form {form_id} with new metadata, questions, and options")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating form: {e}")
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue