Skip to content

Commit

Permalink
Merge pull request #459 from TAMUSHPE/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JasonIsAzn authored Aug 25, 2024
2 parents 75cd460 + 8bcf7f5 commit 43125d4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 50 deletions.
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "TAMU SHPE",
"slug": "TAMU-SHPE",
"version": "1.0.7",
"version": "1.0.8",
"owner": "tamu-shpe",
"orientation": "portrait",
"icon": "./assets/icon.png",
Expand Down Expand Up @@ -54,7 +54,7 @@
"permissions": [
"android.permission.RECORD_AUDIO"
],
"versionCode": 65,
"versionCode": 67,
"userInterfaceStyle": "automatic"
},
"ios": {
Expand Down
40 changes: 32 additions & 8 deletions functions/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const geographicDistance = (pos1: GeoPoint, pos2: GeoPoint): number => {
return EARTH_RADIUS * c;
}

/**
* Meters that are acceptable to be beyond the geofencing bubble.
* This deals with bad geolocation data that assumes people are further away from their actual physical location
*/
const ACCEPTABLE_DISTANCE_ERROR = 20;

/**
* Handles a request from a user to sign into an event.
*/
Expand Down Expand Up @@ -64,22 +70,35 @@ export const eventSignIn = functions.https.onCall(async (data, context) => {
};

if (eventLog !== undefined && eventLog.signInTime !== undefined) {
throw new functions.https.HttpsError("already-exists", "Sign in time already exists.");
const message = "Sign in time already exists.";
functions.logger.error(message);
throw new functions.https.HttpsError("already-exists", message);
}
else if (event.endTime && (event.endTime.toMillis() + (event.endTimeBuffer ?? 0)) < Date.now()) {
throw new functions.https.HttpsError("deadline-exceeded", "Event has already ended.");
const message = "Event has already ended.";
functions.logger.error(message);
throw new functions.https.HttpsError("deadline-exceeded", message);
}
else if (event.startTime && (event.startTime.toMillis() - (event.startTimeBuffer ?? 0) > Date.now())) {
throw new functions.https.HttpsError("failed-precondition", "Event has not started.")
const message = "Event has not started.";
functions.logger.error(message)
throw new functions.https.HttpsError("failed-precondition", message);
}
else if (event.geolocation && event.geofencingRadius) {
if (typeof data.location.latitude != "number" || typeof data.location.longitude != "number" || !isFinite(data.location.latitude) || !isFinite(data.location.longitude)) {
throw new functions.https.HttpsError("invalid-argument", "Invalid geopoint object passed into function.");
const message = "Invalid geopoint object passed into function.";
functions.logger.error(message);
throw new functions.https.HttpsError("invalid-argument", message);
}

const distance = geographicDistance(event.geolocation, data.location);
if (distance > event.geofencingRadius + 10) {
throw new functions.https.HttpsError("out-of-range", `This event has geofencing enabled and the given user is ${distance} meters away when required radius is ${event.geofencingRadius} meters.`);
const message = `${event.name} has geofencing enabled and the given user is ${distance} meters away when required radius is ${event.geofencingRadius} + ${ACCEPTABLE_DISTANCE_ERROR} meters.`;
if (distance > event.geofencingRadius + ACCEPTABLE_DISTANCE_ERROR) {
functions.logger.error(message);
throw new functions.https.HttpsError("out-of-range", message);
}
else {
functions.logger.debug(message);
}
}

Expand Down Expand Up @@ -145,8 +164,13 @@ export const eventSignOut = functions.https.onCall(async (data, context) => {
}

const distance = geographicDistance(event.geolocation, data.location);
if (distance > event.geofencingRadius + 10) {
throw new functions.https.HttpsError("out-of-range", `This event has geofencing enabled and the given user is ${distance} meters away when required radius is ${event.geofencingRadius} meters.`);
const message = `${event.name} has geofencing enabled and the given user is ${distance} meters away when required radius is ${event.geofencingRadius} + ${ACCEPTABLE_DISTANCE_ERROR} meters.`;
if (distance > event.geofencingRadius + ACCEPTABLE_DISTANCE_ERROR) {
functions.logger.error(message);
throw new functions.https.HttpsError("out-of-range", message);
}
else {
functions.logger.debug(message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shpe-app",
"version": "1.0.7",
"version": "1.0.8",
"scripts": {
"start": "npx expo start --dev-client",
"test": "jest --coverage=true --verbose --bail --config ./jest.config.ts",
Expand Down
21 changes: 0 additions & 21 deletions src/screens/events/SetGeneralEventDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ const SetGeneralEventDetails = ({ navigation }: EventProps) => {
}
else {
setStartTime(Timestamp.fromDate(date));
if (endTime && date.valueOf() > endTime?.toDate().valueOf()) {
setEndTime(Timestamp.fromMillis(date.getTime() + MillisecondTimes.HOUR));
}
}
setShowStartDatePicker(false);
}}
Expand All @@ -227,9 +224,6 @@ const SetGeneralEventDetails = ({ navigation }: EventProps) => {
else if (!date) {
console.warn("Date picked is undefined.")
}
else if (endTime && date.valueOf() > endTime?.toDate().valueOf()) {
Alert.alert("Invalid Start Time", "Event cannot start after end time.")
}
else {
setStartTime(Timestamp.fromDate(date));
}
Expand Down Expand Up @@ -287,9 +281,6 @@ const SetGeneralEventDetails = ({ navigation }: EventProps) => {
if (!date) {
console.warn("Date picked is undefined.")
}
else if (startTime && date.valueOf() < startTime?.toDate().valueOf()) {
Alert.alert("Invalid End Date", "Event cannot end before start date.")
}
else {
setEndTime(Timestamp.fromDate(date));
}
Expand All @@ -304,9 +295,6 @@ const SetGeneralEventDetails = ({ navigation }: EventProps) => {
if (!date) {
console.warn("Date picked is undefined.")
}
else if (startTime && date.valueOf() < startTime?.toDate().valueOf()) {
Alert.alert("Invalid End Time", "Event cannot end before start time.")
}
else {
setEndTime(Timestamp.fromDate(date));
}
Expand Down Expand Up @@ -417,9 +405,6 @@ const SetGeneralEventDetails = ({ navigation }: EventProps) => {
else if (!date) {
console.warn("Date picked is undefined.")
}
else if (endTime && date.valueOf() > endTime?.toDate().valueOf()) {
Alert.alert("Invalid Start Time", "Event cannot start after end time.")
}
else {
setStartTime(Timestamp.fromDate(date));
}
Expand All @@ -440,9 +425,6 @@ const SetGeneralEventDetails = ({ navigation }: EventProps) => {
if (!date) {
console.warn("Date picked is undefined.")
}
else if (startTime && date.valueOf() < startTime?.toDate().valueOf()) {
Alert.alert("Invalid End Date", "Event cannot end before start date.")
}
else {
setEndTime(Timestamp.fromDate(date));
}
Expand All @@ -458,9 +440,6 @@ const SetGeneralEventDetails = ({ navigation }: EventProps) => {
if (!date) {
console.warn("Date picked is undefined.")
}
else if (startTime && date.valueOf() < startTime?.toDate().valueOf()) {
Alert.alert("Invalid End Time", "Event cannot end before start time.")
}
else {
setEndTime(Timestamp.fromDate(date));
}
Expand Down
17 changes: 8 additions & 9 deletions src/screens/events/UpdateEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ const UpdateEvent = ({ navigation }: EventProps) => {
}

const handleUpdateEvent = async () => {
if (!name) {
Alert.alert("Empty Name", "Event must have a name!")
return;
} else if (startTime!.toMillis() > endTime!.toMillis()) {
Alert.alert("Event ends before start time", "Event cannot end before it starts.")
return;
}

setLoading(true)
let updatedEvent: SHPEEvent = {};
switch (event.eventType) {
Expand Down Expand Up @@ -150,9 +158,6 @@ const UpdateEvent = ({ navigation }: EventProps) => {
updatedEvent.copyFromObject(eventData);
}

console.log(updatedEvent.geofencingRadius, 'this is updatedEvent Variable geofencing');
console.log(updatedEvent, 'updated event');

await setEvent(event.id!, updatedEvent);
setLoading(false)
navigation.navigate("EventInfo", { event: updatedEvent });
Expand Down Expand Up @@ -340,9 +345,6 @@ const UpdateEvent = ({ navigation }: EventProps) => {
else if (!date) {
console.warn("Date picked is undefined.")
}
else if (endTime && date.valueOf() > endTime?.toDate().valueOf()) {
Alert.alert("Invalid Start Time", "Event cannot start after end time.")
}
else {
setStartTime(Timestamp.fromDate(date));
}
Expand Down Expand Up @@ -519,9 +521,6 @@ const UpdateEvent = ({ navigation }: EventProps) => {
else if (!date) {
console.warn("Date picked is undefined.")
}
else if (endTime && date.valueOf() > endTime?.toDate().valueOf()) {
Alert.alert("Invalid Start Time", "Event cannot start after end time.")
}
else {
setStartTime(Timestamp.fromDate(date));
}
Expand Down
18 changes: 9 additions & 9 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,15 @@ export type UserEventData = {

export const getStatusMessage = (status: EventLogStatus, mode?: "sign-in" | "sign-out"): string => {
const statusMessages = {
[EventLogStatus.SUCCESS]: `Successfully ${mode === "sign-in" ? "signed in" : "signed out"}.`,
[EventLogStatus.EVENT_OVER]: "The event is already over.",
[EventLogStatus.EVENT_ONGOING]: "The event is ongoing.",
[EventLogStatus.EVENT_NOT_FOUND]: "The event was not found.",
[EventLogStatus.ALREADY_LOGGED]: `You have already ${mode === "sign-in" ? "signed in" : "signed out"}.`,
[EventLogStatus.NOT_A_STUDENT]: "Only students can sign in/out of events.",
[EventLogStatus.EVENT_NOT_STARTED]: "The event has not started yet.",
[EventLogStatus.OUT_OF_RANGE]: "You are not close enough to the event to sign in/out.",
[EventLogStatus.ERROR]: "An internal error occurred. Please try again.",
[EventLogStatus.SUCCESS]: `Successfully ${mode === `sign-in` ? `signed in` : `signed out`}.`,
[EventLogStatus.EVENT_OVER]: `The event is already over.`,
[EventLogStatus.EVENT_ONGOING]: `The event is ongoing.`,
[EventLogStatus.EVENT_NOT_FOUND]: `The event was not found.`,
[EventLogStatus.ALREADY_LOGGED]: `You have already ${mode === `sign-in` ? `signed in` : `signed out`}.`,
[EventLogStatus.NOT_A_STUDENT]: `Only students can ${mode === `sign-in` ? `sign in` : `sign out`} of events.`,
[EventLogStatus.EVENT_NOT_STARTED]: `The event has not started yet.`,
[EventLogStatus.OUT_OF_RANGE]: `You are not close enough to the event to ${mode === `sign-in` ? `sign in` : `sign out`}.`,
[EventLogStatus.ERROR]: `An internal error occurred. Please try again.`,
};

return statusMessages[status] || "An unknown error occurred.";
Expand Down

0 comments on commit 43125d4

Please sign in to comment.