@kiminix/tp-client 1.18.0 → 1.20.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.
- package/dist/enum.d.ts +2 -1
- package/dist/enum.js +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/menus/preset/apis.js +1 -1
- package/dist/menus/preset/types/available-menu.d.ts +12 -0
- package/dist/menus/preset/types/available-menu.js +1 -0
- package/dist/menus/preset/types/preset-menu.d.ts +1 -4
- package/dist/menus/preset/types/types.d.ts +4 -0
- package/dist/menus/preset/types/types.js +1 -0
- package/dist/menus/preset/user-apis.d.ts +16 -0
- package/dist/menus/preset/user-apis.js +81 -0
- package/dist/reservations/admin-apis.d.ts +6 -4
- package/dist/reservations/admin-apis.js +11 -11
- package/dist/reservations/types/types.d.ts +27 -0
- package/dist/reservations/types/types.js +2 -0
- package/dist/reservations/types/user/reservation-preview.d.ts +17 -0
- package/dist/reservations/types/user/reservation-preview.js +1 -0
- package/dist/reservations/types/user/reserve-response.d.ts +3 -0
- package/dist/reservations/types/user/reserve-response.js +1 -0
- package/dist/reservations/types.d.ts +27 -0
- package/dist/reservations/types.js +2 -0
- package/dist/reservations/user/types.d.ts +31 -0
- package/dist/reservations/user/types.js +2 -0
- package/dist/reservations/user/user-apis.d.ts +32 -0
- package/dist/reservations/user/user-apis.js +205 -0
- package/dist/reservations/user-apis.d.ts +23 -3
- package/dist/reservations/user-apis.js +51 -13
- package/dist/types.d.ts +5 -0
- package/dist/types.js +25 -1
- package/dist/utils/menu-utils.js +2 -3
- package/package.json +1 -1
package/dist/enum.d.ts
CHANGED
package/dist/enum.js
CHANGED
|
@@ -9,7 +9,8 @@ export var ReservationStatus;
|
|
|
9
9
|
export var DealKind;
|
|
10
10
|
(function (DealKind) {
|
|
11
11
|
DealKind["Discount"] = "discount";
|
|
12
|
-
DealKind["
|
|
12
|
+
DealKind["CashbackUse"] = "cashback_use";
|
|
13
|
+
DealKind["CashBackSave"] = "cashback_save";
|
|
13
14
|
})(DealKind || (DealKind = {}));
|
|
14
15
|
export var TimelineDirection;
|
|
15
16
|
(function (TimelineDirection) {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ export { IamUserAPIs } from './iam/user-apis';
|
|
|
6
6
|
export { PresetMenusAPIs } from './menus/preset/apis';
|
|
7
7
|
export { PresetMenusAdminAPIs } from './menus/preset/admin-apis';
|
|
8
8
|
export { NotifyAPIs } from './notify/apis';
|
|
9
|
-
export { ReservationsUserAPIs } from './reservations/user-apis';
|
|
9
|
+
export { ReservationsUserAPIs } from './reservations/user/user-apis';
|
|
10
|
+
export * from './reservations/user/types';
|
|
10
11
|
export { ReservationsAdminAPIs } from './reservations/admin-apis';
|
|
11
12
|
export { SitemapAPIs } from './sitemap/apis';
|
|
12
13
|
export { StatisticsAdminAPIs } from './statistics/admin-apis';
|
|
14
|
+
export { PresetMenusUserAPIs } from './menus/preset/user-apis';
|
|
13
15
|
export { MenuUtils } from './utils/menu-utils';
|
|
14
16
|
export { BusinessUtils } from './utils/business-utils';
|
|
15
17
|
export * from './utils/date-utils';
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,12 @@ export { IamUserAPIs } from './iam/user-apis';
|
|
|
6
6
|
export { PresetMenusAPIs } from './menus/preset/apis';
|
|
7
7
|
export { PresetMenusAdminAPIs } from './menus/preset/admin-apis';
|
|
8
8
|
export { NotifyAPIs } from './notify/apis';
|
|
9
|
-
export { ReservationsUserAPIs } from './reservations/user-apis';
|
|
9
|
+
export { ReservationsUserAPIs } from './reservations/user/user-apis';
|
|
10
|
+
export * from './reservations/user/types';
|
|
10
11
|
export { ReservationsAdminAPIs } from './reservations/admin-apis';
|
|
11
12
|
export { SitemapAPIs } from './sitemap/apis';
|
|
12
13
|
export { StatisticsAdminAPIs } from './statistics/admin-apis';
|
|
14
|
+
export { PresetMenusUserAPIs } from './menus/preset/user-apis';
|
|
13
15
|
//
|
|
14
16
|
export { MenuUtils } from './utils/menu-utils';
|
|
15
17
|
export { BusinessUtils } from './utils/business-utils';
|
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import axios from "axios";
|
|
38
38
|
import { base } from "../../constants";
|
|
39
|
-
// preset-menus module APIs
|
|
39
|
+
// preset-menus module public APIs
|
|
40
40
|
var PresetMenusAPIs = /** @class */ (function () {
|
|
41
41
|
function PresetMenusAPIs() {
|
|
42
42
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Price } from "./types";
|
|
2
|
+
export interface Discount {
|
|
3
|
+
price: Price;
|
|
4
|
+
minBookingTotal: number | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface AvailablePresetMenu {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
price: Price;
|
|
10
|
+
minBookingTotal: number | undefined;
|
|
11
|
+
discount: Discount | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LocalDate } from "../../types";
|
|
2
|
+
import { AvailablePresetMenu } from "./types/available-menu";
|
|
3
|
+
import { Either } from "purify-ts";
|
|
4
|
+
export declare class PresetMenusUserAPIs {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param businessId
|
|
8
|
+
* @param date
|
|
9
|
+
* @returns available preset menus for the given business and date. can fail with bellow errors code: unauthenticated, past_day, expired_licence, internal_error
|
|
10
|
+
*/
|
|
11
|
+
static getAvailableMenus(props: {
|
|
12
|
+
token?: string;
|
|
13
|
+
businessId: string;
|
|
14
|
+
date: LocalDate;
|
|
15
|
+
}): Promise<Either<Error, AvailablePresetMenu[]>>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import axios from "axios";
|
|
38
|
+
import { base } from "../../constants";
|
|
39
|
+
import { Left, Right } from "purify-ts";
|
|
40
|
+
// preset-menus module public APIs
|
|
41
|
+
var PresetMenusUserAPIs = /** @class */ (function () {
|
|
42
|
+
function PresetMenusUserAPIs() {
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param businessId
|
|
47
|
+
* @param date
|
|
48
|
+
* @returns available preset menus for the given business and date. can fail with bellow errors code: unauthenticated, past_day, expired_licence, internal_error
|
|
49
|
+
*/
|
|
50
|
+
PresetMenusUserAPIs.getAvailableMenus = function (props) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, axios.get(base + "/preset-menus/user/available?business=".concat(props.businessId, "&date=").concat(props.date), {
|
|
55
|
+
headers: {
|
|
56
|
+
'Authorization': "".concat(props.token)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.then(function (response) {
|
|
60
|
+
return Right(response.data);
|
|
61
|
+
})
|
|
62
|
+
// handled error
|
|
63
|
+
.catch(function (error) {
|
|
64
|
+
var _a, _b, _c, _d, _e, _f;
|
|
65
|
+
// unauthenticated
|
|
66
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) == 401)
|
|
67
|
+
return (Left(new Error((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.code)));
|
|
68
|
+
//past_day
|
|
69
|
+
else if (((_d = error.response) === null || _d === void 0 ? void 0 : _d.status) == 400)
|
|
70
|
+
return (Left(new Error((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.code)));
|
|
71
|
+
else
|
|
72
|
+
throw new Error('internal_error', error);
|
|
73
|
+
})];
|
|
74
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
return PresetMenusUserAPIs;
|
|
80
|
+
}());
|
|
81
|
+
export { PresetMenusUserAPIs };
|
|
@@ -22,17 +22,19 @@ export declare class ReservationsAdminAPIs {
|
|
|
22
22
|
notes?: string;
|
|
23
23
|
};
|
|
24
24
|
}): Promise<Either<Error, any>>;
|
|
25
|
-
static
|
|
25
|
+
static reserve(props: {
|
|
26
26
|
token?: string;
|
|
27
|
-
id: string;
|
|
28
27
|
user: {
|
|
29
28
|
firstName: string;
|
|
30
29
|
lastName: string;
|
|
31
30
|
phone?: string;
|
|
32
31
|
};
|
|
33
32
|
datetime: Date;
|
|
34
|
-
children: number;
|
|
35
|
-
adults: number;
|
|
36
33
|
notes?: string;
|
|
34
|
+
commands: {
|
|
35
|
+
menuId: string;
|
|
36
|
+
adult: number;
|
|
37
|
+
child?: number;
|
|
38
|
+
}[];
|
|
37
39
|
}): Promise<Either<Error, void>>;
|
|
38
40
|
}
|
|
@@ -36,6 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import axios from "axios";
|
|
38
38
|
import { base } from "../constants";
|
|
39
|
+
import { ErrorWithMetadata } from "../types";
|
|
39
40
|
import { format } from "date-fns";
|
|
40
41
|
import { Left, Right } from "purify-ts";
|
|
41
42
|
var ReservationsAdminAPIs = /** @class */ (function () {
|
|
@@ -154,17 +155,15 @@ var ReservationsAdminAPIs = /** @class */ (function () {
|
|
|
154
155
|
});
|
|
155
156
|
});
|
|
156
157
|
};
|
|
157
|
-
ReservationsAdminAPIs.
|
|
158
|
+
ReservationsAdminAPIs.reserve = function (props) {
|
|
158
159
|
return __awaiter(this, void 0, void 0, function () {
|
|
159
160
|
return __generator(this, function (_a) {
|
|
160
161
|
switch (_a.label) {
|
|
161
|
-
case 0: return [4 /*yield*/, axios.post(base + "/reservations/admin
|
|
162
|
-
id: props.id,
|
|
162
|
+
case 0: return [4 /*yield*/, axios.post(base + "/reservations/admin", {
|
|
163
163
|
user: props.user,
|
|
164
164
|
datetime: format(props.datetime, "yyyy-MM-dd'T'HH:mm"),
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
notes: props.notes
|
|
165
|
+
notes: props.notes,
|
|
166
|
+
commands: props.commands
|
|
168
167
|
}, {
|
|
169
168
|
headers: {
|
|
170
169
|
'Authorization': "".concat(props.token),
|
|
@@ -176,13 +175,14 @@ var ReservationsAdminAPIs = /** @class */ (function () {
|
|
|
176
175
|
// handle error
|
|
177
176
|
if (error.response.status == 401)
|
|
178
177
|
return Left(Error("unauthorized"));
|
|
179
|
-
else if (error.response.status == 404)
|
|
180
|
-
return Left(Error("not_found"));
|
|
181
178
|
else if (error.response.status == 400) {
|
|
182
|
-
//unavailable_day
|
|
183
|
-
//inactive_manual_booking
|
|
179
|
+
// unavailable_day
|
|
180
|
+
// inactive_manual_booking
|
|
181
|
+
// expired_preview
|
|
182
|
+
// invalid_guest_number
|
|
183
|
+
// min_booking_amount
|
|
184
184
|
var response = error.response.data;
|
|
185
|
-
return Left(
|
|
185
|
+
return Left(new ErrorWithMetadata(response.code, response.metadata));
|
|
186
186
|
}
|
|
187
187
|
else
|
|
188
188
|
return Left(Error('internal_error'));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TimelineDirection } from "../../enum";
|
|
2
|
+
export interface ReservationPreviewResponse {
|
|
3
|
+
datetime: Date;
|
|
4
|
+
total: number;
|
|
5
|
+
totalBeforeDeal: number | undefined;
|
|
6
|
+
commands: CommandPreview[];
|
|
7
|
+
}
|
|
8
|
+
export interface CommandPreview {
|
|
9
|
+
menuId: string;
|
|
10
|
+
title: string;
|
|
11
|
+
adult: CommandEntryPreview;
|
|
12
|
+
child: CommandEntryPreview | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface CommandEntryPreview {
|
|
15
|
+
number: number;
|
|
16
|
+
price: number;
|
|
17
|
+
priceBeforeDeal: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface ReservationResponse {
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GetPageRequest {
|
|
23
|
+
token?: string;
|
|
24
|
+
page: number;
|
|
25
|
+
size: number;
|
|
26
|
+
direction: TimelineDirection;
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ReservationPreviewResponse {
|
|
2
|
+
datetime: Date;
|
|
3
|
+
total: number;
|
|
4
|
+
totalBeforeDeal: number | undefined;
|
|
5
|
+
commands: CommandPreview[];
|
|
6
|
+
}
|
|
7
|
+
export interface CommandPreview {
|
|
8
|
+
menuId: string;
|
|
9
|
+
title: string;
|
|
10
|
+
adult: CommandEntryPreview;
|
|
11
|
+
child: CommandEntryPreview | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface CommandEntryPreview {
|
|
14
|
+
number: number;
|
|
15
|
+
price: number;
|
|
16
|
+
priceBeforeDeal: number | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TimelineDirection } from "../enum";
|
|
2
|
+
export interface ReservationPreviewResponse {
|
|
3
|
+
datetime: Date;
|
|
4
|
+
total: number;
|
|
5
|
+
totalBeforeDeal: number | undefined;
|
|
6
|
+
commands: CommandPreview[];
|
|
7
|
+
}
|
|
8
|
+
export interface CommandPreview {
|
|
9
|
+
menuId: string;
|
|
10
|
+
title: string;
|
|
11
|
+
adult: CommandEntryPreview;
|
|
12
|
+
child: CommandEntryPreview | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface CommandEntryPreview {
|
|
15
|
+
number: number;
|
|
16
|
+
price: number;
|
|
17
|
+
priceBeforeDeal: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface ReservationResponse {
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GetPageRequest {
|
|
23
|
+
token?: string;
|
|
24
|
+
page: number;
|
|
25
|
+
size: number;
|
|
26
|
+
direction: TimelineDirection;
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TimelineDirection } from "../../enum";
|
|
2
|
+
export interface ReservationPreviewResponse {
|
|
3
|
+
datetime: Date;
|
|
4
|
+
total: number;
|
|
5
|
+
totalBeforeDeal: number;
|
|
6
|
+
commands: CommandPreview[];
|
|
7
|
+
}
|
|
8
|
+
export interface CommandPreview {
|
|
9
|
+
menuId: string;
|
|
10
|
+
title: string;
|
|
11
|
+
adult: CommandEntryPreview;
|
|
12
|
+
child: CommandEntryPreview | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface CommandEntryPreview {
|
|
15
|
+
number: number;
|
|
16
|
+
price: number;
|
|
17
|
+
priceBeforeDeal: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ReservationResponse {
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GetPageRequest {
|
|
23
|
+
token?: string;
|
|
24
|
+
page: number;
|
|
25
|
+
size: number;
|
|
26
|
+
direction: TimelineDirection;
|
|
27
|
+
}
|
|
28
|
+
export interface GetByIdRequest {
|
|
29
|
+
token?: string;
|
|
30
|
+
id: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Reservation } from "../types/shared";
|
|
2
|
+
import { DealKind } from "../../enum";
|
|
3
|
+
import { GetByIdRequest, GetPageRequest, ReservationPreviewResponse, ReservationResponse } from "./types";
|
|
4
|
+
export declare class ReservationsUserAPIs {
|
|
5
|
+
static getPage({ token, page, size, direction }: GetPageRequest): Promise<Reservation[]>;
|
|
6
|
+
static get({ id, token }: GetByIdRequest): Promise<Reservation>;
|
|
7
|
+
static cancel(id: string, token?: string): Promise<any>;
|
|
8
|
+
static reserve(props: {
|
|
9
|
+
token?: string;
|
|
10
|
+
businessId: string;
|
|
11
|
+
date: Date;
|
|
12
|
+
time: Date;
|
|
13
|
+
dealKind?: DealKind;
|
|
14
|
+
commands: {
|
|
15
|
+
menuId: string;
|
|
16
|
+
adult: number;
|
|
17
|
+
child?: number;
|
|
18
|
+
}[];
|
|
19
|
+
}): Promise<ReservationResponse>;
|
|
20
|
+
static preview(props: {
|
|
21
|
+
token?: string;
|
|
22
|
+
businessId: string;
|
|
23
|
+
date: Date;
|
|
24
|
+
time: Date;
|
|
25
|
+
dealKind?: DealKind;
|
|
26
|
+
commands: {
|
|
27
|
+
menuId: string;
|
|
28
|
+
adult: number;
|
|
29
|
+
child?: number;
|
|
30
|
+
}[];
|
|
31
|
+
}): Promise<ReservationPreviewResponse>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import axios from "axios";
|
|
38
|
+
import { format } from "date-fns";
|
|
39
|
+
import { base } from "../../constants";
|
|
40
|
+
import { ErrorWithMetadata } from "../../types";
|
|
41
|
+
var ReservationsUserAPIs = /** @class */ (function () {
|
|
42
|
+
function ReservationsUserAPIs() {
|
|
43
|
+
}
|
|
44
|
+
ReservationsUserAPIs.getPage = function (_a) {
|
|
45
|
+
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;
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
return __generator(this, function (_d) {
|
|
48
|
+
switch (_d.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, axios.get(base + "/reservations/user?page=".concat(page, "&size=").concat(size, "&direction=").concat(direction), {
|
|
50
|
+
headers: {
|
|
51
|
+
'Authorization': "".concat(token)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
.then(function (response) { return response.data; })
|
|
55
|
+
.catch(function (error) {
|
|
56
|
+
// handle error
|
|
57
|
+
if (error.response.status == 401)
|
|
58
|
+
throw new Error("unauthorized");
|
|
59
|
+
else
|
|
60
|
+
throw new Error('internal_error', error);
|
|
61
|
+
})];
|
|
62
|
+
case 1: return [2 /*return*/, _d.sent()];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
ReservationsUserAPIs.get = function (_a) {
|
|
68
|
+
var id = _a.id, token = _a.token;
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
return __generator(this, function (_b) {
|
|
71
|
+
switch (_b.label) {
|
|
72
|
+
case 0: return [4 /*yield*/, axios.get(base + "/reservations/user/".concat(id), {
|
|
73
|
+
headers: {
|
|
74
|
+
'Authorization': "".concat(token),
|
|
75
|
+
'Content-Type': 'application/json'
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
.then(function (response) { return response.data; })
|
|
79
|
+
.catch(function (error) {
|
|
80
|
+
// handle error
|
|
81
|
+
if (error.response.status == 401)
|
|
82
|
+
throw new Error("unauthorized");
|
|
83
|
+
else if (error.response.status == 404)
|
|
84
|
+
throw new Error("not_found");
|
|
85
|
+
else
|
|
86
|
+
throw new Error('internal_error', error);
|
|
87
|
+
})];
|
|
88
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
ReservationsUserAPIs.cancel = function (id, token) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, axios.patch(base + "/reservations/user/".concat(id, "/cancel"), {}, {
|
|
98
|
+
headers: {
|
|
99
|
+
'Authorization': "".concat(token)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
.then(function (response) { return response.data; })
|
|
103
|
+
.catch(function (error) {
|
|
104
|
+
// handle error
|
|
105
|
+
if (error.response.status == 401)
|
|
106
|
+
throw new Error("unauthorized");
|
|
107
|
+
else if (error.response.status == 404)
|
|
108
|
+
throw new Error("not_found");
|
|
109
|
+
else if (error.response.status == 400) {
|
|
110
|
+
//reservation_not_found
|
|
111
|
+
var response = error.response.data;
|
|
112
|
+
throw new Error(response.code);
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
throw new Error('internal_error', error);
|
|
116
|
+
})];
|
|
117
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
ReservationsUserAPIs.reserve = function (props) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var datetime;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
datetime = new Date(props.date);
|
|
129
|
+
datetime.setHours(props.time.getHours(), props.time.getMinutes());
|
|
130
|
+
return [4 /*yield*/, axios.post(base + "/reservations/user", {
|
|
131
|
+
businessId: props.businessId,
|
|
132
|
+
datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
|
|
133
|
+
dealKind: props.dealKind,
|
|
134
|
+
commands: props.commands
|
|
135
|
+
}, {
|
|
136
|
+
headers: {
|
|
137
|
+
'Authorization': "".concat(props.token),
|
|
138
|
+
'Content-Type': 'application/json'
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
.then(function (response) { return response.data; })
|
|
142
|
+
.catch(function (error) {
|
|
143
|
+
// handle error
|
|
144
|
+
if (error.response.status == 401)
|
|
145
|
+
throw new Error("unauthorized");
|
|
146
|
+
else if (error.response.status == 400) {
|
|
147
|
+
// banned_user
|
|
148
|
+
// already_booked
|
|
149
|
+
// unavailable_day
|
|
150
|
+
// expired_preview
|
|
151
|
+
// invalid_guest_number
|
|
152
|
+
// min_booking_amount
|
|
153
|
+
var response = error.response.data;
|
|
154
|
+
throw new ErrorWithMetadata(response.code, response.metadata);
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
throw new Error('internal_error', error);
|
|
158
|
+
})];
|
|
159
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
ReservationsUserAPIs.preview = function (props) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var datetime;
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
datetime = new Date(props.date);
|
|
171
|
+
datetime.setHours(props.time.getHours(), props.time.getMinutes());
|
|
172
|
+
return [4 /*yield*/, axios.post(base + "/reservations/user/preview", {
|
|
173
|
+
businessId: props.businessId,
|
|
174
|
+
datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
|
|
175
|
+
dealKind: props.dealKind,
|
|
176
|
+
commands: props.commands
|
|
177
|
+
}, {
|
|
178
|
+
headers: {
|
|
179
|
+
'Authorization': "".concat(props.token),
|
|
180
|
+
'Content-Type': 'application/json'
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
.then(function (response) { return response.data; })
|
|
184
|
+
.catch(function (error) {
|
|
185
|
+
// handle error
|
|
186
|
+
if (error.response.status == 401)
|
|
187
|
+
throw new Error("unauthorized");
|
|
188
|
+
else if (error.response.status == 400) {
|
|
189
|
+
//expired_preview
|
|
190
|
+
//min_booking_amount
|
|
191
|
+
//invalid_guest_number
|
|
192
|
+
var response = error.response.data;
|
|
193
|
+
throw new ErrorWithMetadata(response.code, response.metadata);
|
|
194
|
+
}
|
|
195
|
+
else
|
|
196
|
+
throw new Error('internal_error', error);
|
|
197
|
+
})];
|
|
198
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
return ReservationsUserAPIs;
|
|
204
|
+
}());
|
|
205
|
+
export { ReservationsUserAPIs };
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { Reservation } from "./types/shared";
|
|
2
2
|
import { GetByIdRequest } from "./types/user/get-id";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { DealKind } from "../enum";
|
|
4
|
+
import { GetPageRequest, ReservationPreviewResponse, ReservationResponse } from "./types";
|
|
5
5
|
export declare class ReservationsUserAPIs {
|
|
6
6
|
static getPage({ token, page, size, direction }: GetPageRequest): Promise<Reservation[]>;
|
|
7
7
|
static get({ id, token }: GetByIdRequest): Promise<Reservation>;
|
|
8
8
|
static cancel(id: string, token?: string): Promise<any>;
|
|
9
|
-
static
|
|
9
|
+
static reserve(props: {
|
|
10
|
+
token?: string;
|
|
11
|
+
id: string;
|
|
12
|
+
date: Date;
|
|
13
|
+
time: Date;
|
|
14
|
+
children: number;
|
|
15
|
+
adults: number;
|
|
16
|
+
dealKind?: DealKind;
|
|
17
|
+
}): Promise<ReservationResponse>;
|
|
18
|
+
static preview(props: {
|
|
19
|
+
token?: string;
|
|
20
|
+
businessId: string;
|
|
21
|
+
date: Date;
|
|
22
|
+
time: Date;
|
|
23
|
+
dealKind?: DealKind;
|
|
24
|
+
commands: {
|
|
25
|
+
menuId: string;
|
|
26
|
+
adult: number;
|
|
27
|
+
child?: number;
|
|
28
|
+
}[];
|
|
29
|
+
}): Promise<ReservationPreviewResponse>;
|
|
10
30
|
}
|
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
import axios from "axios";
|
|
38
38
|
import { format } from "date-fns";
|
|
39
39
|
import { base } from "../constants";
|
|
40
|
+
import { ErrorWithMetadata } from "../types";
|
|
40
41
|
var ReservationsUserAPIs = /** @class */ (function () {
|
|
41
42
|
function ReservationsUserAPIs() {
|
|
42
43
|
}
|
|
@@ -118,24 +119,23 @@ var ReservationsUserAPIs = /** @class */ (function () {
|
|
|
118
119
|
});
|
|
119
120
|
});
|
|
120
121
|
};
|
|
121
|
-
ReservationsUserAPIs.
|
|
122
|
-
var token = _a.token, id = _a.id, date = _a.date, time = _a.time, children = _a.children, adults = _a.adults, dealKind = _a.dealKind;
|
|
122
|
+
ReservationsUserAPIs.reserve = function (props) {
|
|
123
123
|
return __awaiter(this, void 0, void 0, function () {
|
|
124
124
|
var datetime;
|
|
125
|
-
return __generator(this, function (
|
|
126
|
-
switch (
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
127
|
case 0:
|
|
128
|
-
datetime = new Date(date);
|
|
129
|
-
datetime.setHours(time.getHours(), time.getMinutes());
|
|
130
|
-
return [4 /*yield*/, axios.post(base + "/reservations/user
|
|
131
|
-
id: id,
|
|
128
|
+
datetime = new Date(props.date);
|
|
129
|
+
datetime.setHours(props.time.getHours(), props.time.getMinutes());
|
|
130
|
+
return [4 /*yield*/, axios.post(base + "/reservations/user", {
|
|
131
|
+
id: props.id,
|
|
132
132
|
datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
|
|
133
|
-
children: children,
|
|
134
|
-
adults: adults,
|
|
135
|
-
dealKind: dealKind
|
|
133
|
+
children: props.children,
|
|
134
|
+
adults: props.adults,
|
|
135
|
+
dealKind: props.dealKind
|
|
136
136
|
}, {
|
|
137
137
|
headers: {
|
|
138
|
-
'Authorization': "".concat(token),
|
|
138
|
+
'Authorization': "".concat(props.token),
|
|
139
139
|
'Content-Type': 'application/json'
|
|
140
140
|
}
|
|
141
141
|
})
|
|
@@ -158,7 +158,45 @@ var ReservationsUserAPIs = /** @class */ (function () {
|
|
|
158
158
|
else
|
|
159
159
|
throw new Error('internal_error', error);
|
|
160
160
|
})];
|
|
161
|
-
case 1: return [2 /*return*/,
|
|
161
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
ReservationsUserAPIs.preview = function (props) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
var datetime;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
datetime = new Date(props.date);
|
|
173
|
+
datetime.setHours(props.time.getHours(), props.time.getMinutes());
|
|
174
|
+
return [4 /*yield*/, axios.post(base + "/reservations/user/preview", {
|
|
175
|
+
businessId: props.businessId,
|
|
176
|
+
datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
|
|
177
|
+
dealKind: props.dealKind,
|
|
178
|
+
commands: props.commands
|
|
179
|
+
}, {
|
|
180
|
+
headers: {
|
|
181
|
+
'Authorization': "".concat(props.token),
|
|
182
|
+
'Content-Type': 'application/json'
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
.then(function (response) { return response.data; })
|
|
186
|
+
.catch(function (error) {
|
|
187
|
+
// handle error
|
|
188
|
+
if (error.response.status == 401)
|
|
189
|
+
throw new Error("unauthorized");
|
|
190
|
+
else if (error.response.status == 400) {
|
|
191
|
+
//expired_preview
|
|
192
|
+
//min_booking_amount
|
|
193
|
+
var response = error.response.data;
|
|
194
|
+
throw new ErrorWithMetadata(response.code, response.metadata);
|
|
195
|
+
}
|
|
196
|
+
else
|
|
197
|
+
throw new Error('internal_error', error);
|
|
198
|
+
})];
|
|
199
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
162
200
|
}
|
|
163
201
|
});
|
|
164
202
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -2,9 +2,14 @@ export type LocalDate = string;
|
|
|
2
2
|
export interface ApiError {
|
|
3
3
|
message: string;
|
|
4
4
|
code?: string;
|
|
5
|
+
metadata?: any;
|
|
5
6
|
}
|
|
6
7
|
export interface Licence {
|
|
7
8
|
from: LocalDate;
|
|
8
9
|
to: LocalDate;
|
|
9
10
|
isManualBookingActive: boolean;
|
|
10
11
|
}
|
|
12
|
+
export declare class ErrorWithMetadata extends Error {
|
|
13
|
+
metadata: any;
|
|
14
|
+
constructor(code: string, metadata?: any);
|
|
15
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var ErrorWithMetadata = /** @class */ (function (_super) {
|
|
17
|
+
__extends(ErrorWithMetadata, _super);
|
|
18
|
+
function ErrorWithMetadata(code, metadata) {
|
|
19
|
+
var _this = _super.call(this, code) || this; // Pass the message to the Error constructor
|
|
20
|
+
_this.metadata = metadata; // Set the metadata property
|
|
21
|
+
return _this;
|
|
22
|
+
}
|
|
23
|
+
return ErrorWithMetadata;
|
|
24
|
+
}(Error));
|
|
25
|
+
export { ErrorWithMetadata };
|
package/dist/utils/menu-utils.js
CHANGED
|
@@ -13,8 +13,7 @@ var MenuUtils = /** @class */ (function () {
|
|
|
13
13
|
var _a;
|
|
14
14
|
// correct way to get daily discounts Map instance
|
|
15
15
|
var discounts_ = (_a = menu.discount) !== null && _a !== void 0 ? _a : {};
|
|
16
|
-
|
|
17
|
-
return discounts;
|
|
16
|
+
return new Map(Object.entries(discounts_));
|
|
18
17
|
};
|
|
19
18
|
MenuUtils.getAvailableDiscounts = function (menu) {
|
|
20
19
|
var discounts = this.getDiscounts(menu);
|
|
@@ -38,7 +37,7 @@ var MenuUtils = /** @class */ (function () {
|
|
|
38
37
|
};
|
|
39
38
|
MenuUtils.getAvailableDiscountByDay = function (menu, date) {
|
|
40
39
|
var discount = this.getDiscountByDay(menu, date);
|
|
41
|
-
return discount.isAvailable ? discount : undefined;
|
|
40
|
+
return (discount === null || discount === void 0 ? void 0 : discount.isAvailable) ? discount : undefined;
|
|
42
41
|
};
|
|
43
42
|
MenuUtils.getDiscountByDay = function (menu, date) {
|
|
44
43
|
// correct way to get daily discount Map instance
|