From be32c74ff89ccd165366389c2499a13e86b6b989 Mon Sep 17 00:00:00 2001 From: HarshGurnani <68934498+HarshGurnani@users.noreply.github.com> Date: Sun, 29 Oct 2023 10:04:30 -0700 Subject: [PATCH] linting --- ALUM/ALUM/ALUMApp.swift | 18 ++-- ALUM/ALUM/Models/CurrentUserModel.swift | 4 +- ALUM/ALUM/Services/APIConfig.swift | 114 ++++++++++++------------ backend/src/errors/service.ts | 2 +- backend/src/routes/sessions.ts | 36 ++++---- backend/src/routes/user.ts | 11 ++- backend/src/services/note.ts | 16 ++-- backend/src/services/notifications.ts | 24 ++--- backend/src/services/user.ts | 10 ++- backend/src/types/cakes.ts | 2 +- 10 files changed, 132 insertions(+), 105 deletions(-) diff --git a/ALUM/ALUM/ALUMApp.swift b/ALUM/ALUM/ALUMApp.swift index 8dc1368c..3cc17704 100644 --- a/ALUM/ALUM/ALUMApp.swift +++ b/ALUM/ALUM/ALUMApp.swift @@ -13,13 +13,13 @@ import Firebase import UserNotifications import FirebaseMessaging -//class AppDelegate: NSObject, UIApplicationDelegate { +// class AppDelegate: NSObject, UIApplicationDelegate { // func application(_ application: UIApplication, -// didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { +// didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { // FirebaseApp.configure() // return true // } -//} +// } extension View { func dismissKeyboardOnDrag() -> some View { @@ -42,12 +42,12 @@ struct ALUMApp: App { } } - class AppDelegate: NSObject, UIApplicationDelegate { let gcmMessageIDKey = "gcm.message_id" @ObservedObject var currentUser: CurrentUserModel = CurrentUserModel.shared - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { + + func application(_ application: UIApplication, didFinishLaunchingWithOptions + launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { FirebaseApp.configure() Messaging.messaging().delegate = self @@ -84,7 +84,6 @@ class AppDelegate: NSObject, UIApplicationDelegate { } } - extension AppDelegate: MessagingDelegate { func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { print("did receive FCM Token") @@ -96,12 +95,13 @@ extension AppDelegate: MessagingDelegate { } @available(iOS 10, *) -extension AppDelegate : UNUserNotificationCenterDelegate { +extension AppDelegate: UNUserNotificationCenterDelegate { // Receive displayed notifications for iOS 10 devices. func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, - withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + withCompletionHandler completionHandler: + @escaping (UNNotificationPresentationOptions) -> Void) { let userInfo = notification.request.content.userInfo if let messageID = userInfo[gcmMessageIDKey] { diff --git a/ALUM/ALUM/Models/CurrentUserModel.swift b/ALUM/ALUM/Models/CurrentUserModel.swift index 881bec49..4243209d 100644 --- a/ALUM/ALUM/Models/CurrentUserModel.swift +++ b/ALUM/ALUM/Models/CurrentUserModel.swift @@ -160,7 +160,7 @@ class CurrentUserModel: ObservableObject { } return userStatus } - + func sendFcmTokenHelper(fcmToken: String) { Task { do { @@ -170,7 +170,7 @@ class CurrentUserModel: ObservableObject { } } } - + func sendFcmToken(fcmToken: String) async throws { print(fcmToken) print(self.uid) diff --git a/ALUM/ALUM/Services/APIConfig.swift b/ALUM/ALUM/Services/APIConfig.swift index 9e9169fb..f8721b4a 100644 --- a/ALUM/ALUM/Services/APIConfig.swift +++ b/ALUM/ALUM/Services/APIConfig.swift @@ -11,14 +11,12 @@ let developmentMode = false // Firebase URL will not be updated very frequently because // so your changes to backend will only reflect on localhost until deployed -/* #if DEBUG let baseURL = "http://127.0.0.1:3000" #else let baseURL = "https://firebaseapp-ozybc5bsma-uc.a.run.app" #endif -*/ -let baseURL = "http://100.115.53.55:3000" + struct URLString { static let user = "\(baseURL)/user" static let mentor = "\(baseURL)/mentor" @@ -48,68 +46,68 @@ enum APIRoute { var url: String { switch self { - case .getSelf: - return [URLString.user, "me"].joined(separator: "/") - case .getMentor(let userId): - return [URLString.mentor, userId].joined(separator: "/") - case .getMentee(let userId): - return [URLString.mentee, userId].joined(separator: "/") - case .postMentor: - return URLString.mentor - case .postMentee: - return URLString.mentee - case .getNote(noteId: let noteId): - return [URLString.notes, noteId].joined(separator: "/") - case .patchNote(noteId: let noteId): - return [URLString.notes, noteId].joined(separator: "/") - case .getSession(sessionId: let sessionId): - return [URLString.sessions, sessionId].joined(separator: "/") - case .getSessions: - return URLString.sessions - case .postSession: - return URLString.sessions - case .getCalendly: - return URLString.calendly - case .patchUser(let userId): - return [URLString.user, userId].joined(separator: "/") - case .deleteSession(sessionId: let sessionId): - return [URLString.sessions, sessionId].joined(separator: "/") - case .patchSession(sessionId: let sessionId): - return [URLString.sessions, sessionId].joined(separator: "/") + case .getSelf: + return [URLString.user, "me"].joined(separator: "/") + case .getMentor(let userId): + return [URLString.mentor, userId].joined(separator: "/") + case .getMentee(let userId): + return [URLString.mentee, userId].joined(separator: "/") + case .postMentor: + return URLString.mentor + case .postMentee: + return URLString.mentee + case .getNote(noteId: let noteId): + return [URLString.notes, noteId].joined(separator: "/") + case .patchNote(noteId: let noteId): + return [URLString.notes, noteId].joined(separator: "/") + case .getSession(sessionId: let sessionId): + return [URLString.sessions, sessionId].joined(separator: "/") + case .getSessions: + return URLString.sessions + case .postSession: + return URLString.sessions + case .getCalendly: + return URLString.calendly + case .patchUser(let userId): + return [URLString.user, userId].joined(separator: "/") + case .deleteSession(sessionId: let sessionId): + return [URLString.sessions, sessionId].joined(separator: "/") + case .patchSession(sessionId: let sessionId): + return [URLString.sessions, sessionId].joined(separator: "/") } } var method: String { switch self { - case .getSelf, .getMentee, .getMentor, .getNote, .getSession, .getSessions, .getCalendly: - return "GET" - case .postMentor, .postMentee, .postSession: - return "POST" - case .patchNote, .patchUser, .patchSession: - return "PATCH" - case .deleteSession: - return "DELETE" + case .getSelf, .getMentee, .getMentor, .getNote, .getSession, .getSessions, .getCalendly: + return "GET" + case .postMentor, .postMentee, .postSession: + return "POST" + case .patchNote, .patchUser, .patchSession: + return "PATCH" + case .deleteSession: + return "DELETE" } } var requireAuth: Bool { switch self { - case - .getSelf, - .getMentor, - .getMentee, - .getNote, - .patchNote, - .getSession, - .getSessions, - .postSession, - .getCalendly, - .patchUser, - .patchSession, - .deleteSession: - return true - case .postMentee, .postMentor: - return false + case + .getSelf, + .getMentor, + .getMentee, + .getNote, + .patchNote, + .getSession, + .getSessions, + .postSession, + .getCalendly, + .patchUser, + .patchSession, + .deleteSession: + return true + case .postMentee, .postMentor: + return false } } @@ -127,7 +125,7 @@ enum APIRoute { var successCode: Int { switch self { - case .getSelf, .getMentor, .getMentee, .getNote, .patchNote, + case .getSelf, .getMentor, .getMentee, .getNote, .patchNote, .getSession, .getSessions, .getCalendly, .patchUser, .deleteSession, .patchSession: return 200 // 200 Ok case .postMentor, .postMentee, .postSession: @@ -140,7 +138,7 @@ enum APIRoute { let errorMap: [Int: AppError] switch self { - case .getSelf, .getMentor, .getMentee, .getNote, .patchNote, + case .getSelf, .getMentor, .getMentee, .getNote, .patchNote, .getSession, .getSessions, .getCalendly, .patchUser, .deleteSession, .patchSession: errorMap = [ @@ -157,7 +155,7 @@ enum APIRoute { 400: AppError.internalError(.invalidRequest, message: message) ] } - + let error = errorMap[statusCode] ?? AppError.internalError(.unknownError, message: labeledMessage) return error } diff --git a/backend/src/errors/service.ts b/backend/src/errors/service.ts index 124893cd..2742e3c7 100644 --- a/backend/src/errors/service.ts +++ b/backend/src/errors/service.ts @@ -49,7 +49,7 @@ export class ServiceError extends CustomError { static MENTOR_WAS_NOT_SAVED = new ServiceError(11, 404, MENTOR_WAS_NOT_SAVED); static MENTEE_WAS_NOT_SAVED = new ServiceError(12, 404, MENTEE_WAS_NOT_SAVED); - + static INVALID_ROLE_WAS_FOUND = new ServiceError(11, 404, INVALID_ROLE_WAS_FOUND); static ERROR_DELETING_EVENT = new ServiceError(7, 404, ERROR_DELETING_EVENT); diff --git a/backend/src/routes/sessions.ts b/backend/src/routes/sessions.ts index d089d211..2e61087e 100644 --- a/backend/src/routes/sessions.ts +++ b/backend/src/routes/sessions.ts @@ -53,8 +53,8 @@ router.post( } const accessToken = mentor.personalAccessToken; const data = await getCalendlyEventDate(req.body.calendlyURI, accessToken); - const startDate = new Date(2023, 0O5, 0O5, 17, 0, 0, 0); - const endDate = new Date(2023, 0O5, 0O5, 18, 0, 0, 0); + const startDate = new Date(2023, 0o5, 0o5, 17, 0, 0, 0); + const endDate = new Date(2023, 0o5, 0o5, 18, 0, 0, 0); const session = new Session({ preSession: null, @@ -80,7 +80,7 @@ router.post( session.postSessionMentee = postMenteeNoteId._id; session.postSessionMentor = postMentorNoteId._id; await session.save(); - + await sendNotification( "New session booked!", "You have a new session with " + mentee.name + ". Check out your session details \u{1F60E}", @@ -93,7 +93,7 @@ router.post( ". Fill out your pre-session notes now \u{1F60E}", mentee.fcmToken ); - + return res.status(201).json({ sessionId: session._id, mentorId: session.mentorId, @@ -327,14 +327,18 @@ router.patch( await Session.findByIdAndUpdate(sessionId, { $set: updates }, { new: true }); await sendNotification( "A session has been rescheduled", - "Your upcoming session with " + mentor.name + " has been rescheduled! Check out your new session details.", + "Your upcoming session with " + + mentor.name + + " has been rescheduled! Check out your new session details.", mentee.fcmToken - ) + ); await sendNotification( "A session has been rescheduled", - "" + mentee.name + " has rescheduled your upcoming session! Check out your session details.", + "" + + mentee.name + + " has rescheduled your upcoming session! Check out your session details.", mentor.fcmToken - ) + ); return res.status(200).json({ message: "Successfuly updated the session!", }); @@ -377,23 +381,25 @@ router.delete( "A session has been cancelled.", "Your session with " + mentor.name + " has been cancelled.", mentee.fcmToken - ) + ); await sendNotification( "A session has been cancelled.", "" + mentee.name + " has cancelled your upcoming session.", mentor.fcmToken - ) - } else if (role === "mentor") { + ); + } else if (role === "mentor") { await sendNotification( "A session has been cancelled.", "Your session with " + mentee.name + " has been cancelled.", mentor.fcmToken - ) - await sendNotification ( + ); + await sendNotification( "A session has been cancelled.", - "" + mentor.name + " has cancelled your upcoming session. \u{1F494} Reschedule to save your pre-session notes.", + "" + + mentor.name + + " has cancelled your upcoming session. \u{1F494} Reschedule to save your pre-session notes.", mentee.fcmToken - ) + ); } return res.status(200).json({ message: "calendly successfully cancelled, notes deleted, session deleted.", diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index 82a295de..8a571458 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -8,7 +8,14 @@ import mongoose from "mongoose"; import { validateReqBodyWithCake } from "../middleware/validation"; import { Mentee, Mentor, Pairing } from "../models"; import { createUser } from "../services/auth"; -import { getMenteeId, getMentorId, updateMentor, updateMentee, updateMentorFCMToken, updateMenteeFCMToken } from "../services/user"; +import { + getMenteeId, + getMentorId, + updateMentor, + updateMentee, + updateMentorFCMToken, + updateMenteeFCMToken, +} from "../services/user"; import { CreateMenteeRequestBodyCake, CreateMentorRequestBodyCake, @@ -457,7 +464,7 @@ router.patch( next(e); } } -) +); /** * * This route will update a mentor's values. diff --git a/backend/src/services/note.ts b/backend/src/services/note.ts index f9d13daf..f9060422 100644 --- a/backend/src/services/note.ts +++ b/backend/src/services/note.ts @@ -154,19 +154,23 @@ async function updateNotes(updatedNotes: UpdateNoteDetailsType[], documentId: st sessionDoc.preSessionCompleted = true; await sendNotification( "Pre-session update!", - "Looks like " + mentee.name + " has some questions for you. Check out " + mentee.name + "'s pre-session notes.", + "Looks like " + + mentee.name + + " has some questions for you. Check out " + + mentee.name + + "'s pre-session notes.", mentor.fcmToken ); - } - else if (noteDoc.type === "postMentor") { + } else if (noteDoc.type === "postMentor") { sessionDoc.postSessionMentorCompleted = true; await sendNotification( "Post-session update!", - "" + mentor.name + " has updated their post-session notes. Check out what they had to say!", + "" + + mentor.name + + " has updated their post-session notes. Check out what they had to say!", mentee.fcmToken ); - } - else if (noteDoc.type === "postMentee") sessionDoc.postSessionMenteeCompleted = true; + } else if (noteDoc.type === "postMentee") sessionDoc.postSessionMenteeCompleted = true; if (missedNote && sessionDoc.missedSessionReason == null) sessionDoc.missedSessionReason = missedReason; await sessionDoc.save(); diff --git a/backend/src/services/notifications.ts b/backend/src/services/notifications.ts index 6dcfcd98..9d905905 100644 --- a/backend/src/services/notifications.ts +++ b/backend/src/services/notifications.ts @@ -9,12 +9,11 @@ import { InternalError } from "../errors"; * cool with glasses - 1F60E * check mark - 2705 * broken heart - 1F494 - * + * * To find emojis and their unicode value, use https://apps.timwhitlock.info/emoji/tables/unicode * The unicode is in format "U+1234"; in code, use "\u{1234}" */ - async function sendNotification(title: string, body: string, deviceToken: string) { const message = { notification: { @@ -35,11 +34,12 @@ async function sendNotification(title: string, body: string, deviceToken: string }); } - async function startUpcomingSessionCronJob() { schedule.scheduleJob("*/1 * * * *", async () => { try { - const upcomingNotifSessions = await Session.find({ upcomingSessionNotifSent: { $eq: false } }); + const upcomingNotifSessions = await Session.find({ + upcomingSessionNotifSent: { $eq: false }, + }); upcomingNotifSessions.forEach(async (session) => { const dateNow = new Date(); const mentee = await Mentee.findById(session.menteeId); @@ -54,26 +54,26 @@ async function startUpcomingSessionCronJob() { if (session.preSessionCompleted) { const menteeNotif = await sendNotification( "You have an upcoming session.", - "Ready for your session with ${mentor.name} in 24 hours? \u{1F440}", + `Ready for your session with ${mentor.name} in 24 hours? \u{1F440}`, mentee.fcmToken ); console.log("Function executed successfully:", menteeNotif); const mentorNotif = await sendNotification( "You have an upcoming session.", - "Ready for your session with " + mentee.name + " in 24 hours? " + "\u{1F440}. Check out " + mentee.name + "'s pre-session notes.", + `Ready for your session with " + mentee.name + " in 24 hours? \u{1F440}. Check out " + mentee.name + "'s pre-session notes.`, mentor.fcmToken ); console.log("Function executed successfully:", mentorNotif); } else { const menteeNotif = await sendNotification( "You have an upcoming session.", - "Ready for your session with " + mentor.name + " in 24 hours? " + "\u{1F440}. Fill out your pre-session notes now!", + `Ready for your session with " + mentor.name + " in 24 hours? \u{1F440}. Fill out your pre-session notes now!`, mentee.fcmToken ); console.log("Function executed successfully:", menteeNotif); const mentorNotif = await sendNotification( "You have an upcoming session.", - "Ready for your session with " + mentee.name + " in 24 hours? " + "\u{1F440}", + `Ready for your session with ${mentee.name} in 24 hours? \u{1F440}`, mentor.fcmToken ); console.log("Function executed successfully:", mentorNotif); @@ -106,13 +106,17 @@ async function startPostSessionCronJob() { // mentee notification await sendNotification( "\u{2705} Session complete!", - "How did your session with " + mentor.name + " go? Jot it down in your post-session notes.", + "How did your session with " + + mentor.name + + " go? Jot it down in your post-session notes.", mentee.fcmToken ); // mentor notification await sendNotification( "\u{2705} Session complete!", - "How did your session with " + mentee.name + " go? Jot it down in your post-session notes.", + "How did your session with " + + mentee.name + + " go? Jot it down in your post-session notes.", mentor.fcmToken ); session.postSessionNotifSent = true; diff --git a/backend/src/services/user.ts b/backend/src/services/user.ts index e3fd640b..e05128fb 100644 --- a/backend/src/services/user.ts +++ b/backend/src/services/user.ts @@ -115,4 +115,12 @@ async function updateMentee(updatedMentee: UpdateMenteeRequestBodyType, userID: } } -export { getMentorId, getMenteeId, updateMentorFCMToken, updateMenteeFCMToken, updateMentor, updateMentee, saveImage }; +export { + getMentorId, + getMenteeId, + updateMentorFCMToken, + updateMenteeFCMToken, + updateMentor, + updateMentee, + saveImage, +}; diff --git a/backend/src/types/cakes.ts b/backend/src/types/cakes.ts index 50d2ead0..c7c5e099 100644 --- a/backend/src/types/cakes.ts +++ b/backend/src/types/cakes.ts @@ -40,7 +40,7 @@ export const CreateMentorRequestBodyCake = bake({ export const UpdateUserCake = bake({ fcmToken: string, uid: string, - role: string + role: string, }); export const UpdateMentorRequestBodyCake = bake({ name: string,