@movalib/movalib-commons 1.40.0 → 1.41.1
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.
- package/devIndex.tsx +1 -1
- package/dist/devIndex.js +1 -1
- package/dist/src/helpers/ApiHelper.d.ts +0 -1
- package/dist/src/helpers/ApiHelper.js +0 -1
- package/dist/src/services/GarageService.d.ts +3 -0
- package/dist/src/services/GarageService.js +28 -0
- package/dist/src/services/GarageService.types.d.ts +25 -0
- package/dist/src/services/GarageService.types.js +2 -0
- package/dist/src/services/VehicleService.d.ts +2 -0
- package/dist/src/services/VehicleService.js +19 -0
- package/dist/src/services/VehicleService.types.d.ts +13 -0
- package/dist/src/services/VehicleService.types.js +2 -0
- package/package.json +1 -1
- package/src/helpers/ApiHelper.ts +23 -11
- package/src/services/GarageService.ts +18 -0
- package/src/services/GarageService.types.ts +28 -0
- package/src/services/VehicleService.ts +9 -0
- package/src/services/VehicleService.types.ts +16 -0
package/devIndex.tsx
CHANGED
package/dist/devIndex.js
CHANGED
|
@@ -15,7 +15,6 @@ export type APIRequest = {
|
|
|
15
15
|
* ATTENTION : cela signifie que toutes les requêtes du Front seront de type "preflight"
|
|
16
16
|
* Il faut penser à configurer l'API pour autoriser les headers
|
|
17
17
|
* @param options
|
|
18
|
-
* @param dispatch
|
|
19
18
|
* @returns
|
|
20
19
|
*/
|
|
21
20
|
export declare const request: (options: APIRequest) => Promise<APIResponse<any>>;
|
|
@@ -46,7 +46,6 @@ function handleResponse(response) {
|
|
|
46
46
|
* ATTENTION : cela signifie que toutes les requêtes du Front seront de type "preflight"
|
|
47
47
|
* Il faut penser à configurer l'API pour autoriser les headers
|
|
48
48
|
* @param options
|
|
49
|
-
* @param dispatch
|
|
50
49
|
* @returns
|
|
51
50
|
*/
|
|
52
51
|
var request = function (options) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { APIResponse } from "../helpers/ApiHelper";
|
|
2
2
|
import Employee from "../models/Employee";
|
|
3
3
|
import Garage from "../models/Garage";
|
|
4
|
+
import { AddCustomerVehicleParams, DeleteCustomerVehicleParams } from "./GarageService.types";
|
|
4
5
|
export default class GarageService {
|
|
5
6
|
static updateVehicleGarageEvent(garageId: string, eventId: string, req: any): Promise<APIResponse<string>>;
|
|
6
7
|
static sendGarageMandate(garageId: string): Promise<APIResponse<string>>;
|
|
@@ -34,4 +35,6 @@ export default class GarageService {
|
|
|
34
35
|
static sendGarageSupportRequest(garageId: string, req: {
|
|
35
36
|
message: string;
|
|
36
37
|
}): Promise<APIResponse<string>>;
|
|
38
|
+
static addCustomerVehicle({ garageId, customerId, ...payload }: AddCustomerVehicleParams): Promise<APIResponse<string>>;
|
|
39
|
+
static deleteCustomerVehicle({ garageId, customerId, vehicleId }: DeleteCustomerVehicleParams): Promise<APIResponse<string>>;
|
|
37
40
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
var ApiHelper_1 = require("../helpers/ApiHelper");
|
|
4
15
|
var Enums_1 = require("../helpers/Enums");
|
|
@@ -234,6 +245,23 @@ var GarageService = /** @class */ (function () {
|
|
|
234
245
|
body: JSON.stringify(req)
|
|
235
246
|
});
|
|
236
247
|
};
|
|
248
|
+
GarageService.addCustomerVehicle = function (_a) {
|
|
249
|
+
var garageId = _a.garageId, customerId = _a.customerId, payload = __rest(_a, ["garageId", "customerId"]);
|
|
250
|
+
return (0, ApiHelper_1.request)({
|
|
251
|
+
url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/customers/").concat(customerId, "/vehicles"),
|
|
252
|
+
method: Enums_1.APIMethod.POST,
|
|
253
|
+
appType: Enums_1.MovaAppType.GARAGE,
|
|
254
|
+
body: JSON.stringify(payload)
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
GarageService.deleteCustomerVehicle = function (_a) {
|
|
258
|
+
var garageId = _a.garageId, customerId = _a.customerId, vehicleId = _a.vehicleId;
|
|
259
|
+
return (0, ApiHelper_1.request)({
|
|
260
|
+
url: "".concat(ApiHelper_1.API_BASE_URL, "/garage/").concat(garageId, "/customers/").concat(customerId, "/vehicles/").concat(vehicleId),
|
|
261
|
+
method: Enums_1.APIMethod.DELETE,
|
|
262
|
+
appType: Enums_1.MovaAppType.GARAGE,
|
|
263
|
+
});
|
|
264
|
+
};
|
|
237
265
|
return GarageService;
|
|
238
266
|
}());
|
|
239
267
|
exports.default = GarageService;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type AddCustomerVehicleParams = {
|
|
2
|
+
/** L'identifiant unique du garage */
|
|
3
|
+
garageId: string;
|
|
4
|
+
/** L'identifiant unique du client */
|
|
5
|
+
customerId: string;
|
|
6
|
+
/** La plaque d'immat du véhicule */
|
|
7
|
+
plate: string;
|
|
8
|
+
/** Le nombre de km au compteur */
|
|
9
|
+
currentMileage?: number;
|
|
10
|
+
/** Le nombre moyen de km par an */
|
|
11
|
+
averageMileagePerYear?: number;
|
|
12
|
+
/** Identification du pneu (XXX XX RXX XXX) */
|
|
13
|
+
tireWidth?: string;
|
|
14
|
+
tireHeight?: string;
|
|
15
|
+
tireDiameter?: string;
|
|
16
|
+
tireSpeedIndex?: string;
|
|
17
|
+
};
|
|
18
|
+
export type DeleteCustomerVehicleParams = {
|
|
19
|
+
/** L'identifiant unique du garage */
|
|
20
|
+
garageId: string;
|
|
21
|
+
/** L'identifiant unique du client */
|
|
22
|
+
customerId: string;
|
|
23
|
+
/** L'identifiant unique du véhicule */
|
|
24
|
+
vehicleId: string;
|
|
25
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { APIResponse } from "../helpers/ApiHelper";
|
|
2
2
|
import { MovaAppType } from "../helpers/Enums";
|
|
3
|
+
import { EditVehicleParams } from "./VehicleService.types";
|
|
3
4
|
export default class VehicleService {
|
|
4
5
|
static getVehicleDescription(appType: MovaAppType, plate: string): Promise<APIResponse<string>>;
|
|
6
|
+
static editVehicle({ vehicleId, ...payload }: EditVehicleParams): Promise<APIResponse<string>>;
|
|
5
7
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
var ApiHelper_1 = require("../helpers/ApiHelper");
|
|
4
15
|
var Enums_1 = require("../helpers/Enums");
|
|
@@ -12,6 +23,14 @@ var VehicleService = /** @class */ (function () {
|
|
|
12
23
|
appType: appType,
|
|
13
24
|
});
|
|
14
25
|
};
|
|
26
|
+
VehicleService.editVehicle = function (_a) {
|
|
27
|
+
var vehicleId = _a.vehicleId, payload = __rest(_a, ["vehicleId"]);
|
|
28
|
+
return (0, ApiHelper_1.request)({
|
|
29
|
+
url: "".concat(ApiHelper_1.API_BASE_URL, "/vehicle/").concat(vehicleId),
|
|
30
|
+
method: Enums_1.APIMethod.PATCH,
|
|
31
|
+
body: JSON.stringify(payload)
|
|
32
|
+
});
|
|
33
|
+
};
|
|
15
34
|
return VehicleService;
|
|
16
35
|
}());
|
|
17
36
|
exports.default = VehicleService;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type EditVehicleParams = {
|
|
2
|
+
/** Identifiant unique du véhicule */
|
|
3
|
+
vehicleId: string;
|
|
4
|
+
/** Nombre de km au compteur */
|
|
5
|
+
currentMileage: number;
|
|
6
|
+
/** Nombre de km annuel moyen */
|
|
7
|
+
averageMileagePerYear: number;
|
|
8
|
+
/** Identification du pneu (XXX XX RXX XXX) */
|
|
9
|
+
tireWidth: string;
|
|
10
|
+
tireHeight: string;
|
|
11
|
+
tireDiameter: string;
|
|
12
|
+
tireSpeedIndex: string;
|
|
13
|
+
};
|
package/package.json
CHANGED
package/src/helpers/ApiHelper.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { APIMethod, MovaAppType } from "./Enums";
|
|
2
2
|
import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, readCookie } from "./CookieUtils";
|
|
3
3
|
import Logger from "./Logger";
|
|
4
|
-
import { useHistory } from "react-router-dom";
|
|
5
4
|
|
|
6
5
|
export const API_BASE_URL = process.env.REACT_APP_API_URL || 'https://localhost:8443/api';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
success:
|
|
10
|
-
data
|
|
11
|
-
|
|
7
|
+
type APISuccess<T> = {
|
|
8
|
+
success: true;
|
|
9
|
+
data: T;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type APIError = {
|
|
13
|
+
success: false;
|
|
14
|
+
error: string;
|
|
12
15
|
};
|
|
16
|
+
// This inference type is not ready yet, we have to be sure
|
|
17
|
+
// that we handle all the backend return cases before changing this
|
|
18
|
+
// export type APIResponse<T> = APISuccess<T> | APIError;
|
|
19
|
+
|
|
20
|
+
export type APIResponse<T> = {
|
|
21
|
+
success: boolean,
|
|
22
|
+
data?: T,
|
|
23
|
+
error?: string
|
|
24
|
+
|
|
25
|
+
}
|
|
13
26
|
|
|
14
27
|
export type APIRequest = {
|
|
15
28
|
url: string,
|
|
@@ -33,7 +46,7 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
|
|
|
33
46
|
const dataPromise = isJson ? response.json() : response.text();
|
|
34
47
|
|
|
35
48
|
return dataPromise.then(data => {
|
|
36
|
-
|
|
49
|
+
|
|
37
50
|
if (!response.ok) {
|
|
38
51
|
|
|
39
52
|
Logger.error(data);
|
|
@@ -53,7 +66,7 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
|
|
|
53
66
|
|
|
54
67
|
return { success: false, error: errorMsg };
|
|
55
68
|
}
|
|
56
|
-
|
|
69
|
+
|
|
57
70
|
return { success: true, data };
|
|
58
71
|
});
|
|
59
72
|
}
|
|
@@ -62,9 +75,8 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
|
|
|
62
75
|
/**
|
|
63
76
|
* ATTENTION : cela signifie que toutes les requêtes du Front seront de type "preflight"
|
|
64
77
|
* Il faut penser à configurer l'API pour autoriser les headers
|
|
65
|
-
* @param options
|
|
66
|
-
* @
|
|
67
|
-
* @returns
|
|
78
|
+
* @param options
|
|
79
|
+
* @returns
|
|
68
80
|
*/
|
|
69
81
|
export const request = (options:APIRequest): Promise<APIResponse<any>> => {
|
|
70
82
|
|
|
@@ -103,4 +115,4 @@ export const request = (options:APIRequest): Promise<APIResponse<any>> => {
|
|
|
103
115
|
Logger.error('There has been a problem with your fetch operation : ', error.message);
|
|
104
116
|
return handleError(error);
|
|
105
117
|
});
|
|
106
|
-
}
|
|
118
|
+
}
|
|
@@ -2,6 +2,7 @@ import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
|
|
|
2
2
|
import { APIMethod, MovaAppType } from "../helpers/Enums";
|
|
3
3
|
import Employee from "../models/Employee";
|
|
4
4
|
import Garage from "../models/Garage";
|
|
5
|
+
import {AddCustomerVehicleParams, DeleteCustomerVehicleParams} from "./GarageService.types";
|
|
5
6
|
|
|
6
7
|
export default class GarageService {
|
|
7
8
|
|
|
@@ -270,4 +271,21 @@ export default class GarageService {
|
|
|
270
271
|
});
|
|
271
272
|
}
|
|
272
273
|
|
|
274
|
+
static addCustomerVehicle({garageId, customerId, ...payload}: AddCustomerVehicleParams):Promise<APIResponse<string>> {
|
|
275
|
+
return request({
|
|
276
|
+
url: `${API_BASE_URL}/garage/${garageId}/customers/${customerId}/vehicles`,
|
|
277
|
+
method: APIMethod.POST,
|
|
278
|
+
appType: MovaAppType.GARAGE,
|
|
279
|
+
body: JSON.stringify(payload)
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
static deleteCustomerVehicle({garageId, customerId, vehicleId}: DeleteCustomerVehicleParams):Promise<APIResponse<string>> {
|
|
284
|
+
return request({
|
|
285
|
+
url: `${API_BASE_URL}/garage/${garageId}/customers/${customerId}/vehicles/${vehicleId}`,
|
|
286
|
+
method: APIMethod.DELETE,
|
|
287
|
+
appType: MovaAppType.GARAGE,
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
|
|
273
291
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type AddCustomerVehicleParams = {
|
|
2
|
+
/** L'identifiant unique du garage */
|
|
3
|
+
garageId: string;
|
|
4
|
+
/** L'identifiant unique du client */
|
|
5
|
+
customerId: string;
|
|
6
|
+
/** La plaque d'immat du véhicule */
|
|
7
|
+
plate: string;
|
|
8
|
+
/** Le nombre de km au compteur */
|
|
9
|
+
currentMileage?: number;
|
|
10
|
+
/** Le nombre moyen de km par an */
|
|
11
|
+
averageMileagePerYear?: number;
|
|
12
|
+
|
|
13
|
+
/** Identification du pneu (XXX XX RXX XXX) */
|
|
14
|
+
tireWidth?: string;
|
|
15
|
+
tireHeight?: string;
|
|
16
|
+
tireDiameter?: string;
|
|
17
|
+
tireSpeedIndex?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export type DeleteCustomerVehicleParams = {
|
|
22
|
+
/** L'identifiant unique du garage */
|
|
23
|
+
garageId: string;
|
|
24
|
+
/** L'identifiant unique du client */
|
|
25
|
+
customerId: string;
|
|
26
|
+
/** L'identifiant unique du véhicule */
|
|
27
|
+
vehicleId: string;
|
|
28
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
|
|
2
2
|
import { APIMethod, MovaAppType } from "../helpers/Enums";
|
|
3
|
+
import {EditVehicleParams} from "./VehicleService.types";
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
export default class VehicleService {
|
|
@@ -12,4 +13,12 @@ export default class VehicleService {
|
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
static editVehicle({vehicleId, ...payload}: EditVehicleParams): Promise<APIResponse<string>> {
|
|
17
|
+
return request({
|
|
18
|
+
url: `${API_BASE_URL}/vehicle/${vehicleId}`,
|
|
19
|
+
method: APIMethod.PATCH,
|
|
20
|
+
body: JSON.stringify(payload)
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type EditVehicleParams = {
|
|
2
|
+
/** Identifiant unique du véhicule */
|
|
3
|
+
vehicleId: string;
|
|
4
|
+
|
|
5
|
+
/** Nombre de km au compteur */
|
|
6
|
+
currentMileage: number;
|
|
7
|
+
/** Nombre de km annuel moyen */
|
|
8
|
+
averageMileagePerYear: number;
|
|
9
|
+
|
|
10
|
+
/** Identification du pneu (XXX XX RXX XXX) */
|
|
11
|
+
tireWidth: string;
|
|
12
|
+
tireHeight: string;
|
|
13
|
+
tireDiameter: string;
|
|
14
|
+
tireSpeedIndex: string;
|
|
15
|
+
|
|
16
|
+
}
|