members profile

This commit is contained in:
CHIEFSOFT\ameye
2025-08-14 11:55:41 -04:00
parent 8dcb589716
commit a7cc90e75a
5 changed files with 164 additions and 7 deletions
+18
View File
@@ -48,6 +48,24 @@ ALTER TABLE members ADD stripe_customer_id VARCHAR(100)
ALTER TABLE members ADD profile_completed timestamp without time zone DEFAULT NULL;
CREATE TABLE members_profile(
id SERIAL,
uid uuid DEFAULT uuid_generate_v4(),
member_id INT REFERENCES members(id) UNIQUE NOT NULL,
practice VARCHAR(100) NOT NULL,
specialization VARCHAR(100) NOT NULL,
introduction TEXT,
added timestamp without time zone DEFAULT now(),
updated timestamp without time zone DEFAULT now()
);
ALTER TABLE ONLY members_profile
ADD CONSTRAINT members_members_profile_id_key UNIQUE (id);
ALTER TABLE members_profile OWNER TO merms_panel
-- UPDATE members SET account_name ='This is the account name';
-- UPDATE members SET firstname ='Firstname';
+32 -6
View File
@@ -7,7 +7,7 @@ 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 Members, MembersActions
from app.models import Members, MembersActions, MembersProfile
# 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
@@ -153,14 +153,40 @@ class AccountService(BaseService):
practice = str(validated_data.get('practice'))
specialization = str(validated_data.get('specialization'))
introduction = str(validated_data.get('introduction'))
profile_uid = ''
profile_completed = None
member = Members.get_member_by_uid(uid)
if member:
# Simulate processing
member_data = {
"member_id": member.id,
"uid": str(uid),
"username": member.username,
"account_name": member.account_name,
"firstname":member.firstname,
"lastname": member.lastname,
"email": member.email,
"room": member.uid,
"token": user_token
}
current_profile = MembersProfile.get_member_profile_by_member_id(member.id)
if current_profile is not None:
profile_uid=current_profile.uid
profile_completed = member.profile_completed
else:
profle_result = MembersProfile.create_member_profile(member.id, practice, specialization, introduction)
if profle_result:
profile_uid = profle_result.uid
if profile_uid is not None and profile_uid != '':
profile_completed = Members.set_member_profile_completed(member_data['uid'])
calendar_data = {
"last_update": datetime.datetime.utcnow(),
"start_profile_called": "Doing nothing yet"
result_data = {
"profile_completed": profile_completed,
"profile_uid": profile_uid,
"last_update": datetime.datetime.utcnow()
}
return ResponseHelper.success(data=calendar_data)
return ResponseHelper.success(data=result_data)
except ValidationError as err:
+3 -1
View File
@@ -21,13 +21,15 @@ from .provision_actions import ProvisionActions
from .password_reset import PasswordReset
from .member_product_refresh import MembersProductsRefresh
from .members_products_settings import MembersProductsSettings
from .members_profile import MembersProfile
__all__ = ['Members','Customer', 'Account', 'Products',
'MembersProducts', 'MembersActions', 'MembersPending', 'ProductsDetails',
'ProvisionActions', 'MembersProductsRefresh','MembersProductsSettings',
'PasswordReset',
'PasswordReset','MembersProfile',
'Loan', 'Transaction', 'Repayment',
'LoanCharge', 'Offer', 'Charge', 'RACCheck', 'LoanRepaymentSchedule',
'TransactionOffer', 'RepaymentsData', 'Salary']
+11
View File
@@ -61,6 +61,17 @@ class Members(db.Model):
return None
return member
@classmethod
def set_member_profile_completed(cls, uid):
member = cls.query.filter_by(uid=str(uid)).first()
if not member:
logger.info(f"User UID = {uid} found")
raise ValueError(f"Member with UID {uid} does not exist.")
member.profile_completed = datetime.now(timezone.utc)
return member.profile_completed
@classmethod
def add_member(cls, firstname, lastname, email, username,password, country):
+100
View File
@@ -0,0 +1,100 @@
from datetime import datetime, timezone, timedelta
from itertools import product
from app.extensions import db
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import relationship
from dateutil.relativedelta import relativedelta
from datetime import timedelta
import logging
from sqlalchemy import and_, or_, not_
from sqlalchemy.sql import func
import uuid
logger = logging.getLogger(__name__)
class MembersProfile(db.Model):
__tablename__ = 'members_profile'
id = db.Column(
db.Integer,
primary_key=True,
autoincrement=True,
)
uid = db.Column(db.String(150), nullable=False)
member_id = db.Column(db.Integer, nullable=False)
practice = db.Column(db.String(100), nullable=False)
specialization = db.Column(db.String(100), nullable=False)
introduction = db.Column(db.String(3500), nullable=True)
added = db.Column(db.DateTime(timezone=True), server_default=func.now())
updated = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
@classmethod
def get_member_profile_by_member_id(cls, member_id):
member_profile = cls.query.filter_by(member_id=str(member_id)).first()
if not member_profile:
return None
return member_profile
@classmethod
def get_member_profile_by_profile_uid(cls, profile_uid):
member_profile = cls.query.filter_by(uid=str(profile_uid)).first()
if not member_profile:
return None
return member_profile
@classmethod
def get_member_product_by_product_member_id(cls, member_id, product_id):
member_product = cls.query.filter_by(member_id=str(member_id), product_id=str(product_id)).first()
if not member_product:
return None
return member_product
@classmethod
def create_member_profile(cls, member_id ,practice,specialization,introduction):
# Create the subscription
'''
merms_panel=# select * from members_profile;
id | uid | member_id | practice | specialization | introduction | added | updated
----+-----+-----------+----------+----------------+--------------+-------+---------
(0 rows)
'''
logger.info(f" Data for Profile Data {member_id} ,{practice} ,{specialization}, {introduction} ")
profile_data = cls(
uid=str(uuid.uuid4()),
member_id=member_id,
practice=practice,
specialization=specialization,
introduction=introduction,
added=datetime.now(timezone.utc),
updated=datetime.now(timezone.utc)
)
try:
logger.info(f" About to Insert Profile Data {profile_data.member_id} ")
db.session.add(profile_data)
db.session.flush()
except IntegrityError as err:
logger.error(f" Error inserting profile data {err} -- ")
raise ValueError(f"Database integrity error: {err}")
return profile_data
def to_dict(self):
"""
Convert the Loan object to a dictionary format for JSON serialization.
"""
return {
'id': self.id,
'uid': self.uid,
'member_id': self.member_id,
'practice': self.practice,
'specialization': self.specialization,
'introduction': self.dns_group,
'added': self.added,
'updated': self.updated
}
def __repr__(self):
return f'<MembersProfile {self.id}>'