sahab-utils 1.9.1 → 1.9.2
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/ts/capacity.d.ts +12 -0
- package/dist/ts/capacity.js +23 -0
- package/dist/ts/cash.d.ts +3 -0
- package/dist/ts/cash.js +11 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./constants/types"), exports);
|
|
18
18
|
__exportStar(require("./ts/broadcast"), exports);
|
|
19
|
+
__exportStar(require("./ts/capacity"), exports);
|
|
19
20
|
__exportStar(require("./ts/calcs"), exports);
|
|
20
21
|
__exportStar(require("./ts/cash"), exports);
|
|
21
22
|
__exportStar(require("./ts/cashback"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Provider } from '../constants/types';
|
|
2
|
+
/** Whether a carwash takes orders itself: on unless the owner switched it off, so a record with no flag counts as on. */
|
|
3
|
+
export declare const providerReceivesOrders: (provider?: Pick<Provider, "receiveOrders"> | null) => boolean;
|
|
4
|
+
/** How many orders a slot can hold: the explicit drivers on the booking, else the drivers near the customer, else every
|
|
5
|
+
* active driver, plus the owner when they take orders themselves. The server lists slots and validates bookings with this, and
|
|
6
|
+
* the provider app shows it, so they cannot disagree. */
|
|
7
|
+
export declare function computeAllowedOrdersPerSlot(params: {
|
|
8
|
+
providerReceiveOrders?: boolean;
|
|
9
|
+
totalActiveDrivers: number;
|
|
10
|
+
driverIdsFromClient?: string[];
|
|
11
|
+
nearbyDriverCount?: number;
|
|
12
|
+
}): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.providerReceivesOrders = void 0;
|
|
4
|
+
exports.computeAllowedOrdersPerSlot = computeAllowedOrdersPerSlot;
|
|
5
|
+
/** Whether a carwash takes orders itself: on unless the owner switched it off, so a record with no flag counts as on. */
|
|
6
|
+
const providerReceivesOrders = (provider) => (provider === null || provider === void 0 ? void 0 : provider.receiveOrders) !== false;
|
|
7
|
+
exports.providerReceivesOrders = providerReceivesOrders;
|
|
8
|
+
/** How many orders a slot can hold: the explicit drivers on the booking, else the drivers near the customer, else every
|
|
9
|
+
* active driver, plus the owner when they take orders themselves. The server lists slots and validates bookings with this, and
|
|
10
|
+
* the provider app shows it, so they cannot disagree. */
|
|
11
|
+
function computeAllowedOrdersPerSlot(params) {
|
|
12
|
+
const { providerReceiveOrders, totalActiveDrivers, driverIdsFromClient, nearbyDriverCount } = params;
|
|
13
|
+
if (driverIdsFromClient && driverIdsFromClient.length > 0) {
|
|
14
|
+
return providerReceiveOrders ? driverIdsFromClient.length + 1 : driverIdsFromClient.length;
|
|
15
|
+
}
|
|
16
|
+
if (nearbyDriverCount != null && nearbyDriverCount > 0) {
|
|
17
|
+
return providerReceiveOrders ? nearbyDriverCount + 1 : nearbyDriverCount;
|
|
18
|
+
}
|
|
19
|
+
if (providerReceiveOrders) {
|
|
20
|
+
return totalActiveDrivers + 1;
|
|
21
|
+
}
|
|
22
|
+
return totalActiveDrivers === 0 ? 1 : totalActiveDrivers;
|
|
23
|
+
}
|
package/dist/ts/cash.d.ts
CHANGED
|
@@ -11,3 +11,6 @@ export declare const isFreeOrder: (order?: Partial<Order>) => boolean;
|
|
|
11
11
|
export declare function resolveCashFee(configs?: Pick<PaymentConfigs, 'cashFee'> | null): number;
|
|
12
12
|
/** The fee this order would carry if paid in cash: none when there is nothing to collect. */
|
|
13
13
|
export declare function cashFeeForOrder(order: Partial<Order> | undefined, configs?: Pick<PaymentConfigs, 'cashFee'> | null): number;
|
|
14
|
+
/** What the washer takes from the customer for a cash order, and what the server records as collected when the order is finished:
|
|
15
|
+
* nothing for a free order, else the order's total to pay. Undefined for an online order, which was paid up front. */
|
|
16
|
+
export declare function cashAmountToCollect(order?: Partial<Order>): number | undefined;
|
package/dist/ts/cash.js
CHANGED
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isFreeOrder = exports.getOrderTotalWithoutCashFee = exports.MAX_CASH_FEE = void 0;
|
|
4
4
|
exports.resolveCashFee = resolveCashFee;
|
|
5
5
|
exports.cashFeeForOrder = cashFeeForOrder;
|
|
6
|
+
exports.cashAmountToCollect = cashAmountToCollect;
|
|
6
7
|
const types_1 = require("../constants/types");
|
|
7
8
|
const calcs_1 = require("./calcs");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
8
10
|
/** Cash payment — the shared rules. The fee is set from `payment_methods/configs`; the app only shows it
|
|
9
11
|
* and cloudFun is what charges it, so both must reach the same number from the same config. */
|
|
10
12
|
/** A fee above this is read as a typo (5000 for 5.00) and ignored rather than charged to customers. */
|
|
@@ -26,3 +28,12 @@ function resolveCashFee(configs) {
|
|
|
26
28
|
function cashFeeForOrder(order, configs) {
|
|
27
29
|
return (0, exports.isFreeOrder)(order) ? 0 : resolveCashFee(configs);
|
|
28
30
|
}
|
|
31
|
+
/** What the washer takes from the customer for a cash order, and what the server records as collected when the order is finished:
|
|
32
|
+
* nothing for a free order, else the order's total to pay. Undefined for an online order, which was paid up front. */
|
|
33
|
+
function cashAmountToCollect(order) {
|
|
34
|
+
if ((order === null || order === void 0 ? void 0 : order.paymentType) !== types_1.OrderPaymentType.CASH)
|
|
35
|
+
return undefined;
|
|
36
|
+
if ((0, exports.isFreeOrder)(order))
|
|
37
|
+
return 0;
|
|
38
|
+
return Math.max(0, (0, utils_1.preventNaN)((0, calcs_1.getCustomerTotalToPay)(order)));
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sahab-utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "This package contains types and utils functions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
10
|
"deploy": "npm run build && npm publish",
|
|
11
|
-
"test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js && node tests/utils.test.js && node tests/wheel.test.js && node tests/calcs.test.js && node tests/orderActivity.test.js && node tests/push.test.js && node tests/broadcast.test.js && node tests/iban.test.js && node tests/cash.test.js && node tests/workingHours.test.js && node tests/payLink.test.js && node tests/offerings.test.js"
|
|
11
|
+
"test": "npm run build && node tests/loyalty.test.js && node tests/gifts.test.js && node tests/cashback.test.js && node tests/utils.test.js && node tests/wheel.test.js && node tests/calcs.test.js && node tests/orderActivity.test.js && node tests/push.test.js && node tests/broadcast.test.js && node tests/iban.test.js && node tests/cash.test.js && node tests/workingHours.test.js && node tests/payLink.test.js && node tests/offerings.test.js && node tests/capacity.test.js"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|