STABLE: Final schema sync, optimized gitignore
This commit is contained in:
@@ -1,14 +1,31 @@
|
||||
from datetime import datetime, timedelta
|
||||
# /opt/docker/dev/service_finder/backend/app/services/notification_service.py
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from app.models.user import User
|
||||
from app.models.vehicle import Vehicle
|
||||
from app.core.email import send_expiry_notification
|
||||
from fastapi import BackgroundTasks
|
||||
from app.models.identity import User
|
||||
from app.models.asset import Asset
|
||||
from app.core.email import send_expiry_notification # Feltételezett core funkció
|
||||
|
||||
async def check_expiring_documents(db: AsyncSession, background_tasks: BackgroundTasks):
|
||||
# Példa: Műszaki vizsga lejárata 30 napon belül
|
||||
threshold = datetime.now().date() + timedelta(days=30)
|
||||
result = await db.execute(
|
||||
select(Vehicle, User).join(User).where(Vehicle.mot_expiry_date <= threshold)
|
||||
)
|
||||
for vehicle, user in result.all():
|
||||
send_expiry_notification(background_tasks, user.email, f"Műszaki vizsga ({vehicle.license_plate})")
|
||||
class NotificationService:
|
||||
@staticmethod
|
||||
async def check_expiring_documents(db: AsyncSession, background_tasks: BackgroundTasks):
|
||||
"""
|
||||
Példa: Műszaki vizsga lejárata 30 napon belül.
|
||||
A logikát az új Asset és Identity modellekhez igazítottuk.
|
||||
"""
|
||||
threshold = datetime.now(timezone.utc).date() + timedelta(days=30)
|
||||
|
||||
# JAVÍTVA: Asset join identity.User-el az új struktúra szerint
|
||||
stmt = select(Asset, User).join(User, Asset.owner_org_id == User.scope_id).where(
|
||||
Asset.status == "active"
|
||||
)
|
||||
|
||||
result = await db.execute(stmt)
|
||||
for asset, user in result.all():
|
||||
# A lejárati adatot a dúsított factory_data-ból vesszük
|
||||
expiry = asset.factory_data.get("mot_expiry_date") if asset.factory_data else None
|
||||
if expiry:
|
||||
expiry_dt = datetime.strptime(expiry, "%Y-%m-%d").date()
|
||||
if expiry_dt <= threshold:
|
||||
send_expiry_notification(background_tasks, user.email, f"Műszaki vizsga lejár: {asset.license_plate}")
|
||||
Reference in New Issue
Block a user