Skip to content

Commit

Permalink
feat: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Jul 17, 2024
1 parent 4f50be6 commit 23f3779
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions insights/sources/rooms/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
from insights.sources.filtersets import GenericSQLFilter


# use stub files to represent it on other parts of the code
# Use django_filters Filter class as a reference
class RoomSQLFilter:
"""Responsible for cleaning and validating Filter data"""

def __init__(
self,
source_field: str,
table_alias: str,
join_clause: dict = {},
value: any = None,
) -> None:
self.source_field = source_field
self.table_alias = table_alias
self.join_clause = join_clause
self.value = value


class RoomFilterSet:
agent = RoomSQLFilter(
agent = GenericSQLFilter(
source_field="user_id",
table_alias="r",
)
project = RoomSQLFilter(
project = GenericSQLFilter(
source_field="uuid",
table_alias="p",
join_clause={
Expand All @@ -30,41 +19,50 @@ class RoomFilterSet:
"p": "INNER JOIN public.projects_project AS p ON p.uuid=s.project_id",
},
)
tag = RoomSQLFilter(
tag = GenericSQLFilter(
source_field="sectortag_id",
table_alias="tg",
join_clause={
"tg": "INNER JOIN public.rooms_room_tags AS tg ON tg.room_id=r.uuid"
},
)
tags = tag
sector = RoomSQLFilter(
sector = GenericSQLFilter(
source_field="sector_id",
table_alias="q",
join_clause={
"q": "INNER JOIN public.queues_queue AS q ON q.uuid=r.queue_id",
},
)
sector_id = sector
queue = RoomSQLFilter(
queue = GenericSQLFilter(
source_field="queue_id",
table_alias="r",
)
contact = RoomSQLFilter(
contact = GenericSQLFilter(
source_field="uuid",
table_alias="ctt",
join_clause={
"q": "INNER JOIN public.contacts_contact AS ctt on ctt.uuid=r.contact_id",
},
)
created_on = RoomSQLFilter(
created_on = GenericSQLFilter(
source_field="created_on",
table_alias="r",
)
ended_at = RoomSQLFilter(
ended_at = GenericSQLFilter(
source_field="ended_at",
table_alias="r",
)
user = GenericSQLFilter(
source_field="user_id",
table_alias="r",
)
user_id = user
is_active = GenericSQLFilter(
source_field="is_active",
table_alias="r",
)

def get_field(self, field_name):
try:
Expand Down

0 comments on commit 23f3779

Please sign in to comment.