toulouse-maelis: factorize payload processing on subscriptions (#74763)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
6ba66d06ff
commit
54783a392f
|
@ -2945,27 +2945,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
response['agenda'] = bookings
|
||||
return {'data': response}
|
||||
|
||||
@endpoint(
|
||||
display_category='Inscriptions',
|
||||
description="Ajouter au panier une inscription extra-scolaire ou loisir",
|
||||
name='add-person-basket-subscription',
|
||||
perm='can_access',
|
||||
post={
|
||||
'request_body': {
|
||||
'schema': {
|
||||
'application/json': activity_schemas.SUBSCRIPTION_SCHEMA,
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
def add_person_basket_subscription(
|
||||
self,
|
||||
request,
|
||||
post_data,
|
||||
NameID=None,
|
||||
family_id=None,
|
||||
):
|
||||
family_id = family_id or self.get_link(NameID).family_id
|
||||
def process_subscription_payload(self, family_id, post_data):
|
||||
params = {
|
||||
'numDossier': family_id,
|
||||
'numPerson': post_data['person_id'],
|
||||
|
@ -3007,6 +2987,30 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
'isPresent': True,
|
||||
}
|
||||
)
|
||||
return recurrent_week
|
||||
|
||||
@endpoint(
|
||||
display_category='Inscriptions',
|
||||
description="Ajouter au panier une inscription extra-scolaire ou loisir",
|
||||
name='add-person-basket-subscription',
|
||||
perm='can_access',
|
||||
post={
|
||||
'request_body': {
|
||||
'schema': {
|
||||
'application/json': activity_schemas.SUBSCRIPTION_SCHEMA,
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
def add_person_basket_subscription(
|
||||
self,
|
||||
request,
|
||||
post_data,
|
||||
NameID=None,
|
||||
family_id=None,
|
||||
):
|
||||
family_id = family_id or self.get_link(NameID).family_id
|
||||
recurrent_week = self.process_subscription_payload(family_id, post_data)
|
||||
payload = {
|
||||
'addPersonUnitBasketRequestBean': {
|
||||
'numFamily': family_id,
|
||||
|
@ -3046,47 +3050,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
family_id=None,
|
||||
):
|
||||
family_id = family_id or self.get_link(NameID).family_id
|
||||
params = {
|
||||
'numDossier': family_id,
|
||||
'numPerson': post_data['person_id'],
|
||||
'activityUnitPlace': {
|
||||
'idActivity': post_data['activity_id'],
|
||||
'idUnit': post_data['unit_id'],
|
||||
'idPlace': post_data['place_id'],
|
||||
},
|
||||
}
|
||||
subscription_info = self.call('Activity', 'getPersonUnitInfo', getPersonUnitInfoRequestBean=params)
|
||||
if post_data.get('conveyanceSubscribe') and (
|
||||
post_data['conveyanceSubscribe'].get('idPlaceMorning')
|
||||
or post_data['conveyanceSubscribe'].get('idPlaceAfternoon')
|
||||
):
|
||||
if not subscription_info.get('conveyance'):
|
||||
raise APIError('no conveyance defined on this activity')
|
||||
for payload_key, info_key in [
|
||||
('idPlaceMorning', 'morningJourney'),
|
||||
('idPlaceAfternoon', 'afternoonJourney'),
|
||||
]:
|
||||
if post_data['conveyanceSubscribe'].get(payload_key):
|
||||
info_bus_ids = [
|
||||
x['place']['id']
|
||||
for x in subscription_info['conveyance'][info_key]['depositPlaceList']
|
||||
]
|
||||
payload_bus_id = post_data['conveyanceSubscribe'][payload_key]
|
||||
if not payload_bus_id in info_bus_ids:
|
||||
raise APIError(
|
||||
'no "%s" place defined on "%s" conveyance' % (payload_bus_id, info_key)
|
||||
)
|
||||
|
||||
recurrent_week = []
|
||||
for item in post_data.get('recurrent_week') or []:
|
||||
day_num, key = item.split('-')
|
||||
recurrent_week.append(
|
||||
{
|
||||
'dayNum': day_num,
|
||||
'calendarLetter': key,
|
||||
'isPresent': True,
|
||||
}
|
||||
)
|
||||
recurrent_week = self.process_subscription_payload(family_id, post_data)
|
||||
payload = {
|
||||
'AddPersonSubscribeRequestBean': {
|
||||
'numFamily': family_id,
|
||||
|
|
Loading…
Reference in New Issue