@kiminix/tp-client 1.1.0 → 1.2.0

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.
@@ -1,7 +1,12 @@
1
- import { TimelineDirection } from "../enum";
1
+ import { ReservationStatus } from "../enum";
2
+ import { GetTransitionsRequest } from "../reservations/types/admin/get-available-transitions";
3
+ import { GetByIdRequest } from "./types/admin/get-id";
4
+ import { GetPageRequest } from "./types/admin/get-page";
5
+ import { PatchStatusRequest } from "./types/admin/patch-status";
2
6
  import { Reservation } from "./types/shared";
3
- import { GetByIdRequest } from "./types/get-id";
4
7
  export declare class ReservationsAdminAPIs {
5
- static getPage(token: string | undefined | null, page: number, size: number, direction: TimelineDirection): Promise<Reservation[]>;
6
- static getReservation({ token, id }: GetByIdRequest): Promise<Reservation>;
8
+ static getPage({ token, page, size, direction }: GetPageRequest): Promise<Reservation[]>;
9
+ static getById({ token, id }: GetByIdRequest): Promise<Reservation>;
10
+ static getAvailableTransitions({ token, reservationId }: GetTransitionsRequest): Promise<ReservationStatus[]>;
11
+ static patchStatus({ token, id, status }: PatchStatusRequest): Promise<any>;
7
12
  }
@@ -39,12 +39,11 @@ import { base } from "../constants";
39
39
  var ReservationsAdminAPIs = /** @class */ (function () {
40
40
  function ReservationsAdminAPIs() {
41
41
  }
42
- ReservationsAdminAPIs.getPage = function (token, page, size, direction) {
43
- if (page === void 0) { page = 1; }
44
- if (size === void 0) { size = 10; }
42
+ ReservationsAdminAPIs.getPage = function (_a) {
43
+ var token = _a.token, _b = _a.page, page = _b === void 0 ? 1 : _b, _c = _a.size, size = _c === void 0 ? 10 : _c, direction = _a.direction;
45
44
  return __awaiter(this, void 0, void 0, function () {
46
- return __generator(this, function (_a) {
47
- switch (_a.label) {
45
+ return __generator(this, function (_d) {
46
+ switch (_d.label) {
48
47
  case 0:
49
48
  if (!token) return [3 /*break*/, 2];
50
49
  return [4 /*yield*/, axios.get(base + "/business/reservations?page=".concat(page, "&size=").concat(size, "&direction=").concat(direction), {
@@ -57,13 +56,13 @@ var ReservationsAdminAPIs = /** @class */ (function () {
57
56
  // handle error
58
57
  throw new Error('internal_error', error);
59
58
  })];
60
- case 1: return [2 /*return*/, _a.sent()];
59
+ case 1: return [2 /*return*/, _d.sent()];
61
60
  case 2: throw Error('unauthorized');
62
61
  }
63
62
  });
64
63
  });
65
64
  };
66
- ReservationsAdminAPIs.getReservation = function (_a) {
65
+ ReservationsAdminAPIs.getById = function (_a) {
67
66
  var token = _a.token, id = _a.id;
68
67
  return __awaiter(this, void 0, void 0, function () {
69
68
  return __generator(this, function (_b) {
@@ -90,6 +89,57 @@ var ReservationsAdminAPIs = /** @class */ (function () {
90
89
  });
91
90
  });
92
91
  };
92
+ ReservationsAdminAPIs.getAvailableTransitions = function (_a) {
93
+ var token = _a.token, reservationId = _a.reservationId;
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ return __generator(this, function (_b) {
96
+ switch (_b.label) {
97
+ case 0:
98
+ if (!token) return [3 /*break*/, 2];
99
+ return [4 /*yield*/, axios.get(base + "/business/reservations/".concat(reservationId, "/available-status"), {
100
+ headers: {
101
+ 'Authorization': "".concat(token)
102
+ }
103
+ })
104
+ .then(function (response) { return response.data; })
105
+ .catch(function (error) {
106
+ // handle error
107
+ throw new Error('internal_error', error);
108
+ })];
109
+ case 1: return [2 /*return*/, _b.sent()];
110
+ case 2: throw new Error("unauthorized");
111
+ }
112
+ });
113
+ });
114
+ };
115
+ ReservationsAdminAPIs.patchStatus = function (_a) {
116
+ var token = _a.token, id = _a.id, status = _a.status;
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ return __generator(this, function (_b) {
119
+ switch (_b.label) {
120
+ case 0: return [4 /*yield*/, axios.patch(base + "/business/reservations/".concat(id, "/").concat(status), {}, {
121
+ headers: {
122
+ 'Authorization': "".concat(token)
123
+ }
124
+ })
125
+ .then(function (response) { return response.data; })
126
+ .catch(function (error) {
127
+ // handle error
128
+ if (error.response.status == 404)
129
+ throw new Error("booking_not_found");
130
+ else if (error.response.status == 400) {
131
+ // unauthorized_action
132
+ var response = error.response.data;
133
+ throw new Error(response.code);
134
+ }
135
+ else
136
+ throw new Error('internal_error');
137
+ })];
138
+ case 1: return [2 /*return*/, _b.sent()];
139
+ }
140
+ });
141
+ });
142
+ };
93
143
  return ReservationsAdminAPIs;
94
144
  }());
95
145
  export { ReservationsAdminAPIs };
@@ -0,0 +1,4 @@
1
+ export interface GetTransitionsRequest {
2
+ token?: string;
3
+ reservationId: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ export interface GetByIdRequest {
2
+ token?: string;
3
+ id: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { TimelineDirection } from "../../../enum";
2
+ export interface GetPageRequest {
3
+ token?: string;
4
+ page: number;
5
+ size: number;
6
+ direction: TimelineDirection;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ReservationStatus } from "../../../enum";
2
+ export interface PatchStatusRequest {
3
+ token?: string;
4
+ id: string;
5
+ status: ReservationStatus;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
1
  export declare function getTruncatedTimestamp(): number;
2
2
  export declare function dateToString(date: string | Date, options: Intl.DateTimeFormatOptions): string;
3
+ export declare function toStringDefault(date: string, options: Intl.DateTimeFormatOptions): string;
3
4
  export declare function isBetween(date: Date, start: Date, end: Date): boolean;
4
5
  export declare function isDayAfter(date: Date, dateToCompare: Date, include?: Boolean): boolean;
5
6
  export declare function isDayBefore(date: Date, dateToCompare: Date, include?: Boolean): boolean;
@@ -22,6 +22,9 @@ export function dateToString(date, options) {
22
22
  return date.toLocaleDateString("fr-FR", options);
23
23
  }
24
24
  }
25
+ export function toStringDefault(date, options) {
26
+ return parseISO(date).toLocaleDateString("fr-FR", options);
27
+ }
25
28
  export function isBetween(date, start, end) {
26
29
  return (isSameDay(date, start) || isSameDay(date, end) || (isAfter(date, start) && isBefore(date, end)));
27
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiminix/tp-client",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [