Skip to content

Commit

Permalink
linter and Announcement view bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KathleenX7 committed Dec 7, 2024
1 parent ca9ac47 commit 252fc1d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 13 additions & 12 deletions backend/services/implementations/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ class NotificationService implements INotificationService {
roomIds: number[],
): Promise<NotificationGroupDTO> {
try {
if (roomIds.length == 0) {
throw Object.assign(
new Error('No rooms specified.'),
{ code: 400 }
);
if (roomIds.length === 0) {
throw Object.assign(new Error("No rooms specified."), { code: 400 });
}
if (roomIds.length > 1) {
if (roomIds.length > 1) {
// enforces that a group can only have one member
// remove in the future if the requirements change
throw Object.assign(
new Error('Notification Group can only have one room.'),
{ code: 400 }
new Error("Notification Group can only have one room."),
{ code: 400 },
);
}
const residents = await prisma.resident.findMany({
Expand All @@ -53,16 +50,18 @@ class NotificationService implements INotificationService {
},
include: {
recipients: true,
}
},
});

if (existingGroup && existingGroup.length > 0) {
// throw error if residents match
existingGroup.forEach((group) => {
if (group.recipients.length === residentIds.length) {
throw Object.assign(
new Error('Notification Group already exists with specified roomIds.'),
{ code: 400 }
new Error(
"Notification Group already exists with specified roomIds.",
),
{ code: 400 },
);
}
});
Expand Down Expand Up @@ -99,7 +98,9 @@ class NotificationService implements INotificationService {
},
});
if (existingGroup && existingGroup.length > 0) {
throw 'Announcement Group already exists.';
throw Object.assign(new Error("Announcement Group already exists."), {
code: 400,
});
}

const residents = await prisma.resident.findMany({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const formatRooms = (roomIDs: number[]) => {
const formattedRooms = roomIDs.map((id) => {
if (id === 0) {
return "New Announcement";
} if (id === -1) {
return "All Rooms";
}
return `Room ${id}`;
});
Expand Down

0 comments on commit 252fc1d

Please # to comment.