bckend fix
This commit is contained in:
@@ -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