register
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from flask import Blueprint, request, jsonify, send_from_directory
|
from flask import Blueprint, request, jsonify, send_from_directory
|
||||||
from app.api.services import (
|
from app.api.services import (
|
||||||
LoginService,
|
LoginService,
|
||||||
|
RegisterService,
|
||||||
EligibilityCheckService,
|
EligibilityCheckService,
|
||||||
SelectOfferService,
|
SelectOfferService,
|
||||||
ProvideLoanService,
|
ProvideLoanService,
|
||||||
@@ -48,7 +49,6 @@ def serve_paths(filename):
|
|||||||
@jwt_required()
|
@jwt_required()
|
||||||
def merms_login():
|
def merms_login():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
# logger.info(f"EligibilityCheck request received: {data}")
|
|
||||||
response = LoginService.process_request(data)
|
response = LoginService.process_request(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@@ -56,8 +56,7 @@ def merms_login():
|
|||||||
@jwt_required()
|
@jwt_required()
|
||||||
def merms_register():
|
def merms_register():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
# logger.info(f"EligibilityCheck request received: {data}")
|
response = RegisterService.process_request(data)
|
||||||
response = LoginService.process_request(data)
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# EligibilityCheck Endpoint
|
# EligibilityCheck Endpoint
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from marshmallow import Schema, fields
|
||||||
|
|
||||||
|
class RegisterSchema(Schema):
|
||||||
|
email = fields.Str(required=True)
|
||||||
|
firstname = fields.Str(required=True)
|
||||||
|
lastname = fields.Str(required=True)
|
||||||
|
isChecked = fields.Str(required=True)
|
||||||
@@ -7,4 +7,5 @@ from app.api.services.customer_consent import CustomerConsentService
|
|||||||
from app.api.services.notification_callback import NotificationCallbackService
|
from app.api.services.notification_callback import NotificationCallbackService
|
||||||
from app.api.services.authorization import AuthorizationService
|
from app.api.services.authorization import AuthorizationService
|
||||||
from app.api.services.offer_analysis import OfferAnalysis
|
from app.api.services.offer_analysis import OfferAnalysis
|
||||||
from app.api.services.login import LoginService
|
from app.api.services.login import LoginService
|
||||||
|
from app.api.services.register import RegisterService
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
from flask import session, jsonify
|
||||||
|
from app.models.loan import Loan
|
||||||
|
from app.utils.logger import logger
|
||||||
|
from app.api.services.base_service import BaseService
|
||||||
|
from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||||
|
from marshmallow import ValidationError
|
||||||
|
from app.api.enums import TransactionType
|
||||||
|
from app.api.integrations import SimbrellaIntegration
|
||||||
|
from app.extensions import db
|
||||||
|
from app.models import Offer, RACCheck, Members
|
||||||
|
from app.api.services.offer_analysis import OfferAnalysis
|
||||||
|
from app.api.helpers.response_helper import ResponseHelper
|
||||||
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
from app.api.schemas.register import RegisterSchema
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import jwt
|
||||||
|
import random
|
||||||
|
from app.config import Config
|
||||||
|
|
||||||
|
|
||||||
|
class RegisterService(BaseService):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def process_request(data):
|
||||||
|
"""
|
||||||
|
Process the Login request.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data (dict): The request data.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A standardized response.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with db.session.begin():
|
||||||
|
|
||||||
|
validated_data = RegisterService.validate_data(data, RegisterSchema())
|
||||||
|
# username = validated_data.get('username')
|
||||||
|
# password = validated_data.get('password')
|
||||||
|
|
||||||
|
|
||||||
|
# Simulate processing
|
||||||
|
response_data = {
|
||||||
|
"member_id": 0,
|
||||||
|
"uid": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseHelper.success(data=response_data)
|
||||||
|
|
||||||
|
except ValidationError as err:
|
||||||
|
|
||||||
|
logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}")
|
||||||
|
db.session.rollback()
|
||||||
|
return ResponseHelper.unprocessable_entity(result_description="Validation exception")
|
||||||
|
|
||||||
|
except ValueError as err:
|
||||||
|
logger.error(f"{getattr(err, 'messages', str(err))}")
|
||||||
|
db.session.rollback()
|
||||||
|
return ResponseHelper.error(result_description=str(err))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||||
|
db.session.rollback()
|
||||||
|
return ResponseHelper.internal_server_error()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_loan_limits(customer_id):
|
||||||
|
"""
|
||||||
|
Checks if a customer has exceeded the loan limits for given offer.
|
||||||
|
"""
|
||||||
|
loan = Loan.get_customer_last_loan(customer_id)
|
||||||
|
|
||||||
|
if not loan:
|
||||||
|
return True
|
||||||
|
|
||||||
|
offer_id = loan.offer_id[:5]
|
||||||
|
|
||||||
|
offer = Offer.get_offer_by_id(offer_id)
|
||||||
|
if not offer:
|
||||||
|
logger.error(f"Offer not found for offer_id: {offer_id} (customer_id: {customer_id})")
|
||||||
|
return False
|
||||||
|
|
||||||
|
daily_count = Loan.get_daily_loan_count(customer_id, offer.product_id)
|
||||||
|
|
||||||
|
logger.info(f"daily_count: {daily_count}, Max: {offer.max_daily_loans}")
|
||||||
|
|
||||||
|
if offer.max_daily_loans is not None and daily_count >= offer.max_daily_loans:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# {
|
||||||
|
# "email": "ameye@chiefsoft.com",
|
||||||
|
# "firstname": "Olusesan",
|
||||||
|
# "lastname": "Ameye",
|
||||||
|
# "isChecked": true
|
||||||
|
# }
|
||||||
Reference in New Issue
Block a user