-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from novaforgood/Max/email-whitelist
Add chat stats
- Loading branch information
Showing
28 changed files
with
5,399 additions
and
1,294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
hasura/metadata/databases/mentorcenter/functions/functions.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- "!include public_get_chat_stats.yaml" |
3 changes: 3 additions & 0 deletions
3
hasura/metadata/databases/mentorcenter/functions/public_get_chat_stats.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function: | ||
name: get_chat_stats | ||
schema: public |
39 changes: 39 additions & 0 deletions
39
hasura/metadata/databases/mentorcenter/tables/public_chat_stats.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
table: | ||
name: chat_stats | ||
schema: public | ||
object_relationships: | ||
- name: profile | ||
using: | ||
manual_configuration: | ||
column_mapping: | ||
profile_id: id | ||
insertion_order: null | ||
remote_table: | ||
name: profile | ||
schema: public | ||
select_permissions: | ||
- role: user | ||
permission: | ||
columns: | ||
- profile_id | ||
- rooms_messaged | ||
- rooms_read | ||
- total_rooms | ||
filter: | ||
_or: | ||
- _and: | ||
- _exists: | ||
_table: | ||
name: profile_to_profile_role_flattened | ||
schema: public | ||
_where: | ||
_and: | ||
- user_id: | ||
_eq: X-Hasura-User-Id | ||
- space_id: | ||
_eq: X-Hasura-Space-Id | ||
- profile_role: | ||
_eq: Admin | ||
- profile: | ||
space_id: | ||
_eq: X-Hasura-Space-Id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
hasura/migrations/mentorcenter/1705303183135_create_chat_stats_table/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Could not auto-generate a down migration. | ||
-- Please write an appropriate down migration for the SQL below: | ||
-- CREATE TABLE chat_stats ( | ||
-- profile_id UUID, | ||
-- rooms_messaged bigint, | ||
-- rooms_read bigint, | ||
-- total_rooms bigint | ||
-- ); |
6 changes: 6 additions & 0 deletions
6
hasura/migrations/mentorcenter/1705303183135_create_chat_stats_table/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE chat_stats ( | ||
profile_id UUID, | ||
rooms_messaged bigint, | ||
rooms_read bigint, | ||
total_rooms bigint | ||
); |
33 changes: 33 additions & 0 deletions
33
hasura/migrations/mentorcenter/1705305351034_create_chat_stats_fn/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- Could not auto-generate a down migration. | ||
-- Please write an appropriate down migration for the SQL below: | ||
-- CREATE OR REPLACE FUNCTION get_chat_stats(sp_id UUID DEFAULT NULL, after TIMESTAMP DEFAULT NULL) | ||
-- RETURNS SETOF chat_stats AS $$ | ||
-- | ||
-- BEGIN | ||
-- -- Return the query using the determined cutoff date | ||
-- RETURN QUERY | ||
-- SELECT | ||
-- p.id AS profile_id, | ||
-- COUNT(DISTINCT cm.chat_room_id) AS rooms_messaged, | ||
-- COUNT(DISTINCT CASE WHEN pc.latest_read_chat_message_id IS NOT NULL THEN pc.chat_room_id END) AS rooms_read, | ||
-- COUNT(DISTINCT pc.chat_room_id) AS total_rooms | ||
-- FROM | ||
-- profile p | ||
-- LEFT JOIN | ||
-- profile_to_chat_room pc ON p.id = pc.profile_id | ||
-- LEFT JOIN | ||
-- chat_message cm ON p.id = cm.sender_profile_id AND pc.chat_room_id = cm.chat_room_id | ||
-- JOIN | ||
-- chat_room ON pc.chat_room_id = chat_room.id | ||
-- JOIN | ||
-- "user" ON "user".id = p.user_id | ||
-- JOIN | ||
-- chat_intro ci ON chat_room.chat_intro_id = ci.id | ||
-- WHERE | ||
-- (ci.space_id = sp_id OR sp_id IS NULL) | ||
-- AND (ci.created_at >= after OR after IS NULL) | ||
-- AND "user"."type" = 'User' | ||
-- GROUP BY | ||
-- p.id; | ||
-- END; | ||
-- $$ LANGUAGE plpgsql STABLE; |
31 changes: 31 additions & 0 deletions
31
hasura/migrations/mentorcenter/1705305351034_create_chat_stats_fn/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
CREATE OR REPLACE FUNCTION get_chat_stats(sp_id UUID DEFAULT NULL, after TIMESTAMP DEFAULT NULL) | ||
RETURNS SETOF chat_stats AS $$ | ||
|
||
BEGIN | ||
-- Return the query using the determined cutoff date | ||
RETURN QUERY | ||
SELECT | ||
p.id AS profile_id, | ||
COUNT(DISTINCT cm.chat_room_id) AS rooms_messaged, | ||
COUNT(DISTINCT CASE WHEN pc.latest_read_chat_message_id IS NOT NULL THEN pc.chat_room_id END) AS rooms_read, | ||
COUNT(DISTINCT pc.chat_room_id) AS total_rooms | ||
FROM | ||
profile p | ||
LEFT JOIN | ||
profile_to_chat_room pc ON p.id = pc.profile_id | ||
LEFT JOIN | ||
chat_message cm ON p.id = cm.sender_profile_id AND pc.chat_room_id = cm.chat_room_id | ||
JOIN | ||
chat_room ON pc.chat_room_id = chat_room.id | ||
JOIN | ||
"user" ON "user".id = p.user_id | ||
JOIN | ||
chat_intro ci ON chat_room.chat_intro_id = ci.id | ||
WHERE | ||
(ci.space_id = sp_id OR sp_id IS NULL) | ||
AND (ci.created_at >= after OR after IS NULL) | ||
AND "user"."type" = 'User' | ||
GROUP BY | ||
p.id; | ||
END; | ||
$$ LANGUAGE plpgsql STABLE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.