Skip to content

Commit

Permalink
Add migrations, integrate APIs with residents, and integrate some fro…
Browse files Browse the repository at this point in the history
…ntend
  • Loading branch information
KathleenX7 committed Dec 6, 2024
1 parent 04d474c commit 311fb11
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 138 deletions.
8 changes: 7 additions & 1 deletion backend/services/implementations/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class NotificationService implements INotificationService {
},
announcementGroup: false,
},
include: {
recipients: true,
},
});

return newNotificationGroup;
Expand Down Expand Up @@ -62,6 +65,9 @@ class NotificationService implements INotificationService {
},
announcementGroup: true,
},
include: {
recipients: true,
},
});

return newNotificationGroup;
Expand Down Expand Up @@ -143,7 +149,7 @@ class NotificationService implements INotificationService {
try {
const notificationGroups = await prisma.notificationGroup.findMany({
include: {
// recipients: true, // TODO: resident type is incompatiable at time of writing
recipients: true,
notifications: true,
},
});
Expand Down
84 changes: 51 additions & 33 deletions frontend/src/APIClients/Mutations/NotificationMutations.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,76 @@
import { gql } from "@apollo/client";

export const SEND_NOTIFICATION = gql`
mutation SendNotification(
$authorId: ID!
$title: String!
$message: String!
$recipientIds: [ID!]
) {
sendNotification(
authorId: $authorId
title: $title
message: $message
recipientIds: $recipientIds
) {
export const CREATE_NOTIFICATION_GROUP = gql`
mutation CreateNotificationGroup($roomIds: [Int!]) {
createNotificationGroup(roomIds: $roomIds) {
id
authorId
title
message
createdAt
announcementGroup
}
}
`;

export const DELETE_USER_NOTIFICATION = gql`
mutation DeleteUserNotification($notificationId: ID!) {
deleteUserNotification(notificationId: $notificationId) {
export const CREATE_ANNOUNCEMENT_GROUP = gql`
mutation CreateAnnouncementGroup {
createAnnouncementGroup {
id
announcementGroup
}
}
`;

export const SEND_NOTIFICATION_TO_GROUP = gql`
mutation SendNotificationToGroup(
$groupId: ID!
$notification: CreateNotificationDTO!
) {
sendNotificationToGroup(groupId: $groupId, notification: $notification) {
id
authorId
title
message
createdAt
authorId
}
}
`;

export const UPDATE_SEEN_NOTIFICATION = gql`
mutation UpdateSeenNotification($notificationId: ID!) {
updateSeenNotification(notificationId: $notificationId) {
export const DELETE_NOTIFICATION_GROUP = gql`
mutation DeleteNotificationGroup($groupId: ID!) {
deleteNotificationGroup(groupId: $groupId) {
id
notificationId
recipientId
seen
announcementGroup
}
}
`;

export const SEND_ANNOUNCEMENT = gql`
mutation SendAnnouncement($title: String, $message: String, $userId: ID) {
sendAnnouncement(title: $title, message: $message, userId: $userId) {
export const UPDATE_NOTIFICATION_BY_ID = gql`
mutation UpdateNotificationById(
$notificationId: ID!
$notification: UpdateNotificationDTO!
) {
updateNotificationById(
notificationId: $notificationId
notification: $notification
) {
id
authorId
title
message
createdAt
authorId
}
}
`;

export const DELETE_NOTIFICATION_BY_IDS = gql`
mutation DeleteNotificationByIds($notificationIds: [ID!]) {
deleteNotificationByIds(notificationIds: $notificationIds)
}
`;

export const UPDATE_SEEN_NOTIFICATION = gql`
mutation UpdateSeenNotification($notificationSeenId: ID!) {
updateSeenNotification(notificationSeenId: $notificationSeenId) {
id
notificationId
recipientId
seen
}
}
`;
50 changes: 44 additions & 6 deletions frontend/src/APIClients/Queries/NotificationQueries.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,61 @@
import { gql } from "@apollo/client";

export const GET_NOTIFICATIONS_BY_USER_ID = gql`
query GetNotificationsByUserId($userId: ID!) {
getNotificationsByUserId(userId: $userId) {
export const GET_NOTIFICATIONS_BY_IDS = gql`
query getNotificationsByIds($notificationIds: [ID!]) {
getNotificationsByIds(notificationIds: $notificationIds) {
id
notificationId
recipientId
seen
notification {
id
message
createdAt
authorId
}
}
}
`;

export const GET_NOTIFCATION_BY_ID = gql`
query GetNotificationById($id: ID!) {
getNotificationById(id: $id) {
export const GET_NOTIFCATION_BY_RESIDENT = gql`
query getNotificationByResident($residentId: ID!) {
getNotificationByResident(residentId: $id) {
id
notificationId
recipientId
seen
notification {
id
message
createdAt
authorId
}
}
}
`;

export const GET_ALL_GROUPS_AND_NOTIFICATIONS = gql`
query getAllGroupsAndNotifications {
getAllGroupsAndNotifications {
id
announcementGroup
notifications {
id
message
createdAt
authorId
}
recipients {
userId
residentId
displayName
profilePictureURL
isActive
roomNumber
credits
dateJoined
dateLeft
}
}
}
`;
27 changes: 23 additions & 4 deletions frontend/src/APIClients/Types/NotificationType.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
export type NotificationResponse = {
id: string;
message: string;
createdAt?: Date;
authorId?: string;
title: string;
recipients?: NotificationReceivedResponse[];
};

export type NotificationCreateRequest = {
message: string;
createdAt: Date;
recipients?: [NotificationReceived];
createdAt?: Date;
authorId?: string;
};

export type NotificationUpdateRequest = {
message?: string;
createdAt?: Date;
authorId?: string;
};

export type NotificationGroupResponse = {
id: string;
// recipients?: Residentesponse[]; TODO: add when resident response exists
notifications?: NotificationResponse[];
announcementGroup: boolean;
};

export type NotificationReceived = {
export type NotificationReceivedResponse = {
id: string;
notificationId: string;
notification?: NotificationResponse;
recipientId: number;
seen: boolean;
};
80 changes: 47 additions & 33 deletions frontend/src/components/pages/announcements/AnnouncementsGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ import {
GroupAnnouncements,
} from "../../../types/NotificationTypes";
import { truncateMessage } from "../../../utils/StringUtils";
import {
NotificationGroupResponse,
NotificationResponse,
} from "../../../APIClients/Types/NotificationType";

interface ProcessedGroupAnnouncements {
all: GroupAnnouncements;
private: GroupAnnouncements;
groups: GroupAnnouncements;
all: NotificationGroupResponse[];
private: NotificationGroupResponse[];
groups: NotificationGroupResponse[];
}

export const formatRooms = (roomIDs: number[]) => {
Expand All @@ -57,7 +61,7 @@ const GroupTab = ({
selectedRooms,
}: {
roomKey: string;
firstAnnouncement: Announcement | null;
firstAnnouncement: NotificationResponse | null;
setSelectedGroup: React.Dispatch<React.SetStateAction<string>>;
isDraft: boolean;
selectedRooms?: number[] | null;
Expand Down Expand Up @@ -119,7 +123,7 @@ const GroupTab = ({
};

const GroupList: React.FC<{
announcements: GroupAnnouncements;
announcements: NotificationGroupResponse[];
setSelectedGroup: React.Dispatch<React.SetStateAction<string>>;
addingNewRoom: boolean;
setAddingNewRoom: React.Dispatch<React.SetStateAction<boolean>>;
Expand All @@ -138,29 +142,37 @@ const GroupList: React.FC<{

useEffect(() => {
const processedData: ProcessedGroupAnnouncements = {
all: {},
private: {},
groups: {},
all: [],
private: [],
groups: [],
};
Object.keys(announcements).forEach((key) => {
const rooms = key.split(",").map((room) => parseInt(room.trim(), 10));
const announcementData = announcements[key];

if (rooms.length === 1) {
// Add announcement to 'all' and 'private' if there is only 1 room
processedData.all[key] = announcementData;
processedData.private[key] = announcementData;
} else {
// Add announcement to 'all' and 'groups' if there are more than 1 room
processedData.all[key] = announcementData;
processedData.groups[key] = announcementData;
}
announcements?.forEach((group) => {
processedData.all.push(group);
// if (group.recipients && group.recipients.length > 1) { TODO: whenn recipients are added, include this
// processedData.private.push(group);
// }
processedData.groups.push(group);
});

// Object.keys(announcements).forEach((key) => {
// const rooms = key.split(",").map((room) => parseInt(room.trim(), 10));
// const announcementData = announcements[key];

// if (rooms.length === 1) {
// // Add announcement to 'all' and 'private' if there is only 1 room
// processedData.all[key] = announcementData;
// processedData.private[key] = announcementData;
// } else {
// // Add announcement to 'all' and 'groups' if there are more than 1 room
// processedData.all[key] = announcementData;
// processedData.groups[key] = announcementData;
// }
// });

setProcessedAnnouncements(processedData);
}, [announcements]);

const renderGroupTabs = (announcementsGroup: GroupAnnouncements) => {
const renderGroupTabs = (announcementsGroup: NotificationGroupResponse[]) => {
return (
announcementsGroup &&
[
Expand All @@ -177,21 +189,23 @@ const GroupList: React.FC<{
<></>
),
].concat(
Object.keys(announcementsGroup)
announcementsGroup
.filter(
(roomKey) =>
!searchRooms ||
searchRooms.length === 0 ||
searchRooms.some((room) =>
roomKey.split(",").map(Number).includes(room),
),
(group) => !searchRooms || searchRooms.length === 0,
// || searchRooms.some((room) =>
// roomKey.split(",").map(Number).includes(room),
// ),
)
.map((roomKey) => (
.map((group) => (
<GroupTab
key={roomKey}
roomKey={roomKey}
key={group.id}
roomKey={group.id}
isDraft={false}
firstAnnouncement={announcementsGroup[roomKey][0]}
firstAnnouncement={
group.notifications && group.notifications.length > 0
? group.notifications[0]
: null
}
setSelectedGroup={setSelectedGroup}
/>
)),
Expand Down
Loading

0 comments on commit 311fb11

Please sign in to comment.