Finnish check_access

This commit is contained in:
2026-05-21 18:00:05 +02:00
parent 8b4c3cdec9
commit c30516c2bc

View File

@@ -35,15 +35,20 @@ def isDoorOpen():
def checkAccess(uuid: str, db: Session = Depends(get_session)): def checkAccess(uuid: str, db: Session = Depends(get_session)):
try: try:
current_weekday = datetime.datetime.weekday(datetime.date.today()) current_weekday = datetime.datetime.weekday(datetime.date.today())
print(f"current day is {current_weekday}") current_time = datetime.datetime.now()
card = db.exec(select(Card).where(Card.uuid == uuid)).one() card = db.exec(select(Card).where(Card.uuid == uuid)).one()
for auth in card.group.accessauths: for auth in card.group.accessauths:
print(f"checking auth: {auth.name}") print(f"checking auth: {auth.name}")
for timetable in auth.timetables: for timetable in auth.timetables:
print(f"timetable date is {timetable.weekday - 1}") print(f" checking timetable {timetable.id}")
if current_weekday == timetable.weekday - 1: print(f" comparing weekday: CUR:{current_weekday} TT:{timetable.weekday}")
return True if current_weekday == timetable.weekday:
return False starttime = datetime.datetime.combine(datetime.date.today(), timetable.starttime)
endtime = starttime + datetime.timedelta(minutes=timetable.duration)
print(f" comparing time: Start:{starttime} Current:{current_time} End:{endtime}")
if starttime < current_time < endtime:
return True
return False
except exc.NoResultFound: except exc.NoResultFound:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)