@movalib/movalib-commons 1.0.93 → 1.0.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.request = exports.API_BASE_URL = void 0;
7
7
  var CookieUtils_1 = require("./CookieUtils");
8
8
  var Logger_1 = __importDefault(require("./Logger"));
9
+ var react_router_dom_1 = require("react-router-dom");
9
10
  exports.API_BASE_URL = process.env.REACT_APP_API_URL || 'https://localhost:8443/api';
10
11
  function handleError(error) {
11
12
  var msg = error.message.includes('fetch') ? "Connexion impossible" : error.message;
@@ -17,6 +18,7 @@ function handleError(error) {
17
18
  function handleResponse(response) {
18
19
  var contentType = response.headers.get("content-type");
19
20
  var isJson = contentType && contentType.includes("application/json");
21
+ var history = (0, react_router_dom_1.useHistory)();
20
22
  var dataPromise = isJson ? response.json() : response.text();
21
23
  return dataPromise.then(function (data) {
22
24
  if (!response.ok) {
@@ -29,6 +31,11 @@ function handleResponse(response) {
29
31
  case 404:
30
32
  errorMsg = 'La ressource demandée est introuvable (404)';
31
33
  break;
34
+ case 407:
35
+ // On redirige l'utilisateur vers la page de login (407 = compte utilisateur introuvable, authentification requise)
36
+ errorMsg = (typeof data === 'string') ? data : "Compte introuvable, veuillez vous reconnecter (".concat(response.status, ")");
37
+ history.push('/login');
38
+ break;
32
39
  case 500:
33
40
  errorMsg = 'Une erreur interne du serveur est survenue (500)';
34
41
  break;
@@ -18,8 +18,8 @@ export default class Prestation {
18
18
  */
19
19
  operations?: Operation[];
20
20
  /**
21
- * La notion d'ordre peut être utile à l'affichage d'une liste de prestation par exemple
21
+ * La notion de position (ou d'ordre) peut être utile à l'affichage d'une liste de prestation par exemple
22
22
  */
23
- order: number;
24
- constructor(id: number, code: string, name: string, description: string, category: string, downtime: number, appointmentDelay: number, order: number, operations?: Operation[]);
23
+ position: number;
24
+ constructor(id: number, code: string, name: string, description: string, category: string, downtime: number, appointmentDelay: number, position: number, operations?: Operation[]);
25
25
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var Prestation = /** @class */ (function () {
4
- function Prestation(id, code, name, description, category, downtime, appointmentDelay, order, operations) {
4
+ function Prestation(id, code, name, description, category, downtime, appointmentDelay, position, operations) {
5
5
  this.id = id;
6
6
  this.code = code;
7
7
  this.name = name;
@@ -9,7 +9,7 @@ var Prestation = /** @class */ (function () {
9
9
  this.category = category;
10
10
  this.downtime = downtime;
11
11
  this.appointmentDelay = appointmentDelay;
12
- this.order = order;
12
+ this.position = position;
13
13
  this.operations = operations;
14
14
  }
15
15
  return Prestation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.0.93",
3
+ "version": "1.0.95",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,7 @@
1
1
  import { APIMethod } from "./Enums";
2
2
  import { COOKIE_GARAGE_TOKEN, readCookie } from "./CookieUtils";
3
3
  import Logger from "./Logger";
4
+ import { useHistory } from "react-router-dom";
4
5
 
5
6
  export const API_BASE_URL = process.env.REACT_APP_API_URL || 'https://localhost:8443/api';
6
7
 
@@ -28,7 +29,7 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
28
29
 
29
30
  const contentType = response.headers.get("content-type");
30
31
  const isJson = contentType && contentType.includes("application/json");
31
-
32
+ const history = useHistory();
32
33
  const dataPromise = isJson ? response.json() : response.text();
33
34
 
34
35
  return dataPromise.then(data => {
@@ -44,6 +45,11 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
44
45
  errorMsg = 'Accès non autorisé (403)'; break;
45
46
  case 404:
46
47
  errorMsg = 'La ressource demandée est introuvable (404)'; break;
48
+ case 407:
49
+ // On redirige l'utilisateur vers la page de login (407 = compte utilisateur introuvable, authentification requise)
50
+ errorMsg = (typeof data === 'string') ? data : `Compte introuvable, veuillez vous reconnecter (${response.status})`;
51
+ history.push('/login');
52
+ break;
47
53
  case 500:
48
54
  errorMsg = 'Une erreur interne du serveur est survenue (500)'; break;
49
55
  default:
@@ -21,12 +21,12 @@ export default class Prestation {
21
21
  */
22
22
  operations?: Operation[];
23
23
  /**
24
- * La notion d'ordre peut être utile à l'affichage d'une liste de prestation par exemple
24
+ * La notion de position (ou d'ordre) peut être utile à l'affichage d'une liste de prestation par exemple
25
25
  */
26
- order: number;
26
+ position: number;
27
27
 
28
28
  constructor(id:number, code: string, name:string, description: string, category:string,
29
- downtime:number, appointmentDelay: number, order: number, operations?: Operation[]) {
29
+ downtime:number, appointmentDelay: number, position: number, operations?: Operation[]) {
30
30
  this.id = id;
31
31
  this.code = code;
32
32
  this.name = name;
@@ -34,7 +34,7 @@ export default class Prestation {
34
34
  this.category = category;
35
35
  this.downtime = downtime;
36
36
  this.appointmentDelay = appointmentDelay;
37
- this.order = order;
37
+ this.position = position;
38
38
  this.operations = operations;
39
39
  }
40
40
  }