fix events

This commit is contained in:
Valentin CZERYBA 2024-03-30 23:31:31 +01:00
parent 9ee7f1cf3a
commit 06b50247fd
2 changed files with 6 additions and 6 deletions

View File

@ -24,7 +24,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
if status is not None: if status is not None:
object_search = {"status":{"$eq": status}} object_search = {"status":{"$eq": status}}
if id_event is not None: if id_event is not None:
eventid = ObjectId(id_event) eventid = ObjectId(eventid)
object_search = {"id": {"$regex": userid}} object_search = {"id": {"$regex": userid}}
if status is not None: if status is not None:
object_search = {"$and":[{"id":{"$regex": eventid}}, {"status":{"$eq":status}}]} object_search = {"$and":[{"id":{"$regex": eventid}}, {"status":{"$eq":status}}]}

View File

@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException, status, Response
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from datetime import datetime from datetime import datetime
from ..dependencies import users_token, permissions_checker, database from ..dependencies import users_token, permissions_checker, database
from ..models import events, users from ..models import ipaddress, users
from pydantic import EmailStr from pydantic import EmailStr
from typing import Annotated from typing import Annotated
from bson import ObjectId from bson import ObjectId
@ -19,7 +19,7 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
) )
limit = limit + skip limit = limit + skip
listEvents = [] listEvents = []
event_repository = events.EventRepository(database=database.database) ip_repository = ipaddress.IpAddressRepository(database=database.database)
object_search = {} object_search = {}
if status is not None: if status is not None:
object_search = {"status":{"$eq": status}} object_search = {"status":{"$eq": status}}
@ -28,10 +28,10 @@ async def read_events(authorize: Annotated[bool, Depends(permissions_checker.Per
object_search = {"id": {"$regex": ipid}} object_search = {"id": {"$regex": ipid}}
if status is not None: if status is not None:
object_search = {"$and":[{"id":{"$regex": ipid}}, {"status":{"$eq":status}}]} object_search = {"$and":[{"id":{"$regex": ipid}}, {"status":{"$eq":status}}]}
if name is not None: if ip is not None:
object_search = {"name": {"$regex": name}} object_search = {"ip": {"$regex": ip}}
if status is not None: if status is not None:
object_search = {"$and":[{"name":{"$regex": name}}, {"status":{"$eq":status}}]} object_search = {"$and":[{"ip":{"$regex": ip}}, {"status":{"$eq":status}}]}
for event_index in event_repository.find_by(object_search, limit=limit, skip=skip): for event_index in event_repository.find_by(object_search, limit=limit, skip=skip):