Skip to content

Commit

Permalink
Merge branch 'dev' into cindy-jacob/add-resident
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessh committed Dec 4, 2024
2 parents 05a0f66 + 3077bee commit b4cd596
Show file tree
Hide file tree
Showing 43 changed files with 3,057 additions and 657 deletions.
131 changes: 88 additions & 43 deletions backend/graphql/resolvers/notificationResolvers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import NotificationService from "../../services/implementations/notificationService";
import INotificationService, {
NotificationDTO,
NotificationGroupDTO,
NotificationReceivedDTO,
UpdateNotificationDTO,
CreateNotificationDTO,
} from "../../services/interfaces/notificationService";
import IResidentService from "../../services/interfaces/residentService";
import ResidentService from "../../services/implementations/residentService";
Expand All @@ -13,75 +16,117 @@ const notificationService: INotificationService = new NotificationService(

const notificationResolvers = {
Query: {
getNotificationsByUserId: async (
getNotificationsByIds: async (
_parent: undefined,
{ userId }: { userId: string },
{ notificationIds }: { notificationIds: string[] },
): Promise<NotificationReceivedDTO[]> => {
return notificationService.getNotificationsByUserId(Number(userId));
const notificationReceived = await notificationService.getNotificationsByIds(
notificationIds.map(Number),
);
return notificationReceived;
},
getNotificationById: async (
getNotificationByResident: async (
_parent: undefined,
{ id }: { id: string },
): Promise<NotificationReceivedDTO> => {
return notificationService.getNotificationById(Number(id));
{ residentId }: { residentId: string },
): Promise<NotificationReceivedDTO[]> => {
const notificationReceived = await notificationService.getNotificationByResident(
Number(residentId),
);
return notificationReceived;
},
getAllGroupsAndNotifications: async (): Promise<NotificationGroupDTO[]> => {
const notificationGroups = await notificationService.getAllGroupsAndNotifications();
return notificationGroups;
},
},
Mutation: {
sendNotification: async (
createNotificationGroup: async (
_parent: undefined,
{
authorId,
title,
message,
recipientIds,
roomIds,
}: {
authorId: number;
title: string;
message: string;
recipientIds: number[];
roomIds: number[];
},
): Promise<NotificationDTO> => {
const ids = recipientIds.map((id) => Number(id));
const newNotification = await notificationService.sendNotification(
Number(authorId),
title,
message,
): Promise<NotificationGroupDTO> => {
const ids = roomIds.map((id) => Number(id));
const newNotificationGroup = await notificationService.createNotificationGroup(
ids,
);
return newNotification;
return newNotificationGroup;
},
deleteUserNotification: async (
createAnnouncementGroup: async (): Promise<NotificationGroupDTO> => {
const newNotificationGroup = await notificationService.createAnnouncementGroup();
return newNotificationGroup;
},
sendNotificationToGroup: async (
_parent: undefined,
{ notificationId }: { notificationId: number },
{
groupId,
notification,
}: {
groupId: number;
notification: CreateNotificationDTO;
},
): Promise<NotificationDTO> => {
const deletedNotification = await notificationService.deleteUserNotification(
Number(notificationId),
const newNotification = await notificationService.sendNotificationToGroup(
Number(groupId),
notification,
);
return deletedNotification;
return newNotification;
},
updateSeenNotification: async (
deleteNotificationGroup: async (
_parent: undefined,
{ notificationId }: { notificationId: number },
): Promise<NotificationReceivedDTO> => {
const updatedNotification = await notificationService.updateSeenNotification(
{
groupId,
}: {
groupId: number;
},
): Promise<NotificationGroupDTO> => {
const deletedGroup = await notificationService.deleteNotificationGroup(
Number(groupId),
);
return deletedGroup;
},
updateNotificationById: async (
_parent: undefined,
{
notificationId,
notification,
}: {
notificationId: number;
notification: UpdateNotificationDTO;
},
): Promise<NotificationDTO> => {
const updatedNotification = await notificationService.updateNotificationById(
Number(notificationId),
notification,
);
return updatedNotification;
},
sendAnnouncement: async (
deleteNotificationByIds: async (
_parent: undefined,
{
title,
message,
userId,
}: { title: string; message: string; userId: number },
): Promise<NotificationDTO> => {
const newAnnouncement = await notificationService.sendAnnouncement(
title,
message,
Number(userId),
notificationIds,
}: {
notificationIds: number[];
},
): Promise<boolean> => {
const ids = notificationIds.map((id) => Number(id));
await notificationService.deleteNotificationByIds(ids);
return true;
},
updateSeenNotification: async (
_parent: undefined,
{
notificationSeenId,
}: {
notificationSeenId: number;
},
): Promise<NotificationReceivedDTO> => {
const updatedNotificationReceived = await notificationService.updateSeenNotification(
Number(notificationSeenId),
);
return newAnnouncement;
return updatedNotificationReceived;
},
},
};
Expand Down
54 changes: 37 additions & 17 deletions backend/graphql/types/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,59 @@ import { gql } from "apollo-server-express";
const notificationType = gql`
type NotificationDTO {
id: ID!
authorId: ID
title: String!
message: String!
createdAt: String!
recipients: [NotificationReceivedDTO!]
createdAt: DateTime
authorId: ID
recipients: [NotificationReceivedDTO]
}
type NotificationGroupDTO {
id: ID!
recipients: [ResidentDTO!]
notifications: [NotificationDTO!]
announcementGroup: Boolean!
}
type NotificationReceivedDTO {
id: ID!
notificationId: ID!
notification: NotificationDTO
recipientId: ID!
seen: Boolean!
}
input UpdateNotificationDTO {
authorId: ID
message: String
createdAt: DateTime
}
input CreateNotificationDTO {
authorId: ID
message: String!
createdAt: DateTime
}
extend type Query {
getNotificationsByUserId(userId: ID!): [NotificationReceivedDTO!]
getNotificationById(id: ID!): NotificationReceivedDTO!
getNotificationsByIds(notificationIds: [ID!]): [NotificationReceivedDTO!]
getNotificationByResident(residentId: ID!): [NotificationReceivedDTO!]
getAllGroupsAndNotifications: [NotificationGroupDTO!]
}
extend type Mutation {
sendNotification(
authorId: ID!
title: String!
message: String!
recipientIds: [ID!]
createNotificationGroup(roomIds: [Int!]): NotificationGroupDTO!
createAnnouncementGroup: NotificationGroupDTO!
sendNotificationToGroup(
groupId: ID!
notification: CreateNotificationDTO!
): NotificationDTO!
deleteUserNotification(notificationId: ID!): NotificationDTO!
updateSeenNotification(notificationId: ID!): NotificationReceivedDTO!
sendAnnouncement(
title: String
message: String
userId: ID
deleteNotificationGroup(groupId: ID!): NotificationGroupDTO!
updateNotificationById(
notificationId: ID!
notification: UpdateNotificationDTO!
): NotificationDTO!
deleteNotificationByIds(notificationIds: [ID!]): Boolean!
updateSeenNotification(notificationSeenId: ID!): NotificationReceivedDTO!
}
`;

Expand Down
20 changes: 2 additions & 18 deletions backend/graphql/types/residentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,37 @@ const residentType = gql`
type ResidentDTO {
userId: Int!
residentId: Int!
email: String!
phoneNumber: String
firstName: String!
lastName: String!
displayName: String
profilePictureURL: String
isActive: Boolean!
birthDate: Date!
roomNumber: Int!
credits: Float!
dateJoined: Date!
dateLeft: Date
notes: String
notificationGroup: [NotificationGroupDTO!]!
notificationRecieved: [NotificationReceivedDTO]!
}
input CreateResidentDTO {
email: String!
password: String!
phoneNumber: String
firstName: String!
lastName: String!
displayName: String
profilePictureURL: String
residentId: Int!
birthDate: Date!
roomNumber: Int!
credits: Float
dateJoined: Date
dateLeft: Date
notes: String
}
input UpdateResidentDTO {
email: String
password: String
phoneNumber: String
firstName: String
lastName: String
displayName: String
profilePictureURL: String
residentId: Int
birthDate: Date
roomNumber: Int
credits: Float
dateJoined: Date
dateLeft: Date
notes: String
}
enum RedeemCreditResponse {
Expand Down
10 changes: 5 additions & 5 deletions backend/graphql/types/taskType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ const taskType = gql`
}
input InputTaskAssignedDTO {
taskId: Int
assigneeId: Int
assignerId: Int
status: Status
startDate: DateTime
taskId: Int!
assigneeId: Int!
assignerId: Int!
status: Status!
startDate: DateTime!
comments: String
}
Expand Down
Loading

0 comments on commit b4cd596

Please sign in to comment.