@freedom_sky/feige-lib 5.4.1 → 5.5.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/buffet/index.d.ts +6 -2
- package/dist/buffet/index.js +24 -18
- package/package.json +1 -1
- package/src/buffet/index.ts +23 -10
package/dist/buffet/index.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export declare function dishShowPriceWithBuffet({ dishPrice, dishId, buffet, ord
|
|
|
37
37
|
/**
|
|
38
38
|
*
|
|
39
39
|
*/
|
|
40
|
-
export declare function
|
|
40
|
+
export declare function getRoundCoundAndSecondsToNextTurn({ order }: {
|
|
41
41
|
order: Order;
|
|
42
|
-
}):
|
|
42
|
+
}): {
|
|
43
|
+
roundCount?: number;
|
|
44
|
+
maxRounds?: number;
|
|
45
|
+
secondsToNextTurn: number;
|
|
46
|
+
};
|
package/dist/buffet/index.js
CHANGED
|
@@ -55,31 +55,37 @@ exports.dishShowPriceWithBuffet = dishShowPriceWithBuffet;
|
|
|
55
55
|
/**
|
|
56
56
|
*
|
|
57
57
|
*/
|
|
58
|
-
function
|
|
58
|
+
function getRoundCoundAndSecondsToNextTurn(_a) {
|
|
59
59
|
var order = _a.order;
|
|
60
|
-
var _b;
|
|
61
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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.pop().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.
|
|
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
package/src/buffet/index.ts
CHANGED
|
@@ -75,25 +75,38 @@ export function dishShowPriceWithBuffet({
|
|
|
75
75
|
/**
|
|
76
76
|
*
|
|
77
77
|
*/
|
|
78
|
-
export function
|
|
78
|
+
export function getRoundCoundAndSecondsToNextTurn({
|
|
79
79
|
order
|
|
80
80
|
}: {
|
|
81
81
|
order: Order
|
|
82
|
-
}):
|
|
83
|
-
|
|
84
|
-
|
|
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)
|
|
87
|
-
|
|
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)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
if(previousBuffetSubmitTasks.length === 0) {
|
|
98
|
+
secondsToNextTurn = 0
|
|
99
|
+
}else if(previousBuffetSubmitTasks.length >= maxRounds) {
|
|
100
|
+
secondsToNextTurn = Infinity
|
|
101
|
+
}else {
|
|
102
|
+
const lastBuffetSubmitTime = previousBuffetSubmitTasks.pop().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 {
|