Working on Cvent API related
This commit is contained in:
138
app/routers/e_cvent.py
Normal file
138
app/routers/e_cvent.py
Normal file
@@ -0,0 +1,138 @@
|
||||
import datetime, json, pytz, secrets, time
|
||||
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status
|
||||
from pydantic import BaseModel, EmailStr, Field
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
|
||||
from app.lib_general import log, logging, secure_hash_string
|
||||
from app.config import settings
|
||||
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, redis_lookup_id_random
|
||||
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.methods.e_cvent_methods import get_customer_list, get_customer, get_custom_fields
|
||||
|
||||
from app.models.response_models import Resp_Body_Base, mk_resp
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ### BEGIN ### API Cvent ### get_person() ###
|
||||
# Updated 2022-01-28
|
||||
@router.get('/person/{e_person_id}', response_model=Resp_Body_Base)
|
||||
async def get_person(
|
||||
e_person_id: str = Query(..., min_length=36, max_length=36), # UUID v4
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if cvent_customer_obj_result := get_customer(customer_id=e_person_id):
|
||||
customer_obj = cvent_customer_obj_result
|
||||
else:
|
||||
log.info(f'Cvent contact not found with ID: {e_person_id}')
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
|
||||
# Important contact fields:
|
||||
# id (UUID v4)
|
||||
# type { id, name } for contact type (membership type)
|
||||
# membership { expiration, joined, lastRenewal }
|
||||
|
||||
# email and ccEmail
|
||||
# prefix
|
||||
# designation
|
||||
# title
|
||||
# nickname
|
||||
# firstName
|
||||
# lastName
|
||||
# middleName
|
||||
|
||||
# company
|
||||
|
||||
# homePhone
|
||||
# mobilePhone
|
||||
# workPhone
|
||||
# homeAddress { address1, address2, address3, city, country, countryCode, postalCode, region, regionCode }
|
||||
|
||||
person_data = {}
|
||||
if custom_field_list := customer_obj.get('customFields'): # List
|
||||
for custom_field in custom_field_list:
|
||||
# Get the External ID created by OSIT
|
||||
if custom_field.get('id') == '609ab766-7d79-4a9d-a72c-f126412659ee':
|
||||
person_data['external_id'] = custom_field.get('value')
|
||||
|
||||
# person_data['pronouns'] = ???
|
||||
person_data['informal_name'] = customer_obj.get('nickname')
|
||||
person_data['title_names'] = customer_obj.get('prefix')
|
||||
person_data['given_name'] = customer_obj.get('firstName')
|
||||
person_data['middle_name'] = customer_obj.get('middleName')
|
||||
person_data['family_name'] = customer_obj.get('lastName')
|
||||
person_data['designations'] = customer_obj.get('designation')
|
||||
person_data['professional_title'] = customer_obj.get('title')
|
||||
|
||||
person_data['affiliations'] = customer_obj.get('company')
|
||||
|
||||
contact_data = {}
|
||||
contact_data['email'] = customer_obj.get('email')
|
||||
contact_data['cc_email'] = customer_obj.get('ccEmail')
|
||||
contact_data['phone_mobile'] = customer_obj.get('mobilePhone')
|
||||
contact_data['phone_home'] = customer_obj.get('homePhone')
|
||||
contact_data['phone_office'] = customer_obj.get('workPhone')
|
||||
|
||||
address_data = {}
|
||||
address_data['line_1'] = customer_obj.get('homeAddress').get('address1')
|
||||
address_data['line_2'] = customer_obj.get('homeAddress').get('address2')
|
||||
address_data['line_3'] = customer_obj.get('homeAddress').get('address3')
|
||||
address_data['city'] = customer_obj.get('homeAddress').get('city')
|
||||
address_data['state_province'] = customer_obj.get('homeAddress').get('region')
|
||||
country_subdivision_code = customer_obj.get('homeAddress').get('regionCode') +'-'+customer_obj.get('homeAddress').get('countryCode')
|
||||
address_data['country_subdivision_code'] = customer_obj.get('homeAddress').get('regionCode')
|
||||
address_data['postal_code'] = customer_obj.get('homeAddress').get('postalCode')
|
||||
address_data['country_alpha_2_code'] = customer_obj.get('homeAddress').get('countryCode')
|
||||
address_data['country'] = customer_obj.get('homeAddress').get('country')
|
||||
address_data['country_alpha_2_code'] = customer_obj.get('homeAddress').get('countryCode')
|
||||
|
||||
membership = {}
|
||||
membership['first_start_on'] = customer_obj.get('membership').get('joined') # A trigger should update 'first_start_on' if needed???
|
||||
membership['start_on'] = customer_obj.get('membership').get('lastRenewal') # A trigger should update 'first_start_on' if needed???
|
||||
membership['end_on'] = customer_obj.get('membership').get('expiration')
|
||||
|
||||
membership_type_id = customer_obj.get('type').get('id')
|
||||
membership_type_name = customer_obj.get('type').get('name')
|
||||
# 'id': '5EB898D8-C253-482C-A93A-0B6667C26E04', 'name': 'Al-Anon Member'
|
||||
# 'id': 'A20358C5-0F6C-47AF-9843-BA9483A9D767', 'name': 'Al-Anon Non-Member'
|
||||
# 'id': 'A01900AB-496A-48A1-9B04-C2874651227E', 'name': 'Member'
|
||||
# 'id': '03622AEE-F586-4AE5-A191-B8372543A8C8', 'name': 'Student Member'
|
||||
# 'id': '65437A15-39C2-4EB5-9AFE-67AF6FE41C27', 'name': 'Non-Member'
|
||||
# 'id': 'A69FAF20-BF2A-4222-B15B-7B0C7EFBEAA7', 'name': 'Student Non-member'
|
||||
|
||||
# 'id': 'C9FA7E47-A925-44AB-B94A-9B3003CA2AC4', 'name': 'Attendee'
|
||||
# 'id': '96D5B3CC-FD4E-4957-BA71-9CEF388095EF', 'name': 'Guest'
|
||||
# 'id': 'C49439B3-5AE6-496F-A0AD-4CCB1A9000E3', 'name': 'Spouse/SO Guest Registration'
|
||||
# 'id': 'AADABEF0-3C84-45A2-9D9B-E2CF585D4AE5', 'name': 'General Attendee'
|
||||
# 'id': '54127B4D-E531-4046-AF5C-0F0D71DC39D2', 'name': 'Adult Guest Registration'
|
||||
# 'id': '6F06D6B6-2C23-4EF8-986F-73BF0DB2B229', 'name': "Children's Program with Jerry Moe (7-12 years)"
|
||||
# 'id': '71D07118-C24D-4B2E-888D-56AC1B941495', 'name': "IDAA 20's Guest Registration"
|
||||
# 'id': 'DA17F721-9924-43E3-A31F-C567BA96DC64', 'name': 'IDAA Teen (13-19 years)'
|
||||
|
||||
if membership_type_name == 'Al-Anon Member' or membership_type_name == 'Al-Anon Members':
|
||||
membership_person_type_data['membership_type_id'] = 6
|
||||
membership_person_type_data['product_id'] = 13
|
||||
membership_person_data['level'] = 1
|
||||
membership_person_type_data['level'] = 1
|
||||
elif membership_type_name == 'Annual Contribution' or membership_type_name == 'Annual Contributions': # Unsure... making affiliate
|
||||
membership_person_type_data['membership_type_id'] = 8
|
||||
membership_person_type_data['product_id'] = 13
|
||||
membership_person_data['level'] = 3
|
||||
membership_person_type_data['level'] = 3
|
||||
elif membership_type_name == 'Doctoral Qualifying Member' or membership_type_name == 'Doctoral Qualifying Members':
|
||||
membership_person_type_data['membership_type_id'] = 5
|
||||
membership_person_type_data['product_id'] = 4
|
||||
membership_person_data['level'] = 1
|
||||
membership_person_type_data['level'] = 1
|
||||
elif membership_type_name == 'Student Member' or membership_type_name == 'Student Members':
|
||||
membership_person_type_data['membership_type_id'] = 7
|
||||
membership_person_type_data['product_id'] = 14
|
||||
membership_person_data['level'] = 1
|
||||
membership_person_type_data['level'] = 1
|
||||
Reference in New Issue
Block a user