コード例 #1
0
    def get(self, status):
        """
        Get all insurance companies, together with the company details"""
        # fetch all companies, then their details.
        companies_list = CompanyDetails.get_companies()
        list_of_companies = []
        if companies_list:
            for company in companies_list:
                list_of_products = company['products']
                licenced_classes = [
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
                ]

                # status 1 for registered and O for unregistered
                if status == 0:
                    # return unregistered companies
                    # Only return companies that sell general insurance policies and
                    # don't have an associated insurance company yet
                    if len(company['products']) != 0 and len(
                            company['insurance_company']) == 0:
                        if random.choice(
                                company['products']) in licenced_classes:
                            data = {
                                "id": company['id'],
                                "name": company['name']
                            }
                            list_of_companies.append(data)

                if status == 1:
                    # only return companies that are registered
                    if len(company['products']) != 0 and len(
                            company['insurance_company']) != 0:
                        if random.choice(
                                company['products']) in licenced_classes:
                            data = {
                                "id": company['id'],
                                "name": company['name'],
                                "products": company['products']
                            }
                            list_of_companies.append(data)

            response = helper.make_rest_success_response(
                "Success", list_of_companies)
            return make_response(response, 200)
        else:
            response = helper.make_rest_success_response(
                "No company registered yet")
            return make_response(response, 404)
コード例 #2
0
    def get(self, email):
        """
        Get customer details using an attribute such as email
        """
        # object to store all user data
        data = {}
        # get the agency id of the organization requesting for customer details
        contact_id = get_jwt_identity()
        # get user role
        claims = get_jwt_claims()
        role = claims['role']
        # company_id = self.get_agency_id(role, contact_id)
        # get user id from customer email
        customer = User.get_user_by_email(email)

        # get customer details using the user_id
        customer_details = self.get_customer_details(customer.id)
        data.update({"customer": customer_details})

        # get the cover data using the customer number in customer details
        cust_no = customer_details["customer_number"]
        cover_details = self.get_cover_details(cust_no)
        data.update({"cover_details": cover_details})

        response_msg = helper.make_rest_success_response(
            "Success", data)
        return make_response(response_msg, 200)
コード例 #3
0
    def post(self):
        details = policy_parser.parse_args()
        # get the current agency details
        uid = get_jwt_identity()
        # use the uid to get company through the company contact_id
        company = InsuranceCompany.get_company_by_contact_person(uid)
        """
        First add the loading to the loadingss table, regardless of insurance company
        """
        existing_loadings = Loadings.get_all_loadings()
        names = [loading['name'] for loading in existing_loadings]
        loading_name = details['name']

        # check whether the benefits to be added already exist
        if loading_name not in names:
            new_loading = Loadings(loading_name)
            new_loading.save()
        """
        Store loadings offered by a particular company together with limit
        """
        # get the loading_id
        loading_id = Loadings.get_loading_id_by_name(loading_name)
        company_loading = ICLoadings(company.id, loading_id, details['rate'])
        company_loading.save()
        """
        Send success response
        """
        response_msg = helper.make_rest_success_response(
            "Loading added successfully")
        return make_response(response_msg, 200)
コード例 #4
0
    def post(self):
        """
        send the user an email containing a link to set a new password
        :arg email {string} user email whose account we intend to recover
        :return:
        """
        user_details = user_parser.parse_args()
        user_row = User.get_user_by_email(user_details['email'])
        if user_row:
            profile_details = UserProfile.get_profile_by_user_id(user_row.id)
            account_token = token_handler.user_account_confirmation_token(
                user_row.id)
            email_text = f"To reset your account password, please follow this link " \
                         f"{application.config['ACCOUNT_RESET_ENDPOINT']}/{account_token}"
            email_template = helper.generate_account_recovery_template(
                application.config['ACCOUNT_RESET_ENDPOINT'], account_token,
                profile_details.first_name)
            subject = "Account Password Recovery"
            helper.send_email(user_details['email'], subject, email_template,
                              email_text)
            response_msg = helper.make_rest_success_response(
                "Successfully sent account recovery steps, check your"
                " email")
            return make_response(response_msg, 200)

        response_msg = helper.make_rest_fail_response(
            "There is not account associated with this email")
        return make_response(response_msg, 404)
コード例 #5
0
    def get(self, child_policy_id):
        """
        get the transaction history of a particular policy
        :return:
        """
        transaction_history = PolicyPayments.get_payments_history(
            child_policy_id)
        if transaction_history:
            response_message = "Success"
            return make_response(
                helper.make_rest_success_response(response_message,
                                                  transaction_history), 200)

        response_message = "No data was found"
        return make_response(
            helper.make_rest_success_response(response_message), 404)
コード例 #6
0
    def post(self):
        # get the insurance company details
        uid = get_jwt_identity()

        # get user role so that you can use it to get the agency_id,
        claims = get_jwt_claims()
        role = claims['role']

        # get company_id
        company = self.get_agency_id(role, uid)

        policy_details = policy_parser.parse_args()

        # store the products affiliated with a particular company, one insurance class has many subclasses
        insurance_class = policy_details['insurance_class']
        subclass = policy_details["sub_class"]
        if insurance_class and subclass:
            for i in subclass:
                new_product = ICProducts(company.id, insurance_class, i)
                new_product.save()

        if policy_details['rate']:
            # set the insurance_company's rate
            data = {"rate": policy_details['rate']}
            company.update(data)

        if policy_details["ncd_rate"]:
            data = {"ncd_rate": policy_details["ncd_rate"]}
            company.update(data)

        response = helper.make_rest_success_response("Success")
        return make_response(response, 200)
コード例 #7
0
ファイル: Extensions.py プロジェクト: f0rtun3/nexure-backend
    def post(self):
        details = policy_parser.parse_args()
        # get the current agency details
        uid = get_jwt_identity()
        # use the uid to get company through the company contact_id
        company = InsuranceCompany.get_company_by_contact_person(uid)
        """
        First add the extension to the extensions table, regardless of insurance company
        """
        exisiting_extensions = Extension.get_all_extensions()
        names = [extension['name'] for extension in exisiting_extensions]
        extension_name = details['name']

        # check whether the benefits to be added already exist
        if extension_name not in names:
            new_extension = Extension(extension_name)
            new_extension.save()
        """
        Store benefits offered by a particular company together with limit
        """
        # get the extension_id
        extension = Extension.get_extension_id_by_name(extension_name)

        company_extension = ICExtensions(company.id, extension.id,
                                         details['free_limit'],
                                         details['max_limit'], details['rate'])
        company_extension.save()
        """
        Send success response
        """
        response_msg = helper.make_rest_success_response(
            "Extension added successfully")
        return make_response(response_msg, 200)
コード例 #8
0
ファイル: Benefits.py プロジェクト: f0rtun3/nexure-backend
    def post(self):
        # benefits handler
        details = policy_parser.parse_args()
        # get the current agency details
        uid = get_jwt_identity()
        # use the uid to get company through the company contact_id
        company = InsuranceCompany.get_company_by_contact_person(uid)
        # First add the benefit to the benefits table, regardless of insurance company
        exisiting_benefits = Benefit.get_all_benefits()
        names = [benefit['name'] for benefit in exisiting_benefits]
        benefit_name = details['name']

        # check whether the benefits to be added already exist
        if benefit_name not in names:
            new_benefit = Benefit(benefit_name)
            new_benefit.save()

        # Store benefits offered by a particular company together with limit
        # get the benefit_id
        benefit = Benefit.get_benefit_by_name(benefit_name)

        company_benefit = ICBenefits(company.id, benefit.id,
                                     details['free_limit'],
                                     details['max_limit'], details['rate'])
        company_benefit.save()

        # Send success response
        response_msg = helper.make_rest_success_response(
            "Benefit added successfully")
        return make_response(response_msg, 200)
コード例 #9
0
    def post(self):
        # get the user details from the request sent by the client
        user_details = user_parser.parse_args()
        # check if the user exists before registering them
        user_db_row = User.get_user_by_email(user_details['email'])
        if user_db_row:
            err_msg = f"{user_details['email']} already exists"
            response_msg = helper.make_rest_fail_response(err_msg)
            return make_response(response_msg, 409)

        # check if user phone number exists
        phone_number = UserProfile.get_profile_by_phone_number(
            user_details["phone"])
        if phone_number:
            err_msg = f"{user_details['phone']} already exists"
            response_msg = helper.make_rest_fail_response(err_msg)
            return make_response(response_msg, 409)

        # save the user authentication details and profile details
        # in their respective database tables
        user_uuid = uuid.uuid4()
        new_user_authentication = User(user_uuid, user_details['email'],
                                       user_details['password'])
        new_user_authentication.save()

        new_user_profile = UserProfile(new_user_authentication.id,
                                       user_details['first_name'],
                                       user_details['last_name'],
                                       user_details['phone'])
        new_user_profile.save()

        new_user_role = UserRolePlacement(
            new_user_authentication.id,
            Role.fetch_role_by_name(user_details['role']))
        new_user_role.save()

        # Account confirmation email generation
        # Save extra user details depending on their role
        role = user_details["role"]
        self.onboard_client(role, new_user_authentication.id, user_details)

        #   Send a confirmation link to the user for account confirmation
        confirmation_code = token_handler.user_account_confirmation_token(
            new_user_authentication.id)
        email_template = helper.generate_confirmation_template(
            application.config['CONFIRMATION_ENDPOINT'], confirmation_code)
        subject = "Your account is inactive, please confirm account or check with your administrator"
        email_text = f"Use this link {application.config['CONFIRMATION_ENDPOINT']}/{confirmation_code}" \
                     f" to confirm your account"

        helper.send_email(user_details['email'], subject, email_template,
                          email_text)

        response_msg = helper.make_rest_success_response(
            "Registration successful, kindly"
            " check your email for confirmation link")
        return make_response(response_msg, 200)
コード例 #10
0
    def post(self):
        # this is the POST request resource to handle user signin

        user_details = user_parser.parse_args()
        # check whether the user exists before confirming
        user_db_row = User.get_user_by_email(user_details['email'])

        if not user_db_row:
            response_msg = helper.make_rest_fail_response(
                "User email does not exist")
            return make_response(response_msg, 404)

        # good, let's go ahead and authenticate the user now
        # we also need to check whether the user account is verified or not
        # we don't want inactive accounts accessing our system
        if user_db_row.check_password_hash(user_details['password']):
            if user_db_row.is_active:
                # generate an access and refresh tokens for the user, for obvious reasons
                # also return the user role as a token claim, we'll need that for subsequent
                # requests from the client
                role = self.get_user_role(user_db_row.id)
                if role in ("IASTF", "BRSTF", "TASTF"):
                    # if the user is a staff,
                    # we need to make sure that the account has not been deactivated
                    # by their respective administrator
                    if staff_handler.check_account_status(
                            role, user_db_row.id) == False:
                        msg = "Your account has been blocked by your administrator"
                        return make_response(
                            helper.make_rest_fail_response(msg), 400)

                auth_tokens = token_handler.create_user_token(
                    user_db_row.id, role)
                response_dict = {
                    "authentication": auth_tokens,
                    "role": role,
                    "is_complete": user_db_row.is_complete
                }
                if role in ("BRSTF", "TASTF", "IASTF"):
                    # if the authenticated user is a staff member,
                    # get the corresponding permissions
                    response_dict[
                        'permission'] = UserPermissions.get_permission_by_user_id(
                            user_db_row.id)

                response_msg = helper.make_rest_success_response(
                    "Welcome", response_dict)
                return make_response(response_msg, 200)
            else:
                response_msg = helper.make_rest_fail_response(
                    "Please confirm your account before signing in.")
                return make_response(response_msg, 400)
        else:
            # wrong credentials passed, return the appropriate message
            response_msg = helper.make_rest_fail_response(
                "Wrong credentials passed, please try again")
            return make_response(response_msg, 400)
コード例 #11
0
 def get(self):
     """
     get all the organization types for organization customer onboard
     :return:
     """
     org_types = OrganizationTypes.get_organization_customer_types()
     msg = "Request was successful"
     response = helper.make_rest_success_response(
         msg, {"organizations": org_types})
     return make_response(response, 200)
コード例 #12
0
    def get(self, object_name):
        bucket_name = app.config['S3_BUCKET']
        client_method = "put_object"
        s3_handler = S3FileHandler(bucket_name, object_name)
        response = s3_handler.generate_pre_signed_url(client_method)
        if response:
            return make_response(
                helper.make_rest_success_response("Success", response), 200)

        return make_response(helper.make_rest_fail_response("Failed"), 500)
コード例 #13
0
    def get(self):
        data = OrganizationTypes.get_organization_customer_types()
        if data:
            message = "Request successful"
            response = helper.make_rest_success_response(message, data)
            return make_response(response, 200)

        message = "No data was found"
        response = helper.make_rest_fail_response(message)
        return make_response(response, 404)
コード例 #14
0
 def get(self):
     counties = County.get_all_counties()
     constituencies = Constituency.get_all_constituencies()
     wards = Ward.get_all_wards()
     response = {
         "counties": counties,
         "constituencies": constituencies,
         "wards": wards
     }
     response = helper.make_rest_success_response("Success", response)
     return make_response(response, 200)
コード例 #15
0
ファイル: Extensions.py プロジェクト: f0rtun3/nexure-backend
    def get(self):
        """
        Get all extensions
        """
        extensions = Extension.get_all_extensions()
        if extensions:
            response = helper.make_rest_success_response(
                "Extensions", extensions)
            return make_response(response, 200)

        return make_response(
            helper.make_rest_fail_response("No data was found"), 404)
コード例 #16
0
 def get(self):
     """
     generate an unfresh token
     unfortunately this token is limited to certain CRUD operations
     """
     curr_user_id = get_jwt_identity()  # Fetch supervisor_id
     claims = get_jwt_claims()
     role = claims['role']
     new_token = token_handler.refresh_user_token(curr_user_id, role)
     response = {'access_token': new_token}
     return make_response(
         helper.make_rest_success_response("Success", response))
コード例 #17
0
    def get(self):
        """
        Get all loadings
        """
        loadings = Loadings.get_all_loadings()
        if loadings:
            response_msg = helper.make_rest_success_response(
                "Loadings", loadings)
            return make_response(response_msg, 200)

        return make_response(
            helper.make_rest_fail_response("No data was found"), 404)
コード例 #18
0
ファイル: Benefits.py プロジェクト: f0rtun3/nexure-backend
    def get(self):
        """
        Get all benefits
        """
        benefits = Benefit.get_all_benefits()
        if benefits:
            response_msg = helper.make_rest_success_response(
                "Benefits", benefits)
            return make_response(response_msg, 200)

        return make_response(
            helper.make_rest_fail_response("No data was found"), 404)
コード例 #19
0
    def delete(self):
        """
        deactivate the user account
        :return:
        """
        role = get_jwt_claims()['role']
        customer = json.dumps(customer_parser.parse_args())
        cust_no = customer['cust_no']

        # update the customer agency relationship if activated
        self.delete_cust_agency_relationship(role, cust_no)
        response = helper.make_rest_success_response("User was deleted")
        return make_response(response, 200)
コード例 #20
0
    def put(self):
        """
        authentication token is sent here for confirmation
        token must be valid for account to be activated
        """
        # the user id is needed to needed to know the user whose account we are activating
        user_id = get_jwt_identity()
        user_row = User.get_user_by_id(user_id)
        if user_row:
            if user_row.is_active:
                response = helper.make_rest_success_response(
                    "Your account is already active, please login")
                return make_response(response, 200)
            data = {'is_active': True}
            user_row.update(data)
            response = helper.make_rest_success_response(
                "Your account has been activated, you can now log in")
            return make_response(response, 200)

        # the user has not been found in the database
        response = helper.make_rest_fail_response("User does not exist")
        return make_response(response, 404)
コード例 #21
0
    def get(self, master_id):
        """
        get the master policy and associated child policies
        :return:
        """
        result = MasterController.fetch_master_policy(master_id)
        if result:
            return make_response(
                helper.make_rest_success_response("Successfully fetched",
                                                  result), 200)

        return make_response(
            helper.make_rest_fail_response("Policy was not found"), 404)
コード例 #22
0
    def get(self, object_name):
        """
        get the presigned url to fetch file from s3 resource
        :param object_name {String} the name of object to be uploaded
        """
        bucket_name = app.config['S3_BUCKET']
        s3_handler = S3FileHandler(bucket_name, object_name)
        response = s3_handler.generate_pre_signed_url()
        if response:
            return make_response(
                helper.make_rest_success_response("Success", response), 200)

        return make_response(helper.make_rest_fail_response("Failed"), 500)
コード例 #23
0
ファイル: Cars.py プロジェクト: f0rtun3/nexure-backend
    def get(self):
        """
        Get all cars classified under a particular car make
        """
        # get car makes
        cars = CarMake.get_all_car_makes()
        if cars:
            response = helper.make_rest_success_response(
                "Success", {"cars": cars})
            return make_response(response, 200)

        return make_response(
            helper.make_rest_fail_response("No data was found"), 404)
コード例 #24
0
    def put(self):
        """
        update staff details
        may be user permissions or to block staff member account
        """
        staff_details = user_parser.parse_args()
        staff = User.get_user_by_email(staff_details['email'])

        if staff_details['email'] and not staff:
            response_msg = helper.make_rest_fail_response(
                "User does not exist")
            return make_response(response_msg, 404)

        if staff_details['permissions']:
            if user_update.update_staff_permissions(
                    staff.id, staff_details['permissions']):
                response_msg = helper.make_rest_success_response(
                    "Update successful!")
                return make_response(response_msg, 200)
            else:
                response_msg = helper.make_rest_success_response(
                    "Failed to update staff permissions")
                return make_response(response_msg, 500)

        if type(staff_details['is_active']) == bool:
            # de/activate staff account
            claims = get_jwt_claims()
            role = claims['role']
            if staff_handler.update_account_status(role,
                                                   staff_details['staff_id'],
                                                   staff_details['is_active']):
                return make_response(
                    helper.make_rest_success_response("Update successful"),
                    200)
            else:
                return make_response(
                    helper.make_rest_fail_response(staff_details['is_active']),
                    500)
コード例 #25
0
    def get(self):
        """
        get user profile details
        """
        user_id = get_jwt_identity()
        claims = get_jwt_claims()
        role = claims['role']
        profile_data = self.fetch_profile_data(role, user_id)
        if profile_data is None:
            response = helper.make_rest_fail_response("No user was found")
            return make_response(response, 404)

        response = helper.make_rest_success_response(None, profile_data)
        return make_response(response, 200)
コード例 #26
0
    def get(self, customer_number):
        """
        get the customer active child policies
        this is needed for the payments module where user's active policy payments will be tracked
        :return:
        """
        customers = ChildPolicy.get_child_policies(customer_number)
        if customers:
            return make_response(
                helper.make_rest_success_response("success", customers), 200)

        return make_response(
            helper.make_rest_fail_response("No customer policies were found"),
            404)
コード例 #27
0
    def get(self):
        # get list of staff associated with a particular agency
        # first get agent_id
        uid = get_jwt_identity()

        # get user role so that you can use it to get the agency_id
        claims = get_jwt_claims()
        role = claims['role']
        # get company_id
        company_id = staff_handler.get_agency_id(role, uid)
        # get list of staff associated with company
        company_staff = self.get_agency_staff(role, company_id)

        response = helper.make_rest_success_response(
            "Success", {"staff_list": company_staff})
        return make_response(response, 200)
コード例 #28
0
    def get(self, company_id):
        # get the company linked to the associated company
        company = InsuranceCompany.get_by_associated_company(company_id)
        # get the benefits, loadings and extensions

        benefits = ICBenefits.get_benefits_by_company_id(company.id)
        loadings = ICLoadings.get_loadings_by_company_id(company.id)
        extensions = ICExtensions.get_extensions_by_company_id(company.id)
        data = {
            "benefits": benefits,
            "loadings": loadings,
            "extensions": extensions,
            "discount": company.ncd_rate,
            "rate": company.rate
        }
        response_msg = helper.make_rest_success_response("Success", data)
        return make_response(response_msg, 200)
コード例 #29
0
    def post(self):
        """
        make a new policy payment to the database
        """
        payment_details = payments_parser.parse_args()
        new_installment = PolicyPayments(
            payment_details['transaction_type'], payment_details['amount'],
            payment_details['customer_no'], payment_details['child_policy_id'],
            payment_details['next_date'], payment_details['amount_due'],
            payment_details['transaction_code'])
        if new_installment.add():
            response_message = "Successfully made new installment"
            return make_response(
                helper.make_rest_success_response(response_message), 200)

        response_message = "Failed to make new payment installmnet"
        return make_response(helper.make_rest_fail_response(response_message),
                             500)
コード例 #30
0
    def get(self, child_id):
        """
        Process request to get all unselected benefits and extensions
        of a policy holder, and the rest of the policy details
        :param policy_id:
        :return:
        """
        child = ChildPolicy.get_child_by_id(child_id).serialize()
        result = ChildController.get_unselected_benefits_extensions(child_id)
        if child:
            if result:
                child.update({"unselected_benefits": result})

            return make_response(
                helper.make_rest_success_response("Success", child), 200)

        else:
            return make_response(
                helper.make_rest_fail_response("Policy does not exist"), 404)