Initial commit - Migrated to Dev environment
This commit is contained in:
14
backend/app/services/notification_service.py
Executable file
14
backend/app/services/notification_service.py
Executable file
@@ -0,0 +1,14 @@
|
||||
from datetime import datetime, timedelta
|
||||
from sqlalchemy import select
|
||||
from app.models.user import User
|
||||
from app.models.vehicle import Vehicle
|
||||
from app.core.email import send_expiry_notification
|
||||
|
||||
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})")
|
||||
Reference in New Issue
Block a user