@escapenavigator/utils 1.6.31 → 1.6.33

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.
@@ -0,0 +1,5 @@
1
+ export declare const getFullName: ({ id, name, surname }: {
2
+ id: number;
3
+ name: string;
4
+ surname: string;
5
+ }) => string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFullName = void 0;
4
+ const getFullName = ({ id, name, surname }) => {
5
+ if (name || surname)
6
+ return `${name || ''} ${surname || ''}`.trim();
7
+ return `Client №${id}`;
8
+ };
9
+ exports.getFullName = getFullName;
@@ -24,7 +24,6 @@ var FineDescriptions;
24
24
  const isCancelationAllowed = ({ date, minHoursForFreeCanceling = 0, }) => (0, differenceInHours_1.default)(new Date(date), new Date()) > minHoursForFreeCanceling;
25
25
  exports.isCancelationAllowed = isCancelationAllowed;
26
26
  function getOrderCancelationState({ cancelationReason, cancelationRule, transactions, date, returnCertificates, certificates, minHoursForFreeCanceling, total, payed, minimalPrice, }) {
27
- var _a;
28
27
  /**
29
28
  * В срок ли отменяется игра. Если в срок, то мы отменяем все промокоды и сертификаты, учитываем сумму возврата только с транзакций
30
29
  */
@@ -37,7 +36,7 @@ function getOrderCancelationState({ cancelationReason, cancelationRule, transact
37
36
  const receivedTransactions = getReceivedTransactions(transactions);
38
37
  const receivedTransactionsAmount = receivedTransactions.reduce((acc, tr) => acc + tr.amount, 0);
39
38
  const autoReturtAvailable = receivedTransactions.length === 1 &&
40
- ((_a = receivedTransactions[0]) === null || _a === void 0 ? void 0 : _a.type) !== transaction_type_enum_1.TransactionTypeEnum.INSIDE;
39
+ receivedTransactions[0]?.type !== transaction_type_enum_1.TransactionTypeEnum.INSIDE;
41
40
  const orderPayment = returnCertificates
42
41
  ? payed - certificates.reduce((acc, c) => acc + c.nominal, 0)
43
42
  : payed;
@@ -4,7 +4,6 @@ declare type Props = {
4
4
  slot: any;
5
5
  order?: OrderRO;
6
6
  };
7
- export declare const getClientName: (client: any) => any;
8
7
  export declare const serializeSlotOrderData: (order: Props['order']) => SlotRO['order'];
9
8
  export declare const serializeSlot: ({ slot, order }: Props) => SlotRO;
10
9
  export {};
@@ -1,39 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeSlot = exports.serializeSlotOrderData = exports.getClientName = void 0;
3
+ exports.serializeSlot = exports.serializeSlotOrderData = void 0;
4
4
  const defailt_rule_1 = require("@escapenavigator/types/dist/slot-rule/defailt-rule");
5
- const getClientName = (client) => {
6
- var _a;
7
- if (!client.name && client.surname)
8
- return client.surname;
9
- if (client.name && !client.surname)
10
- return client.name;
11
- if (client.name && client.surname)
12
- return `${(_a = client.name) === null || _a === void 0 ? void 0 : _a.charAt(0)}. ${client.surname}`;
13
- return client.email;
14
- };
15
- exports.getClientName = getClientName;
16
- const serializeSlotOrderData = (order) => {
17
- var _a, _b, _c, _d, _e;
18
- return order && {
19
- id: order.id,
20
- players: order.players,
21
- hasDiscounts: !!((_a = order.discounts) === null || _a === void 0 ? void 0 : _a.length),
22
- hasComments: !!((_b = order.messages) === null || _b === void 0 ? void 0 : _b.length) || !!order.comment,
23
- hasCertificateApplies: !!((_c = order.certificates) === null || _c === void 0 ? void 0 : _c.length),
24
- hasPenalties: !!((_d = order.penalties) === null || _d === void 0 ? void 0 : _d.length),
25
- hasUpsellings: !!((_e = order.upsellings) === null || _e === void 0 ? void 0 : _e.length),
26
- utcDate: order.utcDate,
27
- moderatorId: order.moderatorId,
28
- total: order.total,
29
- payed: order.payed,
30
- code: order.code,
31
- clientName: (0, exports.getClientName)(order.client),
32
- };
5
+ const get_full_name_1 = require("./get-full-name");
6
+ const serializeSlotOrderData = (order) => order && {
7
+ id: order.id,
8
+ players: order.players,
9
+ hasDiscounts: !!order.discounts?.length,
10
+ hasComments: !!order.messages?.length || !!order.comment,
11
+ hasCertificateApplies: !!order.certificates?.length,
12
+ hasPenalties: !!order.penalties?.length,
13
+ hasUpsellings: !!order.upsellings?.length,
14
+ utcDate: order.utcDate,
15
+ moderatorId: order.moderatorId,
16
+ total: order.total,
17
+ payed: order.payed,
18
+ code: order.code,
19
+ clientName: (0, get_full_name_1.getFullName)(order.client),
33
20
  };
34
21
  exports.serializeSlotOrderData = serializeSlotOrderData;
35
22
  const serializeSlot = ({ slot, order }) => {
36
- var _a;
37
23
  const { prepayment, prepaymentType, title, minHoursForBooking, minHoursForFreeCanceling, cancelationRule, } = slot.rule || defailt_rule_1.defaultRule;
38
24
  return {
39
25
  id: slot.id,
@@ -44,7 +30,7 @@ const serializeSlot = ({ slot, order }) => {
44
30
  status: slot.status,
45
31
  start: slot.start,
46
32
  end: slot.end,
47
- tariff: (_a = slot.tariff) === null || _a === void 0 ? void 0 : _a.price,
33
+ tariff: slot.tariff?.price,
48
34
  breakReason: slot.breakReason,
49
35
  rule: {
50
36
  prepayment,
@@ -0,0 +1 @@
1
+ export declare const transformText: (text: string, obj: Record<string, string>) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformText = void 0;
4
+ const transformText = (text, obj) => {
5
+ let res = text || '';
6
+ Object.entries(obj).forEach(([key, value]) => {
7
+ res = res.replace(new RegExp(`{${key}}`, 'g'), value);
8
+ });
9
+ return res;
10
+ };
11
+ exports.transformText = transformText;
@@ -7,7 +7,7 @@ function validateByDto(t) {
7
7
  const errors = (0, class_validator_1.validateSync)(typeof data === 'object' ? data : {});
8
8
  console.log({ formErrors: errors });
9
9
  return Object.fromEntries(errors.map(({ property, constraints }) => {
10
- const err = (constraints === null || constraints === void 0 ? void 0 : constraints.IsNotEmpty) || Object.values(constraints)[0];
10
+ const err = constraints?.IsNotEmpty || Object.values(constraints)[0];
11
11
  const errorText = err.substr(err.indexOf(' ') + 1);
12
12
  return [property, `${t(`validationErrors:${errorText}`)}`];
13
13
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "1.6.31",
3
+ "version": "1.6.33",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,7 @@
14
14
  "test": "jest"
15
15
  },
16
16
  "dependencies": {
17
- "@escapenavigator/types": "^1.6.31",
17
+ "@escapenavigator/types": "^1.6.33",
18
18
  "axios": "^0.21.4",
19
19
  "class-transformer": "^0.5.1",
20
20
  "class-validator": "^0.13.1",
@@ -55,5 +55,5 @@
55
55
  "node_modules"
56
56
  ]
57
57
  },
58
- "gitHead": "4859034b57cf39cebaf1f64716e73f63712dd4b6"
58
+ "gitHead": "7de12c85f7fc6e70f76a7433eb7fcbe1bf85d6a2"
59
59
  }