From bc556f287d11408b14c816f9044d7472958afb45 Mon Sep 17 00:00:00 2001
From: Alberto Defendi <1369-ahl-berto@users.noreply.gitlab.inf.unibz.it>
Date: Mon, 21 Jun 2021 08:43:07 +0200
Subject: [PATCH] Document api components.

---
 src/api/getReservationsList.ts     |  7 ++++++-
 src/api/getRoleObject.ts           |  4 ++++
 src/api/getSeniorList.ts           |  9 ---------
 src/api/getSeniorListByCard.ts     |  6 ++++++
 src/api/getSeniorListByLastName.ts | 17 +++++++++++++++++
 src/api/postCredentials.ts         |  6 ++++++
 src/api/registerSenior.ts          |  6 ++++++
 src/api/setReservation.ts          |  6 ++++++
 src/api/setRole.ts                 |  2 +-
 src/api/userRoles.ts               |  9 ---------
 10 files changed, 52 insertions(+), 20 deletions(-)
 delete mode 100644 src/api/getSeniorList.ts
 create mode 100644 src/api/getSeniorListByLastName.ts
 delete mode 100644 src/api/userRoles.ts

diff --git a/src/api/getReservationsList.ts b/src/api/getReservationsList.ts
index 51ff935..1730150 100644
--- a/src/api/getReservationsList.ts
+++ b/src/api/getReservationsList.ts
@@ -1,5 +1,10 @@
 import axios from 'axios';
 import { ReservationType } from 'types/ReservationType';
 
+/**
+ * @async
+ * Perform GET to get a list of all the reservations inserted by the current user.
+ * @returns a list of reservations.
+ */
 export const getReservationsList = async (): Promise<ReservationType[]> =>
-  axios(`/api/web/reservations/?field=trip_stages`).then((res) => res.data);
+  axios(`/api/web/reservations?fields=trip_stages`).then((res) => res.data);
diff --git a/src/api/getRoleObject.ts b/src/api/getRoleObject.ts
index d1cee65..0664db0 100644
--- a/src/api/getRoleObject.ts
+++ b/src/api/getRoleObject.ts
@@ -1,5 +1,9 @@
 import axios from 'axios';
 import { RoleObjectType } from '../types/RoleObjectType';
 
+/**
+ *
+ * @returns {RoleObjectType}
+ */
 export const getRoleObject = async (): Promise<RoleObjectType> =>
   axios('/api/web/login/get_role').then((res) => res.data.roleObject);
diff --git a/src/api/getSeniorList.ts b/src/api/getSeniorList.ts
deleted file mode 100644
index 271854d..0000000
--- a/src/api/getSeniorList.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import axios from 'axios';
-import { SeniorSearchQueryType } from '../types/SeniorSearchQueryType';
-
-export const getSeniorList = async (
-  name: string,
-): Promise<SeniorSearchQueryType[]> =>
-  axios
-    .get(`/api/web/seniors/by_name/${name}?fields=user,id,member_card_number`)
-    .then((res) => res.data);
diff --git a/src/api/getSeniorListByCard.ts b/src/api/getSeniorListByCard.ts
index ed9bfec..e8a066f 100644
--- a/src/api/getSeniorListByCard.ts
+++ b/src/api/getSeniorListByCard.ts
@@ -1,6 +1,12 @@
 import axios from 'axios';
 import { SeniorSearchQueryType } from '../types/SeniorSearchQueryType';
 
+/**
+ * @async
+ * Search and return a senior list linked by the card.
+ * @param card card number to search.
+ * @returns {SeniorSearchQueryType[]} list of seniors.
+ */
 export const getSeniorListByCard = async (
   card: number,
 ): Promise<SeniorSearchQueryType[]> =>
diff --git a/src/api/getSeniorListByLastName.ts b/src/api/getSeniorListByLastName.ts
new file mode 100644
index 0000000..28c88dc
--- /dev/null
+++ b/src/api/getSeniorListByLastName.ts
@@ -0,0 +1,17 @@
+import axios from 'axios';
+import { SeniorSearchQueryType } from '../types/SeniorSearchQueryType';
+
+/**
+ * @async
+ * Search and return a senior list linked to the last name.
+ * @param lastName to search.
+ * @returns {SeniorSearchQueryType[]} list of seniors.
+ */
+export const getSeniorListByLastName = async (
+  lastName: string,
+): Promise<SeniorSearchQueryType[]> =>
+  axios
+    .get(
+      `/api/web/seniors/by_name/${lastName}?fields=user,id,member_card_number`,
+    )
+    .then((res) => res.data);
diff --git a/src/api/postCredentials.ts b/src/api/postCredentials.ts
index 78a9b0b..c9aa54f 100644
--- a/src/api/postCredentials.ts
+++ b/src/api/postCredentials.ts
@@ -1,6 +1,12 @@
 import axios from 'axios';
 import { CredentialsType } from 'types/CredentialsType';
 
+/**
+ * @async
+ * Post the user credentials on the server. Used to authenticate the user on the platform.
+ * @param values credentials of the user.
+ * @returns {string} response status (see backend docs for status codes).
+ */
 export const postCredentials = async (
   values: CredentialsType,
 ): Promise<string> =>
diff --git a/src/api/registerSenior.ts b/src/api/registerSenior.ts
index d9e3a16..6f4b9b1 100644
--- a/src/api/registerSenior.ts
+++ b/src/api/registerSenior.ts
@@ -1,6 +1,12 @@
 import axios from 'axios';
 import { RegisterSeniorType } from 'types/RegisterSeniorType';
 
+/**
+ * @async
+ * Create an account for the senior on the platform.
+ * @param values values of the new account.
+ * @returns {Promise<void>}.
+ */
 export const registerSenior = async (
   values: RegisterSeniorType,
 ): Promise<void> =>
diff --git a/src/api/setReservation.ts b/src/api/setReservation.ts
index e8c2e61..d99c48d 100644
--- a/src/api/setReservation.ts
+++ b/src/api/setReservation.ts
@@ -1,6 +1,12 @@
 import axios from 'axios';
 import { ReservationType } from 'types/ReservationType';
 
+/**
+ * @async
+ * Register a reservation to the server.
+ * @param reservation data of the reservation.
+ * @returns {Promise<void>}.
+ */
 export const setReservation = async (
   reservation: ReservationType,
 ): Promise<void> => axios.post('/api/web/reservations/', reservation);
diff --git a/src/api/setRole.ts b/src/api/setRole.ts
index 27087fb..073fe69 100644
--- a/src/api/setRole.ts
+++ b/src/api/setRole.ts
@@ -3,7 +3,7 @@ import axios from 'axios';
 /**
  * @async
  * Set the role of the user in the database.
- * @return {string} role
+ * @return {string} role.
  */
 export const setRole = async (role: string): Promise<void> =>
   axios.post('/api/web/login/set_role', { role });
diff --git a/src/api/userRoles.ts b/src/api/userRoles.ts
deleted file mode 100644
index 77e6643..0000000
--- a/src/api/userRoles.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export enum Roles {
-  /** Website visitor, is not logged. Can access to NonAuthRoutes */
-  visitor = '',
-  /** Can access to routes wrapped by withAuthorization. */
-  senior = 'senior',
-  admin = 'admin',
-  operator = 'operator',
-  driver = 'driver',
-}
-- 
GitLab