-
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.
* Updated event model str types to more understandable one * Added db index for event code * Added event reports backend * minor change after merge * event id mistake cleared * Allow collab clubs to also fetch the budget and other details for an event * Allow collab clubs also to check bills status * access to collab clubs added to view report * instead of raising exception sending empty response * Return relevant error/s if bill not found for an event * added eventreport submissionstatus in alleventbills query --------- Co-authored-by: dileepadari <[email protected]>
- Loading branch information
1 parent
819714b
commit cbe41b4
Showing
10 changed files
with
236 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from mutations.event_report import mutations as event_report_mutations | ||
from mutations.events import mutations as events_mutations | ||
from mutations.finances import mutations as finances_mutations | ||
from mutations.holidays import mutations as holidays_mutations | ||
|
||
mutations = [ | ||
*events_mutations, | ||
*event_report_mutations, | ||
*finances_mutations, | ||
*holidays_mutations, | ||
] |
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,76 @@ | ||
from datetime import datetime | ||
|
||
import strawberry | ||
from fastapi.encoders import jsonable_encoder | ||
|
||
from db import event_reportsdb, eventsdb | ||
from models import EventReport | ||
from mtypes import Event_State_Status | ||
from otypes import EventReportType, Info, InputEventReport | ||
from utils import getMember | ||
|
||
|
||
@strawberry.mutation | ||
def addEventReport(details: InputEventReport, info: Info) -> EventReportType: | ||
""" | ||
Add an event report | ||
returns the added event report | ||
""" | ||
|
||
user = info.context.user | ||
if not user: | ||
raise ValueError("User not authenticated") | ||
|
||
user_role = user["role"] | ||
if user_role not in ["club"]: | ||
raise ValueError("User not authorized") | ||
|
||
eventid = details.eventid | ||
if not eventid: | ||
raise ValueError("Event ID is required") | ||
event = eventsdb.find_one( | ||
{ | ||
"_id": eventid, | ||
"datetimeperiod.1": { | ||
"$lt": datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ") | ||
}, | ||
"status.state": Event_State_Status.approved.value, | ||
} | ||
) | ||
if not event: | ||
raise ValueError("Event not found") | ||
if user_role == "club" and event["clubid"] != user["uid"]: | ||
raise ValueError("User not authorized") | ||
|
||
searchspace = { | ||
"event_id": eventid, | ||
} | ||
|
||
event_report = event_reportsdb.find_one(searchspace) | ||
|
||
if event_report: | ||
raise ValueError("Event report already exists") | ||
|
||
# Check if submitted_by is valid | ||
cid = event["clubid"] | ||
uid = details.submitted_by | ||
if not getMember(cid, uid, info.context.cookies): | ||
raise ValueError("Submitted by is not a valid member") | ||
|
||
report_dict = jsonable_encoder(details.to_pydantic()) | ||
report_dict["event_id"] = details.eventid | ||
event_report_id = event_reportsdb.insert_one(report_dict).inserted_id | ||
event_report = event_reportsdb.find_one({"_id": event_report_id}) | ||
|
||
# Update event report submitted status to True | ||
eventsdb.update_one( | ||
{"_id": eventid}, | ||
{"$set": {"event_report_submitted": True}}, | ||
) | ||
|
||
return EventReportType.from_pydantic( | ||
EventReport.model_validate(event_report) | ||
) | ||
|
||
|
||
mutations = [addEventReport] |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from queries.event_report import queries as event_report_queries | ||
from queries.events import queries as events_queries | ||
from queries.finances import queries as finances_queries | ||
from queries.holidays import queries as holidays_queries | ||
|
||
queries = [ | ||
*events_queries, | ||
*event_report_queries, | ||
*finances_queries, | ||
*holidays_queries, | ||
] | ||
] |
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,46 @@ | ||
import strawberry | ||
|
||
from db import event_reportsdb, eventsdb | ||
from models import EventReport | ||
from otypes import EventReportType, Info | ||
|
||
|
||
@strawberry.field | ||
def eventReport(eventid: str, info: Info) -> EventReportType: | ||
""" | ||
Get the event report of an event | ||
returns the event report | ||
""" | ||
|
||
user = info.context.user | ||
if not user: | ||
raise ValueError("User not authenticated") | ||
|
||
user_role = user["role"] | ||
if user_role not in ["cc", "slo", "club"]: | ||
raise ValueError("User not authorized") | ||
|
||
event = eventsdb.find_one({"_id": eventid, "event_report_submitted": True}) | ||
if not event: | ||
raise ValueError("Event not found") | ||
if user_role == "club" and event["clubid"] != user["uid"] and ( | ||
event["collabclubs"] is None | ||
or user["uid"] not in event["collabclubs"] | ||
): | ||
raise ValueError("User not authorized") | ||
|
||
event_report = event_reportsdb.find_one( | ||
{ | ||
"event_id": eventid, | ||
} | ||
) | ||
|
||
if not event_report: | ||
raise ValueError("Event report not found") | ||
|
||
return EventReportType.from_pydantic( | ||
EventReport.model_validate(event_report) | ||
) | ||
|
||
|
||
queries = [eventReport] |
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
Oops, something went wrong.