@freedom_sky/feige-lib 5.4.1 → 5.5.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.
@@ -37,6 +37,10 @@ export declare function dishShowPriceWithBuffet({ dishPrice, dishId, buffet, ord
37
37
  /**
38
38
  *
39
39
  */
40
- export declare function getTimeToNextTurn({ order }: {
40
+ export declare function getRoundCoundAndSecondsToNextTurn({ order }: {
41
41
  order: Order;
42
- }): number;
42
+ }): {
43
+ roundCount?: number;
44
+ maxRounds?: number;
45
+ secondsToNextTurn: number;
46
+ };
@@ -55,31 +55,37 @@ exports.dishShowPriceWithBuffet = dishShowPriceWithBuffet;
55
55
  /**
56
56
  *
57
57
  */
58
- function getTimeToNextTurn(_a) {
58
+ function getRoundCoundAndSecondsToNextTurn(_a) {
59
59
  var order = _a.order;
60
- var _b;
61
- if (!order)
62
- return 0;
63
- if (order.type !== index_1.OrderTypeEnum.Buffet)
64
- return 0;
60
+ var _b, _c;
61
+ var secondsToNextTurn = 0;
65
62
  var buffetCombosItems = (_b = order.buffet) === null || _b === void 0 ? void 0 : _b.snapshot;
66
- if (!buffetCombosItems)
67
- return 0;
68
- if (!buffetCombosItems.orderingByTurns.enable)
69
- return 0;
70
- var _c = buffetCombosItems.orderingByTurns, interval = _c.interval, maxRounds = _c.maxRounds;
63
+ if (!((_c = buffetCombosItems.orderingByTurns) === null || _c === void 0 ? void 0 : _c.enable)) {
64
+ throw 'Buffet ordering by turns is not enabled';
65
+ }
66
+ ;
67
+ var _d = buffetCombosItems.orderingByTurns, interval = _d.interval, maxRounds = _d.maxRounds;
71
68
  var previousBuffetSubmitTasks = order.tasks.filter(function (task) {
72
69
  return (task.type === index_1.CONST.TASK_TYPE.CHECK || task.type === index_1.CONST.TASK_TYPE.APPEND) &&
73
70
  _haveAtLeastOneSameItem(task.content.map(function (content) { return content.dishSnapshot._id; }), buffetCombosItems.dishes.map(function (dish) { return dish.dishId; }));
74
71
  });
75
- if (previousBuffetSubmitTasks.length === 0)
76
- return 0;
77
- if (previousBuffetSubmitTasks.length >= maxRounds)
78
- return Infinity;
79
- var lastBuffetSubmitTime = previousBuffetSubmitTasks.pop().date;
80
- return interval * 60 - Math.floor((Date.now() - new Date(lastBuffetSubmitTime).getTime()) / 1000);
72
+ if (previousBuffetSubmitTasks.length === 0) {
73
+ secondsToNextTurn = 0;
74
+ }
75
+ else if (previousBuffetSubmitTasks.length >= maxRounds) {
76
+ secondsToNextTurn = Infinity;
77
+ }
78
+ else {
79
+ var lastBuffetSubmitTime = previousBuffetSubmitTasks[previousBuffetSubmitTasks.length - 1].date;
80
+ secondsToNextTurn = interval * 60 - Math.floor((Date.now() - new Date(lastBuffetSubmitTime).getTime()) / 1000);
81
+ }
82
+ return {
83
+ roundCount: previousBuffetSubmitTasks.length,
84
+ secondsToNextTurn: secondsToNextTurn,
85
+ maxRounds: maxRounds
86
+ };
81
87
  }
82
- exports.getTimeToNextTurn = getTimeToNextTurn;
88
+ exports.getRoundCoundAndSecondsToNextTurn = getRoundCoundAndSecondsToNextTurn;
83
89
  function _haveAtLeastOneSameItem(arr1, arr2) {
84
90
  var set1 = new Set(arr1);
85
91
  return arr2.some(function (item) { return set1.has(item); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freedom_sky/feige-lib",
3
- "version": "5.4.1",
3
+ "version": "5.5.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -75,25 +75,38 @@ export function dishShowPriceWithBuffet({
75
75
  /**
76
76
  *
77
77
  */
78
- export function getTimeToNextTurn({
78
+ export function getRoundCoundAndSecondsToNextTurn({
79
79
  order
80
80
  }: {
81
81
  order: Order
82
- }): number {
83
- if(!order) return 0;
84
- if (order.type !== OrderTypeEnum.Buffet) return 0;
82
+ }): {
83
+ roundCount?: number,
84
+ maxRounds?: number,
85
+ secondsToNextTurn: number
86
+ } {
87
+ let secondsToNextTurn = 0;
85
88
  const buffetCombosItems = order.buffet?.snapshot;
86
- if (!buffetCombosItems) return 0;
87
- if (!buffetCombosItems.orderingByTurns.enable) return 0;
89
+ if (!buffetCombosItems.orderingByTurns?.enable) {
90
+ throw 'Buffet ordering by turns is not enabled';
91
+ };
88
92
  const { interval, maxRounds } = buffetCombosItems.orderingByTurns;
89
93
  const previousBuffetSubmitTasks = order.tasks.filter(task =>
90
94
  (task.type === CONST.TASK_TYPE.CHECK || task.type === CONST.TASK_TYPE.APPEND) &&
91
95
  _haveAtLeastOneSameItem(task.content.map(content => content.dishSnapshot._id), buffetCombosItems.dishes.map(dish => dish.dishId))
92
96
  );
93
- if(previousBuffetSubmitTasks.length === 0) return 0;
94
- if(previousBuffetSubmitTasks.length >= maxRounds) return Infinity;
95
- const lastBuffetSubmitTime = previousBuffetSubmitTasks.pop().date;
96
- return interval * 60 - Math.floor((Date.now() - new Date(lastBuffetSubmitTime).getTime()) / 1000);
97
+ if(previousBuffetSubmitTasks.length === 0) {
98
+ secondsToNextTurn = 0
99
+ }else if(previousBuffetSubmitTasks.length >= maxRounds) {
100
+ secondsToNextTurn = Infinity
101
+ }else {
102
+ const lastBuffetSubmitTime = previousBuffetSubmitTasks[previousBuffetSubmitTasks.length -1].date;
103
+ secondsToNextTurn = interval * 60 - Math.floor((Date.now() - new Date(lastBuffetSubmitTime).getTime()) / 1000);
104
+ }
105
+ return {
106
+ roundCount: previousBuffetSubmitTasks.length,
107
+ secondsToNextTurn,
108
+ maxRounds
109
+ }
97
110
  }
98
111
 
99
112
  function _haveAtLeastOneSameItem<T>(arr1: T[], arr2: T[]): boolean {