ajuste de cruds incompleto
This commit is contained in:
67
output/generated/services/branches_service.py
Normal file
67
output/generated/services/branches_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.branches.models import Branches
|
||||
from app.modules.branches.schema import
|
||||
|
||||
|
||||
class BranchesService:
|
||||
@staticmethod
|
||||
def create_branches(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_branches = Branches(**data.dict())
|
||||
db.add(new_branches)
|
||||
db.commit()
|
||||
db.refresh(new_branches)
|
||||
return new_branches
|
||||
|
||||
@staticmethod
|
||||
def get_branches(db: Session, branches_id: int, current_user):
|
||||
branches = db.query(Branches).filter(Branches.id == branches_id).first()
|
||||
if not branches:
|
||||
raise ValueError("branches no encontrado")
|
||||
return branches
|
||||
|
||||
@staticmethod
|
||||
def update_branches(db: Session, branches_id: int, data: , current_user):
|
||||
branches = db.query(Branches).filter(Branches.id == branches_id).first()
|
||||
if not branches:
|
||||
raise ValueError("branches no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este branches")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(branches, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(branches)
|
||||
return branches
|
||||
|
||||
@staticmethod
|
||||
def delete_branches(db: Session, branches_id: int, current_user):
|
||||
branches = db.query(Branches).filter(Branches.id == branches_id).first()
|
||||
if not branches:
|
||||
raise ValueError("branches no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este branches")
|
||||
|
||||
try:
|
||||
branches.is_active = False
|
||||
branches.deleted_at = datetime.utcnow()
|
||||
branches.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(branches)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el branches: {e}")
|
||||
|
||||
return {"message": "branches eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/client_service.py
Normal file
67
output/generated/services/client_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.client.models import Client
|
||||
from app.modules.client.schema import
|
||||
|
||||
|
||||
class ClientService:
|
||||
@staticmethod
|
||||
def create_client(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_client = Client(**data.dict())
|
||||
db.add(new_client)
|
||||
db.commit()
|
||||
db.refresh(new_client)
|
||||
return new_client
|
||||
|
||||
@staticmethod
|
||||
def get_client(db: Session, client_id: int, current_user):
|
||||
client = db.query(Client).filter(Client.id == client_id).first()
|
||||
if not client:
|
||||
raise ValueError("client no encontrado")
|
||||
return client
|
||||
|
||||
@staticmethod
|
||||
def update_client(db: Session, client_id: int, data: , current_user):
|
||||
client = db.query(Client).filter(Client.id == client_id).first()
|
||||
if not client:
|
||||
raise ValueError("client no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este client")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(client, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(client)
|
||||
return client
|
||||
|
||||
@staticmethod
|
||||
def delete_client(db: Session, client_id: int, current_user):
|
||||
client = db.query(Client).filter(Client.id == client_id).first()
|
||||
if not client:
|
||||
raise ValueError("client no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este client")
|
||||
|
||||
try:
|
||||
client.is_active = False
|
||||
client.deleted_at = datetime.utcnow()
|
||||
client.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(client)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el client: {e}")
|
||||
|
||||
return {"message": "client eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/coments_service.py
Normal file
67
output/generated/services/coments_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.coments.models import Coments
|
||||
from app.modules.coments.schema import
|
||||
|
||||
|
||||
class ComentsService:
|
||||
@staticmethod
|
||||
def create_coments(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_coments = Coments(**data.dict())
|
||||
db.add(new_coments)
|
||||
db.commit()
|
||||
db.refresh(new_coments)
|
||||
return new_coments
|
||||
|
||||
@staticmethod
|
||||
def get_coments(db: Session, coments_id: int, current_user):
|
||||
coments = db.query(Coments).filter(Coments.id == coments_id).first()
|
||||
if not coments:
|
||||
raise ValueError("coments no encontrado")
|
||||
return coments
|
||||
|
||||
@staticmethod
|
||||
def update_coments(db: Session, coments_id: int, data: , current_user):
|
||||
coments = db.query(Coments).filter(Coments.id == coments_id).first()
|
||||
if not coments:
|
||||
raise ValueError("coments no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este coments")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(coments, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(coments)
|
||||
return coments
|
||||
|
||||
@staticmethod
|
||||
def delete_coments(db: Session, coments_id: int, current_user):
|
||||
coments = db.query(Coments).filter(Coments.id == coments_id).first()
|
||||
if not coments:
|
||||
raise ValueError("coments no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este coments")
|
||||
|
||||
try:
|
||||
coments.is_active = False
|
||||
coments.deleted_at = datetime.utcnow()
|
||||
coments.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(coments)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el coments: {e}")
|
||||
|
||||
return {"message": "coments eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/configuration_service.py
Normal file
67
output/generated/services/configuration_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.configuration.models import Configuration
|
||||
from app.modules.configuration.schema import
|
||||
|
||||
|
||||
class ConfigurationService:
|
||||
@staticmethod
|
||||
def create_configuration(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_configuration = Configuration(**data.dict())
|
||||
db.add(new_configuration)
|
||||
db.commit()
|
||||
db.refresh(new_configuration)
|
||||
return new_configuration
|
||||
|
||||
@staticmethod
|
||||
def get_configuration(db: Session, configuration_id: int, current_user):
|
||||
configuration = db.query(Configuration).filter(Configuration.id == configuration_id).first()
|
||||
if not configuration:
|
||||
raise ValueError("configuration no encontrado")
|
||||
return configuration
|
||||
|
||||
@staticmethod
|
||||
def update_configuration(db: Session, configuration_id: int, data: , current_user):
|
||||
configuration = db.query(Configuration).filter(Configuration.id == configuration_id).first()
|
||||
if not configuration:
|
||||
raise ValueError("configuration no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este configuration")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(configuration, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(configuration)
|
||||
return configuration
|
||||
|
||||
@staticmethod
|
||||
def delete_configuration(db: Session, configuration_id: int, current_user):
|
||||
configuration = db.query(Configuration).filter(Configuration.id == configuration_id).first()
|
||||
if not configuration:
|
||||
raise ValueError("configuration no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este configuration")
|
||||
|
||||
try:
|
||||
configuration.is_active = False
|
||||
configuration.deleted_at = datetime.utcnow()
|
||||
configuration.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(configuration)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el configuration: {e}")
|
||||
|
||||
return {"message": "configuration eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/credits_service.py
Normal file
67
output/generated/services/credits_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.credits.models import Credits
|
||||
from app.modules.credits.schema import
|
||||
|
||||
|
||||
class CreditsService:
|
||||
@staticmethod
|
||||
def create_credits(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_credits = Credits(**data.dict())
|
||||
db.add(new_credits)
|
||||
db.commit()
|
||||
db.refresh(new_credits)
|
||||
return new_credits
|
||||
|
||||
@staticmethod
|
||||
def get_credits(db: Session, credits_id: int, current_user):
|
||||
credits = db.query(Credits).filter(Credits.id == credits_id).first()
|
||||
if not credits:
|
||||
raise ValueError("credits no encontrado")
|
||||
return credits
|
||||
|
||||
@staticmethod
|
||||
def update_credits(db: Session, credits_id: int, data: , current_user):
|
||||
credits = db.query(Credits).filter(Credits.id == credits_id).first()
|
||||
if not credits:
|
||||
raise ValueError("credits no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este credits")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(credits, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(credits)
|
||||
return credits
|
||||
|
||||
@staticmethod
|
||||
def delete_credits(db: Session, credits_id: int, current_user):
|
||||
credits = db.query(Credits).filter(Credits.id == credits_id).first()
|
||||
if not credits:
|
||||
raise ValueError("credits no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este credits")
|
||||
|
||||
try:
|
||||
credits.is_active = False
|
||||
credits.deleted_at = datetime.utcnow()
|
||||
credits.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(credits)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el credits: {e}")
|
||||
|
||||
return {"message": "credits eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/edos_service.py
Normal file
67
output/generated/services/edos_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.edos.models import EDOS
|
||||
from app.modules.edos.schema import
|
||||
|
||||
|
||||
class EDOSService:
|
||||
@staticmethod
|
||||
def create_edos(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_edos = EDOS(**data.dict())
|
||||
db.add(new_edos)
|
||||
db.commit()
|
||||
db.refresh(new_edos)
|
||||
return new_edos
|
||||
|
||||
@staticmethod
|
||||
def get_edos(db: Session, edos_id: int, current_user):
|
||||
edos = db.query(EDOS).filter(EDOS.id == edos_id).first()
|
||||
if not edos:
|
||||
raise ValueError("edos no encontrado")
|
||||
return edos
|
||||
|
||||
@staticmethod
|
||||
def update_edos(db: Session, edos_id: int, data: , current_user):
|
||||
edos = db.query(EDOS).filter(EDOS.id == edos_id).first()
|
||||
if not edos:
|
||||
raise ValueError("edos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este edos")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(edos, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(edos)
|
||||
return edos
|
||||
|
||||
@staticmethod
|
||||
def delete_edos(db: Session, edos_id: int, current_user):
|
||||
edos = db.query(EDOS).filter(EDOS.id == edos_id).first()
|
||||
if not edos:
|
||||
raise ValueError("edos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este edos")
|
||||
|
||||
try:
|
||||
edos.is_active = False
|
||||
edos.deleted_at = datetime.utcnow()
|
||||
edos.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(edos)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el edos: {e}")
|
||||
|
||||
return {"message": "edos eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/efos_service.py
Normal file
67
output/generated/services/efos_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.efos.models import EFOS
|
||||
from app.modules.efos.schema import
|
||||
|
||||
|
||||
class EFOSService:
|
||||
@staticmethod
|
||||
def create_efos(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_efos = EFOS(**data.dict())
|
||||
db.add(new_efos)
|
||||
db.commit()
|
||||
db.refresh(new_efos)
|
||||
return new_efos
|
||||
|
||||
@staticmethod
|
||||
def get_efos(db: Session, efos_id: int, current_user):
|
||||
efos = db.query(EFOS).filter(EFOS.id == efos_id).first()
|
||||
if not efos:
|
||||
raise ValueError("efos no encontrado")
|
||||
return efos
|
||||
|
||||
@staticmethod
|
||||
def update_efos(db: Session, efos_id: int, data: , current_user):
|
||||
efos = db.query(EFOS).filter(EFOS.id == efos_id).first()
|
||||
if not efos:
|
||||
raise ValueError("efos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este efos")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(efos, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(efos)
|
||||
return efos
|
||||
|
||||
@staticmethod
|
||||
def delete_efos(db: Session, efos_id: int, current_user):
|
||||
efos = db.query(EFOS).filter(EFOS.id == efos_id).first()
|
||||
if not efos:
|
||||
raise ValueError("efos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este efos")
|
||||
|
||||
try:
|
||||
efos.is_active = False
|
||||
efos.deleted_at = datetime.utcnow()
|
||||
efos.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(efos)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el efos: {e}")
|
||||
|
||||
return {"message": "efos eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/feed_service.py
Normal file
67
output/generated/services/feed_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.feed.models import Feed
|
||||
from app.modules.feed.schema import
|
||||
|
||||
|
||||
class FeedService:
|
||||
@staticmethod
|
||||
def create_feed(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_feed = Feed(**data.dict())
|
||||
db.add(new_feed)
|
||||
db.commit()
|
||||
db.refresh(new_feed)
|
||||
return new_feed
|
||||
|
||||
@staticmethod
|
||||
def get_feed(db: Session, feed_id: int, current_user):
|
||||
feed = db.query(Feed).filter(Feed.id == feed_id).first()
|
||||
if not feed:
|
||||
raise ValueError("feed no encontrado")
|
||||
return feed
|
||||
|
||||
@staticmethod
|
||||
def update_feed(db: Session, feed_id: int, data: , current_user):
|
||||
feed = db.query(Feed).filter(Feed.id == feed_id).first()
|
||||
if not feed:
|
||||
raise ValueError("feed no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este feed")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(feed, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(feed)
|
||||
return feed
|
||||
|
||||
@staticmethod
|
||||
def delete_feed(db: Session, feed_id: int, current_user):
|
||||
feed = db.query(Feed).filter(Feed.id == feed_id).first()
|
||||
if not feed:
|
||||
raise ValueError("feed no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este feed")
|
||||
|
||||
try:
|
||||
feed.is_active = False
|
||||
feed.deleted_at = datetime.utcnow()
|
||||
feed.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(feed)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el feed: {e}")
|
||||
|
||||
return {"message": "feed eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/files_service.py
Normal file
67
output/generated/services/files_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.files.models import Files
|
||||
from app.modules.files.schema import
|
||||
|
||||
|
||||
class FilesService:
|
||||
@staticmethod
|
||||
def create_files(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_files = Files(**data.dict())
|
||||
db.add(new_files)
|
||||
db.commit()
|
||||
db.refresh(new_files)
|
||||
return new_files
|
||||
|
||||
@staticmethod
|
||||
def get_files(db: Session, files_id: int, current_user):
|
||||
files = db.query(Files).filter(Files.id == files_id).first()
|
||||
if not files:
|
||||
raise ValueError("files no encontrado")
|
||||
return files
|
||||
|
||||
@staticmethod
|
||||
def update_files(db: Session, files_id: int, data: , current_user):
|
||||
files = db.query(Files).filter(Files.id == files_id).first()
|
||||
if not files:
|
||||
raise ValueError("files no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este files")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(files, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(files)
|
||||
return files
|
||||
|
||||
@staticmethod
|
||||
def delete_files(db: Session, files_id: int, current_user):
|
||||
files = db.query(Files).filter(Files.id == files_id).first()
|
||||
if not files:
|
||||
raise ValueError("files no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este files")
|
||||
|
||||
try:
|
||||
files.is_active = False
|
||||
files.deleted_at = datetime.utcnow()
|
||||
files.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(files)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el files: {e}")
|
||||
|
||||
return {"message": "files eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/invoices_service.py
Normal file
67
output/generated/services/invoices_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.invoices.models import Invoices
|
||||
from app.modules.invoices.schema import
|
||||
|
||||
|
||||
class InvoicesService:
|
||||
@staticmethod
|
||||
def create_invoices(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_invoices = Invoices(**data.dict())
|
||||
db.add(new_invoices)
|
||||
db.commit()
|
||||
db.refresh(new_invoices)
|
||||
return new_invoices
|
||||
|
||||
@staticmethod
|
||||
def get_invoices(db: Session, invoices_id: int, current_user):
|
||||
invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first()
|
||||
if not invoices:
|
||||
raise ValueError("invoices no encontrado")
|
||||
return invoices
|
||||
|
||||
@staticmethod
|
||||
def update_invoices(db: Session, invoices_id: int, data: , current_user):
|
||||
invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first()
|
||||
if not invoices:
|
||||
raise ValueError("invoices no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este invoices")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(invoices, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(invoices)
|
||||
return invoices
|
||||
|
||||
@staticmethod
|
||||
def delete_invoices(db: Session, invoices_id: int, current_user):
|
||||
invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first()
|
||||
if not invoices:
|
||||
raise ValueError("invoices no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este invoices")
|
||||
|
||||
try:
|
||||
invoices.is_active = False
|
||||
invoices.deleted_at = datetime.utcnow()
|
||||
invoices.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(invoices)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el invoices: {e}")
|
||||
|
||||
return {"message": "invoices eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/license_service.py
Normal file
67
output/generated/services/license_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.license.models import License
|
||||
from app.modules.license.schema import
|
||||
|
||||
|
||||
class LicenseService:
|
||||
@staticmethod
|
||||
def create_license(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_license = License(**data.dict())
|
||||
db.add(new_license)
|
||||
db.commit()
|
||||
db.refresh(new_license)
|
||||
return new_license
|
||||
|
||||
@staticmethod
|
||||
def get_license(db: Session, license_id: int, current_user):
|
||||
license = db.query(License).filter(License.id == license_id).first()
|
||||
if not license:
|
||||
raise ValueError("license no encontrado")
|
||||
return license
|
||||
|
||||
@staticmethod
|
||||
def update_license(db: Session, license_id: int, data: , current_user):
|
||||
license = db.query(License).filter(License.id == license_id).first()
|
||||
if not license:
|
||||
raise ValueError("license no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este license")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(license, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(license)
|
||||
return license
|
||||
|
||||
@staticmethod
|
||||
def delete_license(db: Session, license_id: int, current_user):
|
||||
license = db.query(License).filter(License.id == license_id).first()
|
||||
if not license:
|
||||
raise ValueError("license no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este license")
|
||||
|
||||
try:
|
||||
license.is_active = False
|
||||
license.deleted_at = datetime.utcnow()
|
||||
license.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(license)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el license: {e}")
|
||||
|
||||
return {"message": "license eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/locations_service.py
Normal file
67
output/generated/services/locations_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.locations.models import Locations
|
||||
from app.modules.locations.schema import
|
||||
|
||||
|
||||
class LocationsService:
|
||||
@staticmethod
|
||||
def create_locations(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_locations = Locations(**data.dict())
|
||||
db.add(new_locations)
|
||||
db.commit()
|
||||
db.refresh(new_locations)
|
||||
return new_locations
|
||||
|
||||
@staticmethod
|
||||
def get_locations(db: Session, locations_id: int, current_user):
|
||||
locations = db.query(Locations).filter(Locations.id == locations_id).first()
|
||||
if not locations:
|
||||
raise ValueError("locations no encontrado")
|
||||
return locations
|
||||
|
||||
@staticmethod
|
||||
def update_locations(db: Session, locations_id: int, data: , current_user):
|
||||
locations = db.query(Locations).filter(Locations.id == locations_id).first()
|
||||
if not locations:
|
||||
raise ValueError("locations no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este locations")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(locations, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(locations)
|
||||
return locations
|
||||
|
||||
@staticmethod
|
||||
def delete_locations(db: Session, locations_id: int, current_user):
|
||||
locations = db.query(Locations).filter(Locations.id == locations_id).first()
|
||||
if not locations:
|
||||
raise ValueError("locations no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este locations")
|
||||
|
||||
try:
|
||||
locations.is_active = False
|
||||
locations.deleted_at = datetime.utcnow()
|
||||
locations.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(locations)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el locations: {e}")
|
||||
|
||||
return {"message": "locations eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/moves_service.py
Normal file
67
output/generated/services/moves_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.moves.models import Moves
|
||||
from app.modules.moves.schema import
|
||||
|
||||
|
||||
class MovesService:
|
||||
@staticmethod
|
||||
def create_moves(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_moves = Moves(**data.dict())
|
||||
db.add(new_moves)
|
||||
db.commit()
|
||||
db.refresh(new_moves)
|
||||
return new_moves
|
||||
|
||||
@staticmethod
|
||||
def get_moves(db: Session, moves_id: int, current_user):
|
||||
moves = db.query(Moves).filter(Moves.id == moves_id).first()
|
||||
if not moves:
|
||||
raise ValueError("moves no encontrado")
|
||||
return moves
|
||||
|
||||
@staticmethod
|
||||
def update_moves(db: Session, moves_id: int, data: , current_user):
|
||||
moves = db.query(Moves).filter(Moves.id == moves_id).first()
|
||||
if not moves:
|
||||
raise ValueError("moves no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este moves")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(moves, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(moves)
|
||||
return moves
|
||||
|
||||
@staticmethod
|
||||
def delete_moves(db: Session, moves_id: int, current_user):
|
||||
moves = db.query(Moves).filter(Moves.id == moves_id).first()
|
||||
if not moves:
|
||||
raise ValueError("moves no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este moves")
|
||||
|
||||
try:
|
||||
moves.is_active = False
|
||||
moves.deleted_at = datetime.utcnow()
|
||||
moves.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(moves)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el moves: {e}")
|
||||
|
||||
return {"message": "moves eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/suppliers_service.py
Normal file
67
output/generated/services/suppliers_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.suppliers.models import Suppliers
|
||||
from app.modules.suppliers.schema import
|
||||
|
||||
|
||||
class SuppliersService:
|
||||
@staticmethod
|
||||
def create_suppliers(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_suppliers = Suppliers(**data.dict())
|
||||
db.add(new_suppliers)
|
||||
db.commit()
|
||||
db.refresh(new_suppliers)
|
||||
return new_suppliers
|
||||
|
||||
@staticmethod
|
||||
def get_suppliers(db: Session, suppliers_id: int, current_user):
|
||||
suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first()
|
||||
if not suppliers:
|
||||
raise ValueError("suppliers no encontrado")
|
||||
return suppliers
|
||||
|
||||
@staticmethod
|
||||
def update_suppliers(db: Session, suppliers_id: int, data: , current_user):
|
||||
suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first()
|
||||
if not suppliers:
|
||||
raise ValueError("suppliers no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este suppliers")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(suppliers, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(suppliers)
|
||||
return suppliers
|
||||
|
||||
@staticmethod
|
||||
def delete_suppliers(db: Session, suppliers_id: int, current_user):
|
||||
suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first()
|
||||
if not suppliers:
|
||||
raise ValueError("suppliers no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este suppliers")
|
||||
|
||||
try:
|
||||
suppliers.is_active = False
|
||||
suppliers.deleted_at = datetime.utcnow()
|
||||
suppliers.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(suppliers)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el suppliers: {e}")
|
||||
|
||||
return {"message": "suppliers eliminado correctamente"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user