@freedom_sky/feige-lib 4.58.0 → 4.58.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.
@@ -8,10 +8,14 @@ export interface PrinteDishInfo {
8
8
  /**
9
9
  *
10
10
  */
11
- export declare function getDishArrFromContents({ contents, lang, specificationInNewLine, order, showBuffet, }: {
11
+ export declare function getDishArrFromContents({ contents, lang, specificationInNewLine, order, showBuffet, text, }: {
12
12
  contents: Content[];
13
13
  lang: string;
14
14
  specificationInNewLine: boolean;
15
15
  order: Order;
16
16
  showBuffet?: boolean;
17
- }): Promise<PrinteDishInfo[]>;
17
+ text?: {
18
+ adult: string;
19
+ child: string;
20
+ };
21
+ }): PrinteDishInfo[];
@@ -1,110 +1,59 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  var index_1 = require("../index");
40
4
  /**
41
5
  *
42
6
  */
43
7
  function getDishArrFromContents(_a) {
44
- var contents = _a.contents, lang = _a.lang, specificationInNewLine = _a.specificationInNewLine, order = _a.order, showBuffet = _a.showBuffet;
45
- return __awaiter(this, void 0, void 0, function () {
46
- var result, specifications, _b, _c, _d, _e, _f, _g;
47
- return __generator(this, function (_h) {
48
- switch (_h.label) {
49
- case 0:
50
- result = contents.map(function (dishGroup) {
51
- var _a;
52
- var selectedNames = [];
53
- dishGroup.dishSnapshot.selectedSpecifications.forEach(function (selectedItems) {
54
- selectedItems.content.forEach(function (tag) {
55
- selectedNames.push(tag.name);
56
- });
57
- });
58
- var name = dishGroup.dishSnapshot.name;
59
- if (!specificationInNewLine && selectedNames.length > 0) {
60
- name += "(" + selectedNames.join() + ")";
61
- }
62
- if (dishGroup.dishSnapshot.type === index_1.DishType.Weigh) {
63
- name += "(" + dishGroup.weight + (index_1.getNameFromNames(dishGroup.dishSnapshot.units, lang, index_1.CONST.DEFALUT_LANGUAGE) || '') + ")";
64
- }
65
- return {
66
- name: name,
67
- count: dishGroup.count,
68
- price: index_1.calcContentPrice({
69
- orderContentItem: dishGroup,
70
- buffetItem: (_a = order.buffet) === null || _a === void 0 ? void 0 : _a.snapshot,
71
- orderType: order.type,
72
- adultNum: order.adultNum,
73
- childNum: order.childNum,
74
- contents: order.content,
75
- }) / dishGroup.count,
76
- specifications: selectedNames,
77
- };
78
- });
79
- if (!(showBuffet && order.type === index_1.OrderTypeEnum.Buffet)) return [3 /*break*/, 5];
80
- specifications = [];
81
- if (!order.adultNum) return [3 /*break*/, 2];
82
- _c = (_b = specifications).push;
83
- _d = "";
84
- return [4 /*yield*/, this.i18n.translate('printer.TEMPLATE.ADULT', { lang: lang })];
85
- case 1:
86
- _c.apply(_b, [_d + (_h.sent()) + order.adultNum]);
87
- _h.label = 2;
88
- case 2:
89
- if (!order.childNum) return [3 /*break*/, 4];
90
- _f = (_e = specifications).push;
91
- _g = "";
92
- return [4 /*yield*/, this.i18n.translate('printer.TEMPLATE.CHILD', { lang: lang })];
93
- case 3:
94
- _f.apply(_e, [_g + (_h.sent()) + order.childNum]);
95
- _h.label = 4;
96
- case 4:
97
- result.unshift({
98
- name: index_1.getNameFromNames(order.buffet.snapshot.names, lang, index_1.CONST.DEFALUT_LANGUAGE) +
99
- ("(" + specifications.join() + ")"),
100
- count: 1,
101
- price: index_1.calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum),
102
- specifications: specifications,
103
- });
104
- _h.label = 5;
105
- case 5: return [2 /*return*/, result];
106
- }
8
+ var contents = _a.contents, lang = _a.lang, specificationInNewLine = _a.specificationInNewLine, order = _a.order, showBuffet = _a.showBuffet, text = _a.text;
9
+ var result = contents.map(function (dishGroup) {
10
+ var _a;
11
+ var selectedNames = [];
12
+ dishGroup.dishSnapshot.selectedSpecifications.forEach(function (selectedItems) {
13
+ selectedItems.content.forEach(function (tag) {
14
+ selectedNames.push(tag.name);
15
+ });
107
16
  });
17
+ var name = index_1.getNameFromNames(dishGroup.dishSnapshot.names, lang, index_1.CONST.DEFALUT_LANGUAGE) || '';
18
+ if (!specificationInNewLine && selectedNames.length > 0) {
19
+ name += "(" + selectedNames.join() + ")";
20
+ }
21
+ if (dishGroup.dishSnapshot.type === index_1.DishType.Weigh) {
22
+ name += "(" + dishGroup.weight + (index_1.getNameFromNames(dishGroup.dishSnapshot.units, lang, index_1.CONST.DEFALUT_LANGUAGE) || '') + ")";
23
+ }
24
+ return {
25
+ name: name,
26
+ count: dishGroup.count,
27
+ price: index_1.calcContentPrice({
28
+ orderContentItem: dishGroup,
29
+ buffetItem: (_a = order.buffet) === null || _a === void 0 ? void 0 : _a.snapshot,
30
+ orderType: order.type,
31
+ adultNum: order.adultNum,
32
+ childNum: order.childNum,
33
+ contents: order.content,
34
+ }) / dishGroup.count,
35
+ specifications: selectedNames,
36
+ };
108
37
  });
38
+ if (showBuffet && order.type === index_1.OrderTypeEnum.Buffet) {
39
+ var specifications = [];
40
+ if (specificationInNewLine) {
41
+ if (order.adultNum) {
42
+ specifications.push("" + (text === null || text === void 0 ? void 0 : text.adult) + order.adultNum);
43
+ }
44
+ if (order.childNum) {
45
+ specifications.push("" + (text === null || text === void 0 ? void 0 : text.child) + order.childNum);
46
+ }
47
+ }
48
+ result.unshift({
49
+ name: index_1.getNameFromNames(order.buffet.snapshot.names, lang, index_1.CONST.DEFALUT_LANGUAGE) + specificationInNewLine
50
+ ? ''
51
+ : "(" + specifications.join() + ")",
52
+ count: 1,
53
+ price: index_1.calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum),
54
+ specifications: specifications,
55
+ });
56
+ }
57
+ return result;
109
58
  }
110
59
  exports.getDishArrFromContents = getDishArrFromContents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freedom_sky/feige-lib",
3
- "version": "4.58.0",
3
+ "version": "4.58.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -19,19 +19,24 @@ export interface PrinteDishInfo {
19
19
  /**
20
20
  *
21
21
  */
22
- export async function getDishArrFromContents({
22
+ export function getDishArrFromContents({
23
23
  contents,
24
24
  lang,
25
25
  specificationInNewLine,
26
26
  order,
27
27
  showBuffet,
28
+ text,
28
29
  }: {
29
30
  contents: Content[];
30
31
  lang: string;
31
32
  specificationInNewLine: boolean;
32
33
  order: Order;
33
34
  showBuffet?: boolean;
34
- }): Promise<PrinteDishInfo[]> {
35
+ text?: {
36
+ adult: string;
37
+ child: string;
38
+ };
39
+ }): PrinteDishInfo[] {
35
40
  const result = contents.map((dishGroup) => {
36
41
  const selectedNames = [];
37
42
  dishGroup.dishSnapshot.selectedSpecifications.forEach((selectedItems) => {
@@ -39,7 +44,7 @@ export async function getDishArrFromContents({
39
44
  selectedNames.push(tag.name);
40
45
  });
41
46
  });
42
- let name = dishGroup.dishSnapshot.name;
47
+ let name = getNameFromNames(dishGroup.dishSnapshot.names, lang, CONST.DEFALUT_LANGUAGE) || '';
43
48
  if (!specificationInNewLine && selectedNames.length > 0) {
44
49
  name += `(${selectedNames.join()})`;
45
50
  }
@@ -65,16 +70,19 @@ export async function getDishArrFromContents({
65
70
  });
66
71
  if (showBuffet && order.type === OrderTypeEnum.Buffet) {
67
72
  const specifications = [];
68
- if (order.adultNum) {
69
- specifications.push(`${await this.i18n.translate('printer.TEMPLATE.ADULT', { lang })}${order.adultNum}`);
70
- }
71
- if (order.childNum) {
72
- specifications.push(`${await this.i18n.translate('printer.TEMPLATE.CHILD', { lang })}${order.childNum}`);
73
+ if (specificationInNewLine) {
74
+ if (order.adultNum) {
75
+ specifications.push(`${text?.adult}${order.adultNum}`);
76
+ }
77
+ if (order.childNum) {
78
+ specifications.push(`${text?.child}${order.childNum}`);
79
+ }
73
80
  }
74
81
  result.unshift({
75
82
  name:
76
- getNameFromNames(order.buffet.snapshot.names, lang, CONST.DEFALUT_LANGUAGE) +
77
- `(${specifications.join()})`,
83
+ getNameFromNames(order.buffet.snapshot.names, lang, CONST.DEFALUT_LANGUAGE) + specificationInNewLine
84
+ ? ''
85
+ : `(${specifications.join()})`,
78
86
  count: 1,
79
87
  price: calcBuffetTotalPrice(order.buffet.snapshot, order.adultNum, order.childNum),
80
88
  specifications: specifications,