Added products
This commit is contained in:
@@ -2,16 +2,17 @@ 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 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.models import MembersProducts, Products, 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
|
||||
# from app.api.schemas.register import RegisterSchema
|
||||
from app.api.schemas.products import ProductsSchema
|
||||
from app.api.schemas.user import UserSchema
|
||||
|
||||
@@ -44,19 +45,20 @@ class ProductsService(BaseService):
|
||||
token = validated_data.get('token')
|
||||
uid = validated_data.get('uid')
|
||||
|
||||
user_id = 1 # current_user["user"]["id"]
|
||||
PRODUCT_LIST = f"""SELECT p.id,p.uid,p.product_id,p.name,p.description,p.status,p.banner,
|
||||
mp.status AS prov_status,
|
||||
(CASE WHEN mp.status =6 THEN 'Preparing' WHEN mp.status=7 THEN 'Active' ELSE 'Activate Now' END) AS status_text
|
||||
FROM products p
|
||||
LEFT JOIN members_products mp ON mp.product_id = p.product_id
|
||||
AND mp.member_id ={user_id}
|
||||
ORDER BY p.id ASC"""
|
||||
member_id = 1 # current_user["user"]["id"]
|
||||
# PRODUCT_LIST = f"""SELECT p.id,p.uid,p.product_id,p.name,p.description,p.status,p.banner,
|
||||
# mp.status AS prov_status,
|
||||
# (CASE WHEN mp.status =6 THEN 'Preparing' WHEN mp.status=7 THEN 'Active' ELSE 'Activate Now' END) AS status_text
|
||||
# FROM products p
|
||||
# LEFT JOIN members_products mp ON mp.product_id = p.product_id
|
||||
# AND mp.member_id ={user_id}
|
||||
# ORDER BY p.id ASC"""
|
||||
#
|
||||
# logger.error(f"Product list query (PRODUCT_LIST: {PRODUCT_LIST})")
|
||||
#
|
||||
# data = db.session.execute(PRODUCT_LIST)
|
||||
data = Products.get_user_product_list(member_id)
|
||||
|
||||
logger.error(f"Product list query (PRODUCT_LIST: {PRODUCT_LIST})")
|
||||
|
||||
data = db.session.execute(PRODUCT_LIST)
|
||||
|
||||
# Simulate processing
|
||||
response_data = {
|
||||
"data": data.fetchall(),
|
||||
@@ -82,38 +84,3 @@ class ProductsService(BaseService):
|
||||
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