def update_contact(org_id, contact_info): """Update the existing contact for this org.""" current_app.logger.debug('>update_contact ') org = OrgModel.find_by_org_id(org_id) if org is None: raise BusinessException(Error.DATA_NOT_FOUND, None) # find the contact link for this org contact_link = ContactLinkModel.find_by_org_id(org_id) if contact_link is None or contact_link.contact is None: raise BusinessException(Error.DATA_NOT_FOUND, None) contact = contact_link.contact contact.update_from_dict(**camelback2snake(contact_info)) contact.commit() current_app.logger.debug('<update_contact ') # return the updated contact return ContactService(contact)
def add_contact(org_id, contact_info): """Create a new contact for this org.""" # check for existing contact (only one contact per org for now) current_app.logger.debug('>add_contact') org = OrgModel.find_by_org_id(org_id) if org is None: raise BusinessException(Error.DATA_NOT_FOUND, None) contact_link = ContactLinkModel.find_by_org_id(org_id) if contact_link is not None: raise BusinessException(Error.DATA_ALREADY_EXISTS, None) contact = ContactModel(**camelback2snake(contact_info)) contact = contact.flush() contact_link = ContactLinkModel() contact_link.contact = contact contact_link.org = org contact_link.save() current_app.logger.debug('<add_contact') return ContactService(contact)