Skip to content

Commit ef15669

Browse files
authored
Refactor activity update logic (#160)
Updated the activity status update logic to conditionally include the approver and updatedAt fields. Enhanced the update operation for activity name and description to also set updatedAt.
1 parent 65e7d26 commit ef15669

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

routers/activities_v2_router.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,26 @@ async def modify_activity_status_v2(
415415
detail="Activity status can only be modified from pending to effective or refused",
416416
)
417417

418+
if status.status == target_activity.status:
419+
raise HTTPException(
420+
status_code=400,
421+
detail="Activity status is not changed",
422+
)
423+
418424
await volunteer.validate_check_permission(user, target_activity, strict=True)
419425

426+
update_content = {
427+
"status": status.status,
428+
"approver": str(user["id"]),
429+
"updatedAt": datetime.now(),
430+
}
431+
432+
if target_activity.status != "pending":
433+
del update_content["approver"] # The activity is not being approved
434+
420435
result = await db.zvms_new.get_collection("activities").update_one(
421436
{"_id": validate_object_id(activity_id)},
422-
{
423-
"$set": {
424-
"status": status.status,
425-
"approver": str(user["id"]),
426-
"updatedAt": datetime.now(),
427-
}
428-
},
437+
{"$set": update_content},
429438
)
430439

431440
if result.modified_count == 0:
@@ -567,7 +576,7 @@ async def update_activity_info(
567576

568577
result = await db.zvms_new.get_collection("activities").update_one(
569578
{"_id": validate_object_id(activity_id)},
570-
{"$set": {"name": payload.name, "description": payload.description}},
579+
{"$set": {"name": payload.name, "description": payload.description, "updatedAt": datetime.now()}},
571580
)
572581

573582
if result.modified_count == 0:

0 commit comments

Comments
 (0)