Skip to content

Commit

Permalink
Add jsdoc to frontend services
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Sep 25, 2023
1 parent d4c2ee4 commit caec157
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 16 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/SupplierSelectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const SupplierSelectList = ({
const _fetch = async (page: number, keyword: string, onFetch?: (data: { rows: any[], rowCount: number }) => void) => {
try {
setLoading(true)
const data = await SupplierService.getCompanies(keyword, page, Env.PAGE_SIZE)
const data = await SupplierService.getSuppliers(keyword, page, Env.PAGE_SIZE)
const _data = data && data.length > 0 ? data[0] : { pageInfo: { totalRecord: 0 }, resultData: [] }
if (!_data) {
Helper.error()
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Bookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Bookings = () => {
setUser(user)
setLoadingCompanies(true)

const allCompanies = await SupplierService.getAllCompanies()
const allCompanies = await SupplierService.getAllSuppliers()
const companies = bookcarsHelper.flattenCompanies(allCompanies)
setAllCompanies(allCompanies)
setCompanies(companies)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Cars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const Cars = () => {
return
}

const allCompanies = await SupplierService.getAllCompanies()
const allCompanies = await SupplierService.getAllSuppliers()
const companies = bookcarsHelper.flattenCompanies(allCompanies)

setPickupLocation(pickupLocation)
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/services/BookingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import Env from '../config/env.config'
import * as UserService from './UserService'
import * as bookcarsTypes from 'bookcars-types'

/**
* Complete the checkout process and create the Booking.
*
* @param {bookcarsTypes.BookPayload} data
* @returns {Promise<number>}
*/
export const book = (data: bookcarsTypes.BookPayload): Promise<number> =>
axios
.post(
Expand All @@ -11,6 +17,12 @@ export const book = (data: bookcarsTypes.BookPayload): Promise<number> =>
)
.then((res) => res.status)

/**
* Update a Booking.
*
* @param {bookcarsTypes.UpsertBookingPayload} data
* @returns {Promise<number>}
*/
export const update = (data: bookcarsTypes.UpsertBookingPayload): Promise<number> =>
axios
.put(`${Env.API_HOST}/api/update-booking`,
Expand All @@ -19,6 +31,14 @@ export const update = (data: bookcarsTypes.UpsertBookingPayload): Promise<number
)
.then((res) => res.status)

/**
* Get bookings.
*
* @param {bookcarsTypes.GetBookingsPayload} payload
* @param {number} page
* @param {number} size
* @returns {Promise<bookcarsTypes.Result<bookcarsTypes.Booking>>}
*/
export const getBookings = (payload: bookcarsTypes.GetBookingsPayload, page: number, size: number): Promise<bookcarsTypes.Result<bookcarsTypes.Booking>> =>
axios
.post(
Expand All @@ -28,6 +48,12 @@ export const getBookings = (payload: bookcarsTypes.GetBookingsPayload, page: num
)
.then((res) => res.data)

/**
* Get a Booking by ID.
*
* @param {string} id
* @returns {Promise<bookcarsTypes.Booking>}
*/
export const getBooking = (id: string): Promise<bookcarsTypes.Booking> =>
axios
.get(
Expand All @@ -36,6 +62,12 @@ export const getBooking = (id: string): Promise<bookcarsTypes.Booking> =>
)
.then((res) => res.data)

/**
* Cancel a Booking.
*
* @param {string} id
* @returns {Promise<number>}
*/
export const cancel = (id: string): Promise<number> =>
axios
.post(
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/services/CarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,43 @@ import Env from '../config/env.config'
import * as UserService from './UserService'
import * as bookcarsTypes from 'bookcars-types'

/**
* Get cars.
*
* @param {bookcarsTypes.GetCarsPayload} data
* @param {number} page
* @param {number} size
* @returns {Promise<bookcarsTypes.Result<bookcarsTypes.Car>>}
*/
export const getCars = (data: bookcarsTypes.GetCarsPayload, page: number, size: number): Promise<bookcarsTypes.Result<bookcarsTypes.Car>> =>
axios
.post(
`${Env.API_HOST}/api/frontend-cars/${page}/${size}}`,
data
).then((res) => res.data)

/**
* Get a Car by ID.
*
* @param {string} id
* @returns {Promise<bookcarsTypes.Car>}
*/
export const getCar = (id: string): Promise<bookcarsTypes.Car> =>
axios
.get(
`${Env.API_HOST}/api/car/${encodeURIComponent(id)}/${UserService.getLanguage()}`
)
.then((res) => res.data)

/**
* Get cars by agency and location.
*
* @param {string} keyword
* @param {bookcarsTypes.GetBookingCarsPayload} data
* @param {number} page
* @param {number} size
* @returns {Promise<bookcarsTypes.Car[]>}
*/
export const getBookingCars = (keyword: string, data: bookcarsTypes.GetBookingCarsPayload, page: number, size: number): Promise<bookcarsTypes.Car[]> =>
axios
.post(
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/services/LocationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@ import Env from '../config/env.config'
import * as UserService from './UserService'
import * as bookcarsTypes from 'bookcars-types'

/**
* Get locations.
*
* @param {string} keyword
* @param {number} page
* @param {number} size
* @returns {Promise<bookcarsTypes.Result<bookcarsTypes.Location>>}
*/
export const getLocations = (keyword: string, page: number, size: number): Promise<bookcarsTypes.Result<bookcarsTypes.Location>> =>
axios
.get(
`${Env.API_HOST}/api/locations/${page}/${size}/${UserService.getLanguage()}/?s=${encodeURIComponent(keyword)}`
)
.then((res) => res.data)

/**
* Get a Location by ID.
*
* @param {string} id
* @returns {Promise<bookcarsTypes.Location>}
*/
export const getLocation = (id: string): Promise<bookcarsTypes.Location> =>
axios
.get(
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import Env from '../config/env.config'
import * as UserService from './UserService'
import * as bookcarsTypes from 'bookcars-types'

/**
* Get NotificationCounter by UserID.
*
* @param {string} userId
* @returns {Promise<bookcarsTypes.NotificationCounter>}
*/
export const getNotificationCounter = (userId: string): Promise<bookcarsTypes.NotificationCounter> => (
axios
.get(
Expand All @@ -12,6 +18,13 @@ export const getNotificationCounter = (userId: string): Promise<bookcarsTypes.No
.then((res) => res.data)
)

/**
* Mark notifications as read.
*
* @param {string} userId
* @param {string[]} ids
* @returns {Promise<number>}
*/
export const markAsRead = (userId: string, ids: string[]): Promise<number> => (
axios
.post(
Expand All @@ -22,6 +35,13 @@ export const markAsRead = (userId: string, ids: string[]): Promise<number> => (
.then((res) => res.status)
)

/**
* Mark notifications as unread.
*
* @param {string} userId
* @param {string[]} ids
* @returns {Promise<number>}
*/
export const markAsUnread = (userId: string, ids: string[]): Promise<number> => (
axios
.post(`${Env.API_HOST}/api/mark-notifications-as-unread/${encodeURIComponent(userId)}`,
Expand All @@ -31,6 +51,13 @@ export const markAsUnread = (userId: string, ids: string[]): Promise<number> =>
.then((res) => res.status)
)

/**
* Delete notifications.
*
* @param {string} userId
* @param {string[]} ids
* @returns {Promise<number>}
*/
export const deleteNotifications = (userId: string, ids: string[]): Promise<number> => (
axios
.post(
Expand All @@ -40,6 +67,13 @@ export const deleteNotifications = (userId: string, ids: string[]): Promise<numb
.then((res) => res.status)
)

/**
* Get notifications.
*
* @param {string} userId
* @param {number} page
* @returns {Promise<bookcarsTypes.Result<bookcarsTypes.Notification>>}
*/
export const getNotifications = (userId: string, page: number): Promise<bookcarsTypes.Result<bookcarsTypes.Notification>> => (
axios
.get(
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/services/SupplierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ import Env from '../config/env.config'
import * as UserService from './UserService'
import * as bookcarsTypes from 'bookcars-types'

export const getAllCompanies = (): Promise<bookcarsTypes.User[]> =>
/**
* Get all suppliers.
*
* @returns {Promise<bookcarsTypes.User[]>}
*/
export const getAllSuppliers = (): Promise<bookcarsTypes.User[]> =>
axios
.get(
`${Env.API_HOST}/api/all-suppliers`,
{ headers: UserService.authHeader() })
.then((res) => res.data)


export const getCompanies = (keyword: string, page: number, size: number): Promise<bookcarsTypes.Result<bookcarsTypes.User>> =>
/**
* Get suppliers.
*
* @param {string} keyword
* @param {number} page
* @param {number} size
* @returns {Promise<bookcarsTypes.Result<bookcarsTypes.User>>}
*/
export const getSuppliers = (keyword: string, page: number, size: number): Promise<bookcarsTypes.Result<bookcarsTypes.User>> =>
axios
.get(
`${Env.API_HOST}/api/suppliers/${page}/${size}/?s=${encodeURIComponent(keyword)}`,
Expand Down
Loading

0 comments on commit caec157

Please sign in to comment.