1414)
1515from helpers .calendar .events import RoomSchedules , CalendarEvents
1616from helpers .email .email import notification
17- from helpers .calendar .credentials import get_single_calendar_event
17+ from helpers .calendar .credentials import (
18+ get_single_calendar_event ,
19+ credentials
20+ )
1821from helpers .auth .authentication import Auth
1922from helpers .pagination .paginate import ListPaginate
2023from helpers .devices .devices import update_device_last_activity
2326 validate_page_and_per_page ,
2427 validate_calendar_id_input
2528)
29+ from helpers .events_filter .events_filter import (
30+ calendar_dates_format ,
31+ empty_string_checker
32+ )
2633
2734utc = pytz .utc
2835
@@ -35,6 +42,87 @@ class Meta:
3542 model = EventsModel
3643
3744
45+ class BookEvent (graphene .Mutation ):
46+ """
47+ Book Calendar events
48+ """
49+ response = graphene .String ()
50+
51+ class Arguments :
52+ event_title = graphene .String (required = True )
53+ start_date = graphene .String (required = True )
54+ start_time = graphene .String (required = True )
55+ duration = graphene .Float (required = False )
56+ attendees = graphene .String (required = False )
57+ organizer = graphene .String (required = False )
58+ description = graphene .String (required = False )
59+ room = graphene .String (required = True )
60+ time_zone = graphene .String (required = True )
61+
62+ @Auth .user_roles ('Admin' , 'Default User' , 'Super Admin' )
63+ def mutate (self , info , ** kwargs ):
64+ """Creates calendar events
65+
66+ Args:
67+ event_title: A sting that communicates the event summary/title
68+ [required]
69+ start_date: The start date of the event eg. 'Nov 4 2019' [required]
70+ start_time: The end time of the event eg '07:00 AM' [required]
71+ duration: A float of the duration of the event in minutes
72+ attendees: A string of emails of the event guests
73+ description: Any additional information about the event
74+ room: The meeting room where the even will be held [required]
75+ time_zone: The timezone of the event location eg. 'Africa/Kigali'
76+ organizer: The email of the co-organizer, the converge email is
77+ the default
78+
79+ Returns:
80+ A string that communicates a successfully created event.
81+ """
82+ room = kwargs .get ('room' , None )
83+ attendees = kwargs .get ('attendees' , None )
84+ description = kwargs .get ('description' , None )
85+ time_zone = kwargs .get ('time_zone' , 'Africa/Accra' )
86+ duration = kwargs .get ('duration' , 60 )
87+ organizer = kwargs .get ('organizer' , None )
88+
89+ event_title = kwargs ['event_title' ]
90+ empty_string_checker (event_title )
91+ empty_string_checker (room )
92+ empty_string_checker (time_zone )
93+
94+ start_date , end_date = calendar_dates_format (
95+ kwargs ['start_date' ], kwargs ['start_time' ], duration )
96+
97+ attendees = attendees .replace (" " , "" ).split ("," )
98+ guests = []
99+ for guest in attendees :
100+ attendee = {'email' : guest }
101+ guests .append (attendee )
102+
103+ event = {
104+ 'summary' : kwargs ['event_title' ],
105+ 'location' : room ,
106+ 'description' : description ,
107+ 'start' : {
108+ 'dateTime' : start_date ,
109+ 'timeZone' : time_zone ,
110+ },
111+ 'end' : {
112+ 'dateTime' : end_date ,
113+ 'timeZone' : time_zone ,
114+ },
115+ 'attendees' : guests ,
116+ "organizer" : {
117+ "email" : organizer
118+ }
119+ }
120+ service = credentials .set_api_credentials ()
121+ service .events ().insert (calendarId = 'primary' , body = event ,
122+ sendNotifications = True ).execute ()
123+ return BookEvent (response = 'Event created successfully' )
124+
125+
38126class EventCheckin (graphene .Mutation ):
39127 """
40128 Returns the eventcheckin payload
@@ -204,6 +292,19 @@ def check_event_in_db(instance, info, event_check, **kwargs):
204292class Mutation (graphene .ObjectType ):
205293 event_checkin = EventCheckin .Field ()
206294 cancel_event = CancelEvent .Field ()
295+ book_event = BookEvent .Field (
296+ description = "Mutation to book a calendar event given the arguments\
297+ \n - event_title: A sting that communicates the event\
298+ summary/title [required]\n - start_date: The start date \
299+ of the event eg 'Nov 4 2019' [required]\
300+ \n - start_time: The end time of the event eg'07:00 AM'[required]\
301+ \n - duration: A float of the duration of the event in minutes\
302+ \n - attendees: A string of emails of the event guests\
303+ \n - description: Any additional information about the event\
304+ \n - room: The meeting room where the even will be held[required]\
305+ \n - organizer: The email of the co - organizer, the converge\
306+ email is the default\
307+ \n - time_zone: The timezone of the event location" )
207308 end_event = EndEvent .Field (
208309 description = "Mutation to end a calendar event given the arguments\
209310 \n - calendar_id: The unique identifier of the calendar event\
0 commit comments