File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 11import { admins } from '../constants/HomeConsts' ;
2+
3+ /**
4+ * isAdmin – Checks whether a given user is an admin.
5+ *
6+ * @remarks
7+ * This function verifies if the user provided has an email that matches one of the predefined admin emails.
8+ *
9+ * @param {firebase.User | null } user – The Firebase user object to check. Can be `null`.
10+ *
11+ * @returns {boolean } – `true` if the user is an admin, otherwise `false`.
12+ */
13+
214export const isAdmin = ( user : firebase . User | null ) => {
315 if ( user && typeof user ?. email === 'string' && admins . includes ( user ?. email ) ) return true ;
416 return false ;
Original file line number Diff line number Diff line change 11import { ReviewWithId } from '../../../common/types/db-types' ;
22
3+ /**
4+ * getAverageRating – Calculates the average overall rating from an array of reviews.
5+ *
6+ * @remarks
7+ * This function sums the `overallRating` values of all reviews where the rating is greater than 0
8+ * and divides the sum by the total number of reviews in the array. If all reviews have a rating of 0,
9+ * the function returns 0.
10+ *
11+ * @param {ReviewWithId[] } reviewData – Array of ReviewWithId objects (reviews)
12+ *
13+ * @returns {number } – The average overall rating of the provided reviews.
14+ */
15+
316const getAverageRating = ( reviewData : ReviewWithId [ ] ) =>
417 reviewData . reduce (
518 ( currSum , { overallRating } ) => ( overallRating > 0 ? currSum + overallRating : currSum ) ,
Original file line number Diff line number Diff line change @@ -5,6 +5,19 @@ export type GetOptions<T> = {
55 errorHandler ?: ( ) => void ;
66 body ?: any ;
77} ;
8+ /**
9+ * get – Sends a GET request to the specified backend API endpoint.
10+ *
11+ * @remarks
12+ * This function simplifies the process of making a GET request using Axios by only requiring the route as it will
13+ * handle the callback, error console log, and error handling for you. This function doesn't return a value but will
14+ * execute the callback function (if provided) with the response data if successful.
15+ *
16+ * @param {string } route – The API endpoint to send the GET request to.
17+ * @param {GetOptions<T> } options – Optional parameters including: callback for handling the response, error handler
18+ * for handling request failures, and an optional request body.
19+ * @param {AxiosRequestConfig } inputConfig – Optional Axios configuration to customize the request.
20+ */
821
922const get = < T > ( route : string , options : GetOptions < T > = { } , inputConfig ?: AxiosRequestConfig ) => {
1023 const { callback, errorHandler, body } = options ;
You can’t perform that action at this time.
0 commit comments