Skip to content

Commit

Permalink
Added Notification Resource Query to query_joins
Browse files Browse the repository at this point in the history
  • Loading branch information
shaurya-blip authored Feb 8, 2022
1 parent 0ab7099 commit 86fb617
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
15 changes: 15 additions & 0 deletions monday/query_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,18 @@ def delete_teams_from_workspace_query(id, team_ids):
}
''' % (id, team_ids)
return query


def create_notification_query(user_id, target_id, text, target_type):
query = '''
mutation {
create_notification (user_id: %s, target_id: %s, text: "%s", target_type: %s) {
text
user_id
target_id
target_type
}
}
''' % (user_id, target_id, text, target_type)
# Target type may be: Project/Post
return query
3 changes: 2 additions & 1 deletion monday/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
from .groups import GroupResource
from .complexity import ComplexityResource
from .workspaces import WorkspaceResource
from .notification import NotificationResource

__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource']
__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource', 'NotificationResource']
14 changes: 14 additions & 0 deletions monday/resources/notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from monday.resources.base import BaseResource
from monday.query_joins import create_notification_query


class NotificationResource(BaseResource):
def __init__(self, token):
super().__init__(token)

def create_notification(self, user_id, target_id, text, target_type):
"""
Refer to here for more information -> https://api.developer.monday.com/docs/notification-queries
"""
query = create_notification_query(user_id, target_id, text, target_type)
return self.client.execute(query)
2 changes: 2 additions & 0 deletions monday/tests/test_case_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ def setUp(self):
self.workspace_id = "123456"
self.workspace_user_kind = "subscriber"
self.team_ids = [105939, 105940, 105941]
self.notification_text = "This is an awesome notification."
self.notification_target_type = "Project"

15 changes: 15 additions & 0 deletions monday/tests/test_notification_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from monday.tests.test_case_resource import BaseTestCase
from monday.query_joins import create_notification_query


class NotificationsTestCase(BaseTestCase):
def setUp(self):
super(NotificationsTestCase, self).setUp()

def test_create_notification_query(self):
query = create_notification_query(self.user_ids[0], self.item_id, self.notification_text, self.notification_target_type)
self.assertIn(str(self.user_ids[0]), query)
self.assertIn(str(self.item_id), query)
self.assertIn(str(self.notification_text), query)
self.assertIn(str(self.notification_target_type), query)

0 comments on commit 86fb617

Please sign in to comment.