Skip to content

Commit

Permalink
Merge pull request #271 from FrederickPu/fix-joan6-bug
Browse files Browse the repository at this point in the history
Fix joan6 bug
  • Loading branch information
logonoff authored Nov 27, 2024
2 parents 2666bec + fee7b2f commit 826adb4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
8 changes: 4 additions & 4 deletions backend/src/models/requestsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ export default {
if (userFetched.requests.length >= room.requestLimit) {
return {
status: 429,
message: 'User has too many pending requests.',
};
message: `User has too many pending requests. Maximum pending requests for this room is ${room.requestLimit}.`,
}
}
if (userFetched.groups[0].requests.length >= room.requestLimit) {
return {
status: 429,
message: 'Group has too many pending requests.',
};
message: `Group has too many pending requests. Maximum pending requests for this room is ${room.requestLimit}.`,
}
}

try {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const addHoursToDate = (date: Date, hours: number): Date => {
* @property endDate The end date of the booking
* @return A formatted string of the time range of the booking
*/
export const formatRangedTime = (startDate: Date, endDate: Date): string => {
export const formatRangedTime = (startDate: Date | string, endDate: Date | string): string => {
const formatDateOptions: Intl.DateTimeFormatOptions = {
hour: 'numeric',
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ interface BookingRequest {
authorUtorid: string;
createdAt: Date;
description: string;
endDate: Date;
endDate: string;
groupId: string;
group: {
id: string;
name: string;
};
reason: string | null;
roomName: string;
startDate: Date;
startDate: string;
status: BookingStatus;
title: string;
updatedAt: Date;
Expand Down
25 changes: 11 additions & 14 deletions frontend/src/pages/Room/joan6.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,12 @@ export const Joan6 = () => {
console.error(err);
});

setCurrentBooking(null);
// get current events
if (currentEvents && currentEvents.length > 0) {
const currentTime = new Date();
// check if current time is in between any of the events
const currentEvent: BookingRequest | undefined = currentEvents.find((event) => {
const currentEvent: BookingRequest | undefined = currentEvents.findLast((event) => {
// 3600000 is 1 hr * 60 min * 60 sec * 1000 ms
// offset added to end date to account for the fact that the end date is not inclusive
return (
Expand All @@ -204,19 +205,15 @@ export const Joan6 = () => {
setCurrentBooking(currentEvent);
}

// get next time the room is free by incrementing the current time until it is not in between any of the events
while (currentTime.getHours() < 23) {
currentTime.setHours(currentTime.getHours() + 1);
if (!currentEvent) {
// found a time when the room is free
setNextFree(
`Will be free at ${currentTime.toLocaleTimeString(undefined, {
hour: 'numeric',
})}`,
);
break;
}
}
const lastEvent = currentEvents[currentEvents.length - 1];
const nextDate = new Date(lastEvent.endDate);
nextDate.setHours(nextDate.getHours() + 1);

setNextFree(
`Will be free at ${nextDate.toLocaleTimeString(undefined, {
hour: 'numeric',
})}`,
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentEvents, room.requests, roomId]);
Expand Down
2 changes: 1 addition & 1 deletion frontend/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

Expand Down

0 comments on commit 826adb4

Please sign in to comment.