@kiminix/tp-client 1.29.0 → 1.31.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/README CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  ## local dev & test
10
10
  - run `npm build`
11
- - then in the project you want to use this package run `npm i /Users/kamoun/workspace/tayara.promo/webapps/tp-client`
11
+ - then in the project you want to use this package run
12
+ `npm i /Users/kamoun/workspace/tayara.promo/webapps/tp-client`
12
13
 
13
14
 
@@ -1,4 +1,12 @@
1
1
  import { PresetMenu } from "./types/preset-menu";
2
+ import { LocalDate } from "../../types";
3
+ import { SpecialDiscount } from "./types/special-discounts";
2
4
  export declare class PresetMenusAPIs {
3
5
  static getByBusiness(businessId: string): Promise<PresetMenu[]>;
6
+ static getSpecialDiscounts(props: {
7
+ token?: string;
8
+ businessId: string;
9
+ code: string;
10
+ date: LocalDate;
11
+ }): Promise<SpecialDiscount[]>;
4
12
  }
@@ -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 { RequestUtils } from "../../utils/request-utils";
39
40
  // preset-menus module public APIs
40
41
  var PresetMenusAPIs = /** @class */ (function () {
41
42
  function PresetMenusAPIs() {
@@ -43,16 +44,36 @@ var PresetMenusAPIs = /** @class */ (function () {
43
44
  PresetMenusAPIs.getByBusiness = function (businessId) {
44
45
  return __awaiter(this, void 0, void 0, function () {
45
46
  return __generator(this, function (_a) {
46
- switch (_a.label) {
47
- case 0: return [4 /*yield*/, axios.get(base + "/preset-menus/user?business=".concat(businessId))
47
+ return [2 /*return*/, RequestUtils.send(function () {
48
+ return axios.get(base + "/preset-menus/user?business=".concat(businessId))
48
49
  .then(function (response) {
49
50
  return response.data;
51
+ });
52
+ })];
53
+ });
54
+ });
55
+ };
56
+ PresetMenusAPIs.getSpecialDiscounts = function (props) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ return __generator(this, function (_a) {
59
+ return [2 /*return*/, RequestUtils.send(function () {
60
+ var queryParams = [
61
+ "business=".concat(props.businessId),
62
+ "code=".concat(props.code),
63
+ "date=".concat(props.date)
64
+ ]
65
+ .filter(function (value) { return value; })
66
+ .join("&");
67
+ return axios.get(base + "/preset-menus/user/special-discounts?".concat(queryParams), {
68
+ headers: {
69
+ 'Authorization': "".concat(props.token)
70
+ }
50
71
  })
51
- .catch(function (error) {
52
- throw new Error('internal_error', error);
53
- })];
54
- case 1: return [2 /*return*/, _a.sent()];
55
- }
72
+ .then(function (response) {
73
+ var result = response.data;
74
+ return result;
75
+ });
76
+ })];
56
77
  });
57
78
  });
58
79
  };
@@ -0,0 +1,12 @@
1
+ import { Price } from "./types";
2
+ export interface Discount {
3
+ price: Price;
4
+ minBookingTotal?: number;
5
+ }
6
+ export interface SpecialDiscount {
7
+ menuId: string;
8
+ title: string;
9
+ price: Price;
10
+ minBookingTotal?: number;
11
+ discount: Discount;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@ import { CashbackStatus, Level, ReservationDealKind } from "../../enum";
2
2
  export interface Discount {
3
3
  type: ReservationDealKind.Discount;
4
4
  value: number;
5
+ specialCode: string | undefined;
5
6
  }
6
7
  export interface CashbackEarn {
7
8
  type: ReservationDealKind.CashbackEarn;
@@ -8,11 +8,12 @@ export interface BusinessOfReservation {
8
8
  address: string;
9
9
  }
10
10
  export interface User {
11
- id?: string;
12
- firstname?: string;
13
- lastname?: string;
14
- phone?: string;
15
- verifiedPhone?: boolean;
11
+ id: string | undefined;
12
+ firstname: string | undefined;
13
+ lastname: string | undefined;
14
+ phone: string | undefined;
15
+ email: string | undefined;
16
+ verifiedPhone: boolean;
16
17
  }
17
18
  export interface GuestDetails {
18
19
  number: number;
@@ -25,6 +25,7 @@ export declare class ReservationsUserAPIs {
25
25
  date: Date;
26
26
  time: Date;
27
27
  deal: ReservationDealKind | undefined;
28
+ specialCode?: string;
28
29
  commands: {
29
30
  menuId: string;
30
31
  adult: number;
@@ -37,6 +38,7 @@ export declare class ReservationsUserAPIs {
37
38
  date: Date;
38
39
  time: Date;
39
40
  deal: ReservationDealKind | undefined;
41
+ specialCode?: string;
40
42
  commands: {
41
43
  menuId: string;
42
44
  adult: number;
@@ -193,6 +193,7 @@ var ReservationsUserAPIs = /** @class */ (function () {
193
193
  businessId: props.businessId,
194
194
  datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
195
195
  deal: props.deal,
196
+ specialCode: props.specialCode,
196
197
  commands: props.commands
197
198
  }, {
198
199
  headers: {
@@ -235,6 +236,7 @@ var ReservationsUserAPIs = /** @class */ (function () {
235
236
  businessId: props.businessId,
236
237
  datetime: format(datetime, "yyyy-MM-dd'T'HH:mm"),
237
238
  deal: props.deal,
239
+ specialCode: props.specialCode,
238
240
  commands: props.commands
239
241
  }, {
240
242
  headers: {
@@ -52,14 +52,15 @@ var RequestUtils = /** @class */ (function () {
52
52
  axiosError = error_1;
53
53
  // The request was made and the server responded with a status code that falls out of the range of 2xx
54
54
  if (axiosError && axiosError.response) {
55
- switch (axiosError.response.status) {
56
- case 401:
57
- throw new Error("unauthorized");
58
- case 400:
59
- response = error_1.response.data;
60
- throw new ErrorWithMetadata(response.code, response.metadata);
61
- default:
62
- throw new Error('internal_error');
55
+ if (axiosError.response.status === 401) {
56
+ throw new Error("unauthorized");
57
+ }
58
+ else if (axiosError.response.status === 404 || axiosError.response.status === 400) {
59
+ response = axiosError.response.data;
60
+ throw new ErrorWithMetadata(response.code, response.metadata);
61
+ }
62
+ else {
63
+ throw new Error('internal_error');
63
64
  }
64
65
  }
65
66
  // The request was made but no response was received
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiminix/tp-client",
3
- "version": "1.29.0",
3
+ "version": "1.31.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [