bckend fix
This commit is contained in:
@@ -4,7 +4,7 @@ from app.api.services.base_service import BaseService
|
||||
from sqlalchemy import func, desc
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from app.extensions import db
|
||||
from app.models import OfficeUsers
|
||||
from app.models import OfficeUsers, CustomTemplates
|
||||
|
||||
|
||||
class OfficeTemplatesService(BaseService):
|
||||
@@ -78,23 +78,20 @@ class OfficeTemplatesService(BaseService):
|
||||
def create_custom_template(data):
|
||||
logger.info('create_custom_template')
|
||||
try:
|
||||
# office_users = OfficeUsers.get_office_users_list()
|
||||
# office_users_data = []
|
||||
# if office_users:
|
||||
# for t in office_users:
|
||||
# office_users_data.append({
|
||||
# 'id': t.id,
|
||||
# 'uid': t.uid,
|
||||
# 'username': t.username,
|
||||
# 'firstname': t.firstname,
|
||||
# 'lastname': t.lastname,
|
||||
# 'acc_level': t.acc_level,
|
||||
# 'status': t.status,
|
||||
# 'added': t.added.isoformat() if t.added else None
|
||||
# })
|
||||
custom_id = data.get('custom_id', '')
|
||||
provision_name = data.get('provision_name', '')
|
||||
|
||||
similarName = CustomTemplates.get_template_by_custom_id(custom_id)
|
||||
if not similarName and provision_name !='':
|
||||
# with db.session.begin():
|
||||
custom_data = CustomTemplates.create_template(custom_id, provision_name)
|
||||
else:
|
||||
custom_data ={
|
||||
"error": "Possible duplicate"
|
||||
}
|
||||
|
||||
office_users_result = {
|
||||
"set_office_user_template": [],
|
||||
"custom_data": custom_data,
|
||||
}
|
||||
return office_users_result
|
||||
|
||||
|
||||
@@ -3,7 +3,14 @@ from app.extensions import db
|
||||
from app.models.charge import Charge
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import logging
|
||||
from sqlalchemy import and_, or_, not_
|
||||
from sqlalchemy.sql import func
|
||||
import uuid
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class CustomTemplates(db.Model):
|
||||
__tablename__ = 'custom_templates'
|
||||
@@ -16,12 +23,31 @@ class CustomTemplates(db.Model):
|
||||
|
||||
@classmethod
|
||||
def get_template_by_custom_id(cls, custom_id):
|
||||
templates = cls.query.filter_by(custom_id=str(custom_id)).all()
|
||||
|
||||
templates = cls.query.filter_by(custom_id=str(custom_id)).first()
|
||||
if not templates:
|
||||
raise ValueError(f"Templates with Custom ID {custom_id} not found")
|
||||
return None
|
||||
return templates
|
||||
|
||||
@classmethod
|
||||
def create_template(cls, custom_id,provision_name):
|
||||
custom_data = cls(
|
||||
uid=str(uuid.uuid4()),
|
||||
custom_id=custom_id,
|
||||
provision_name=provision_name,
|
||||
added=datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
try:
|
||||
logger.info(f" About to Insert Subscription Data {custom_data.custom_id} ")
|
||||
db.session.add(custom_data)
|
||||
db.session.flush()
|
||||
except IntegrityError as err:
|
||||
logger.error(f" Error inserting custom data {err} -- ")
|
||||
raise ValueError(f"Database integrity error: {err}")
|
||||
return custom_data
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_custom_template_for_office(cls, filters):
|
||||
templates = cls.query.all()
|
||||
|
||||
Reference in New Issue
Block a user