@@ -55,7 +55,9 @@ async def appointment_webhook(request):
5555 pg_insert (sa_services )
5656 .values (id = appointment .service_id , company = request ['company' ].id , ** service_insert_update )
5757 .on_conflict_do_update (
58- index_elements = [ser_c .id ], where = ser_c .id == appointment .service_id , set_ = service_insert_update ,
58+ index_elements = [ser_c .id ],
59+ where = ser_c .id == appointment .service_id ,
60+ set_ = service_insert_update ,
5961 )
6062 )
6163 apt_insert_update = appointment .dict (
@@ -66,17 +68,19 @@ async def appointment_webhook(request):
6668 await conn .execute (
6769 pg_insert (sa_appointments )
6870 .values (id = apt_id , service = appointment .service_id , ** apt_insert_update )
69- .on_conflict_do_update (index_elements = [apt_c .id ], where = apt_c .id == apt_id , set_ = apt_insert_update ,)
71+ .on_conflict_do_update (
72+ index_elements = [apt_c .id ],
73+ where = apt_c .id == apt_id ,
74+ set_ = apt_insert_update ,
75+ )
7076 )
7177 return json_response (request , status = 'success' )
7278
7379
7480async def appointment_webhook_mass (request ):
7581 conn = await request ['conn_manager' ].get_connection ()
7682 data = await request .json ()
77- if data ['_request_time' ]:
78- del data ['_request_time' ]
79- for apt_id , apt in data .items ():
83+ for apt in data ['appointments' ]:
8084 if apt ['ss_method' ] == 'POST' :
8185 appointment = AppointmentModel (** apt )
8286
@@ -86,7 +90,7 @@ async def appointment_webhook_mass(request):
8690 raise HTTPConflictJson (
8791 status = 'service conflict' ,
8892 details = f'service { appointment .service_id } already exists'
89- ' and is associated with another company' ,
93+ ' and is associated with another company' ,
9094 )
9195
9296 service_insert_update = dict (
@@ -102,7 +106,9 @@ async def appointment_webhook_mass(request):
102106 pg_insert (sa_services )
103107 .values (id = appointment .service_id , company = request ['company' ].id , ** service_insert_update )
104108 .on_conflict_do_update (
105- index_elements = [ser_c .id ], where = ser_c .id == appointment .service_id , set_ = service_insert_update ,
109+ index_elements = [ser_c .id ],
110+ where = ser_c .id == appointment .service_id ,
111+ set_ = service_insert_update ,
106112 )
107113 )
108114 apt_insert_keys = [
@@ -120,12 +126,16 @@ async def appointment_webhook_mass(request):
120126
121127 await conn .execute (
122128 pg_insert (sa_appointments )
123- .values (id = apt_id , service = appointment .service_id , ** apt_insert_update )
124- .on_conflict_do_update (index_elements = [apt_c .id ], where = apt_c .id == apt_id , set_ = apt_insert_update ,)
129+ .values (id = appointment .id , service = appointment .service_id , ** apt_insert_update )
130+ .on_conflict_do_update (
131+ index_elements = [apt_c .id ],
132+ where = apt_c .id == appointment .id ,
133+ set_ = apt_insert_update ,
134+ )
125135 )
126136 elif apt ['ss_method' ] == 'DELETE' :
127137 await conn .execute (
128- sa_appointments .delete ().where (and_ (apt_c .id == apt_id , ser_c .company == request ['company' ].id ))
138+ sa_appointments .delete ().where (and_ (apt_c .id == apt [ 'id' ] , ser_c .company == request ['company' ].id ))
129139 )
130140 else :
131141 return
@@ -208,7 +218,11 @@ async def appointment_list(request):
208218 q_count = select ([sql_f .count ()]).select_from (sa_appointments .join (sa_services )).where (and_ (* where ))
209219 cur_count = await conn .execute (q_count )
210220
211- return json_response (request , results = results , count = (await cur_count .first ())[0 ],)
221+ return json_response (
222+ request ,
223+ results = results ,
224+ count = (await cur_count .first ())[0 ],
225+ )
212226
213227
214228async def service_list (request ):
@@ -240,7 +254,11 @@ async def service_list(request):
240254 select ([sql_f .count (distinct (ser_c .id ))]).select_from (sa_appointments .join (sa_services )).where (and_ (* where ))
241255 )
242256
243- return json_response (request , results = results , count = (await cur_count .first ())[0 ],)
257+ return json_response (
258+ request ,
259+ results = results ,
260+ count = (await cur_count .first ())[0 ],
261+ )
244262
245263
246264class SSOData (BaseModel ):
@@ -273,7 +291,8 @@ def _get_sso_data(request, company) -> SSOData:
273291 sso_data : SSOData = SSOData .parse_raw (sso_data_ , proto = Protocol .json )
274292 except ValidationError as e :
275293 raise HTTPBadRequestJson (
276- status = 'invalid request data' , details = e .errors (),
294+ status = 'invalid request data' ,
295+ details = e .errors (),
277296 )
278297 else :
279298 if sso_data .expires < datetime .astimezone (datetime .now (), timezone .utc ):
@@ -318,7 +337,13 @@ async def book_appointment(request):
318337 v = await conn .execute (
319338 select ([apt_c .attendees_current_ids ])
320339 .select_from (sa_appointments .join (sa_services ))
321- .where (and_ (ser_c .company == company .id , apt_c .start > datetime .utcnow (), apt_c .id == booking .appointment ,))
340+ .where (
341+ and_ (
342+ ser_c .company == company .id ,
343+ apt_c .start > datetime .utcnow (),
344+ apt_c .id == booking .appointment ,
345+ )
346+ )
322347 )
323348 r = await v .first ()
324349 if not r :
0 commit comments