@managesome/eposmatic-toolkit 0.2.776 → 0.2.778
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/lib/constants/ENUMS.d.ts +17 -0
- package/lib/constants/ENUMS.js +27 -1
- package/lib/helpers/utils/delivery-helpers.d.ts +39 -0
- package/lib/helpers/utils/delivery-helpers.js +81 -0
- package/lib/helpers/utils/hr-helpers.d.ts +2 -0
- package/lib/helpers/utils/hr-helpers.js +8 -0
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/tenant_hr_employees.d.ts +3 -0
- package/lib/schemas/models/tenant_hr_employees.js +5 -0
- package/lib/schemas/models/tenant_hr_leave_requests.d.ts +69 -0
- package/lib/schemas/models/tenant_hr_leave_requests.js +83 -0
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/tenant_hr_employees.d.ts +2 -1
- package/lib/schemas/types/tenant_hr_leave_requests.d.ts +18 -0
- package/lib/schemas/types/tenant_hr_leave_requests.js +2 -0
- package/lib/tests/delivery-expected-time.test.d.ts +1 -0
- package/lib/tests/delivery-expected-time.test.js +80 -0
- package/package.json +1 -1
package/lib/constants/ENUMS.d.ts
CHANGED
|
@@ -1237,3 +1237,20 @@ export declare enum HR_POLICY_STATUS_ENUM {
|
|
|
1237
1237
|
ARCHIVED = "ARCHIVED"
|
|
1238
1238
|
}
|
|
1239
1239
|
export declare const ALL_HR_POLICY_STATUS_NAMES: HR_POLICY_STATUS_ENUM[];
|
|
1240
|
+
export declare enum HR_LEAVE_TYPE_ENUM {
|
|
1241
|
+
ANNUAL = "ANNUAL",
|
|
1242
|
+
SICK = "SICK",
|
|
1243
|
+
CASUAL = "CASUAL",
|
|
1244
|
+
EMERGENCY = "EMERGENCY",
|
|
1245
|
+
MATERNITY = "MATERNITY",
|
|
1246
|
+
PATERNITY = "PATERNITY"
|
|
1247
|
+
}
|
|
1248
|
+
export declare const ALL_HR_LEAVE_TYPE_NAMES: HR_LEAVE_TYPE_ENUM[];
|
|
1249
|
+
export declare enum HR_LEAVE_STATUS_ENUM {
|
|
1250
|
+
PENDING = "PENDING",
|
|
1251
|
+
APPROVED = "APPROVED",
|
|
1252
|
+
REJECTED = "REJECTED",
|
|
1253
|
+
CANCELLED = "CANCELLED"
|
|
1254
|
+
}
|
|
1255
|
+
export declare const ALL_HR_LEAVE_STATUS_NAMES: HR_LEAVE_STATUS_ENUM[];
|
|
1256
|
+
export declare const DEFAULT_HR_LEAVE_ALLOWANCE: Record<HR_LEAVE_TYPE_ENUM, number>;
|
package/lib/constants/ENUMS.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.ALL_EMAIL_DOCUMENT_KINDS = exports.EMAIL_DOCUMENT_KIND_ENUM = exports.AL
|
|
|
5
5
|
exports.PRINTER_INTERFACE_ENUM = exports.RECEIPT_WIDTHS = exports.ALL_NUM_OF_COLUMNS = exports.NUM_OF_COLUMNS_ENUM = exports.SPLIT_SYNC_SOURCE_ENUM = exports.ALL_SPLIT_BILL_TYPES = exports.SPLIT_BILL_TYPE_ENUM = exports.ALL_RIDER_FEE_TYPES = exports.RIDER_FEE_TYPE_ENUM = exports.ALL_DELIVERY_AREAS_SEARCH_TYPES = exports.DELIVERY_AREAS_SEARCH_TYPE_ENUM = exports.ALL_WEB_AUTH_TYPES = exports.WEB_AUTH_TYPE_ENUM = exports.KITCHEN_RECEIPT_TYPE_ENUM = exports.PRINTER_EVENT_TYPE_ENUM = exports.SORT_TYPE_ENUM = exports.WHITELISTED_API_SMS_COUNTRY_CODES = exports.BLACKLISTED_SMS_COUNTRY_CODES = exports.ALL_OTP_TYPES = exports.OTP_TYPE_ENUM = exports.ALL_TAX_INVOICE_PROVIDERS = exports.TAX_INVOICE_PROVIDER_ENUM = exports.ALL_RESERVATION_STATUS_TYPES = exports.RESERVATION_STATUS_ENUM = exports.TENANT_AMOUNT_DUE_TYPE_ENUM = exports.ALL_KITCHEN_DOCKET_FONT_TYPES = exports.KITCHEN_DOCKET_FONT_TYPE_ENUM = exports.ALL_SORT_ORDER_BY_TYPES = exports.SORT_ORDER_BY_ENUM = exports.RECEIPT_IMAGE_TYPE_ENUM = exports.ALL_RECEIPT_TYPES = exports.RECEIPT_TYPE_ENUM = exports.ALL_PRINTING_PREFERENCES = exports.PRINTING_PREFERENCE_ENUM = exports.ALL_PRINTER_BRAND_TYPES = exports.PRINTER_BRAND_TYPE_ENUM = exports.ALL_ORDER_ITEM_TYPES = exports.ORDER_ITEM_TYPE_ENUM = exports.ALL_PLATFORM_PROVIDER_IDS = exports.PLATFORM_PROVIDER_IDS_ENUM = exports.ALL_MARKETING_RECEIPIENT_TYPES = exports.MARKETING_RECEIPIENT_ENUM = exports.ALL_MARKETING_TYPES = exports.MARKETING_TYPE_ENUM = exports.ALL_TOKEN_TYPES = exports.TOKEN_TYPE_ENUM = exports.ALL_EMAIL_STATUS = exports.EMAIL_STATUS_ENUM = exports.ALL_COMMUNICATION_CHANNELS = exports.COMMUNICATION_CHANNEL_ENUM = void 0;
|
|
6
6
|
exports.ALL_ONLINE_ORDERING_DESIGN_TYPES = exports.ONLINE_ORDERING_DESIGN_TYPE_ENUM = exports.ALL_NOTIFICATION_PROVIDERS = exports.NOTIFICATION_PROVIDER_ENUM = exports.ALL_ORDER_COMPLETION_TYPES = exports.ORDER_COMPLETION_TYPE_ENUM = exports.ITEM_COMPARISON_FIELD_ENUM = exports.VOID_ITEM_STAFF_REPORT_ENUM = exports.ALL_DISCOUNT_APPLICABILITY_TYPES = exports.DISCOUNT_APPLICABILITY_ENUM = exports.ALL_DISCOUNT_TYPES = exports.DISCOUNT_TYPE_ENUM = exports.EMAIL_TEMPLATES_TYPE_ENUM = exports.ALL_ALERT_NOTIFICATIONS_TYPES = exports.ALERT_NOTIFICATIONS_TYPE_ENUM = exports.ALL_WALLET_TRANSACTION_STATUS = exports.WALLET_TRANSACTION_STATUS_ENUM = exports.ALL_WALLET_TRANSACTION_CATEGORIES = exports.WALLET_TRANSACTION_CATEGORY_ENUM = exports.ALL_WALLET_TRANSACTION_TYPES = exports.WALLET_TRANSACTION_TYPE_ENUM = exports.ALL_DELIVERY_STATUS = exports.DELIVERY_STATUS_ENUM = exports.ALL_INVENTORY_ITEM_TYPES = exports.INVENTORY_ITEM_TYPE_ENUM = exports.ALL_RATING_TYPES = exports.RATING_TYPE_ENUM = exports.ALL_SUBSCRIPTION_STATUS = exports.SUBSCRIPTION_STATUS_ENUM = exports.ALL_VOID_PURCHASE_ORDER_ITEM_TYPES = exports.VOID_PURCHASE_ORDER_ITEM_TYPE_ENUM = exports.ALL_VOID_ORDER_ITEM_TYPES = exports.VOID_ORDER_ITEM_TYPE_ENUM = exports.COMPARISON_REPORT_TYPE_ENUM = exports.ALL_MULTI_TENANT_WEBSITE_TYPES = exports.MULTI_TENANT_WEBSITE_TYPE_ENUM = exports.ALL_ITEM_TRANSACTION_TYPES = exports.ITEM_TRANSACTION_TYPE_ENUM = exports.INVENTORY_OUTBOUND_TRANSACTIONS = exports.INVENTORY_INBOUND_TRANSACTIONS = exports.ALL_INVENTORY_TRANSACTION_CATEGORIES = exports.INVENTORY_TRANSACTION_CATEGORY_ENUM = exports.ALL_INVENTORY_TRANSACTION_TYPES = exports.INVENTORY_TRANSACTION_TYPE_ENUM = exports.ALL_GST_TYPES = exports.GST_TYPE_ENUM = exports.ALL_EXPENSE_REACCURING_TYPES = exports.EXPENSE_REACCURING_TYPE_ENUM = exports.PAYMENT_EXTENSION_ENUM = exports.ALL_PRINTER_INTERFACES = void 0;
|
|
7
7
|
exports.ALL_HR_CHECK_IN_METHOD_NAMES = exports.HR_CHECK_IN_METHOD_ENUM = exports.ALL_HR_ATTENDANCE_STATUS_NAMES = exports.HR_ATTENDANCE_STATUS_ENUM = exports.ALL_HR_EMPLOYMENT_STATUS_NAMES = exports.HR_EMPLOYMENT_STATUS_ENUM = exports.ALL_INTERNAL_CUSTOMER_PAYMENT_METHOD_NAMES = exports.INTERNAL_CUSTOMER_PAYMENT_METHOD_ENUM = exports.ALL_INTERNAL_CUSTOMER_SUBSCRIPTION_SERVICE_NAMES = exports.INTERNAL_CUSTOMER_SUBSCRIPTION_SERVICE_ENUM = exports.ALL_INTERNAL_CUSTOMER_SUBSCRIPTION_PLAN_NAMES = exports.INTERNAL_CUSTOMER_SUBSCRIPTION_PLAN_ENUM = exports.ALL_INTERNAL_CUSTOMER_BILLING_CYCLE_NAMES = exports.INTERNAL_CUSTOMER_BILLING_CYCLE_ENUM = exports.ALL_INTERNAL_CUSTOMER_TYPE_NAMES = exports.INTERNAL_CUSTOMER_TYPE_ENUM = exports.ALL_INTERNAL_INVOICE_TYPE_NAMES = exports.INTERNAL_INVOICE_TYPE_ENUM = exports.ALL_INTERNAL_INVOICE_STATUS_NAMES = exports.INTERNAL_INVOICE_STATUS_ENUM = exports.ALL_SUBSCRIPTION_HARDWARE_NAMES = exports.SUBSCRIPTION_HARDWARE_ENUM = exports.ALL_CUSTOMER_TARGET_MODES = exports.CUSTOMER_TARGET_MODE_ENUM = exports.ALL_WALLET_ASSIGNMENT_BEHAVIORS = exports.WALLET_ASSIGNMENT_BEHAVIOR_ENUM = exports.ALL_WALLET_ASSET_TYPES = exports.WALLET_ASSET_TYPE_ENUM = exports.ALL_RECEIPT_QR_CODE_TYPES = exports.RECEIPT_QR_CODE_TYPE_ENUM = exports.ALL_INTERNAL_LEAD_STATUS = exports.INTERNAL_LEAD_STATUS_ENUM = exports.ALL_INTERNAL_LEAD_SOURCES = exports.INTERNAL_LEAD_SOURCE_ENUM = exports.ALL_CASH_DRAWER_STATUS = exports.CASH_DRAWER_STATUS_ENUM = exports.ALL_CASH_IN_HAND_TRANSACTION_CATEGORIES = exports.CASH_IN_HAND_TRANSACTION_CATEGORY_ENUM = exports.ALL_CASH_IN_HAND_TRANSACTION_TYPES = exports.CASH_IN_HAND_TRANSACTION_TYPE_ENUM = exports.ALL_CASH_IN_OUT_REFS = exports.CASH_IN_OUT_REF_ENUM = exports.ALL_CASH_IN_OUT_TYPES = exports.CASH_IN_OUT_TYPE_ENUM = exports.ALL_POS_SHIFT_STATUS = exports.POS_SHIFT_STATUS_ENUM = exports.ALL_POS_DAY_STATUS = exports.POS_DAY_STATUS_ENUM = exports.ALL_MODIFIER_OPTION_REF_TYPES = exports.MODIFIER_OPTION_REF_TYPE_ENUM = void 0;
|
|
8
|
-
exports.ALL_HR_POLICY_STATUS_NAMES = exports.HR_POLICY_STATUS_ENUM = exports.ALL_HR_DOCUMENT_STATUS_NAMES = exports.HR_DOCUMENT_STATUS_ENUM = exports.ALL_HR_DOCUMENT_TYPE_NAMES = exports.HR_DOCUMENT_TYPE_ENUM = exports.ALL_HR_PAYMENT_METHOD_NAMES = exports.HR_PAYMENT_METHOD_ENUM = exports.ALL_HR_PAYROLL_STATUS_NAMES = exports.HR_PAYROLL_STATUS_ENUM = exports.ALL_HR_PAY_TYPE_NAMES = exports.HR_PAY_TYPE_ENUM = exports.ALL_HR_EMPLOYEE_DOCUMENT_TYPES = exports.HR_EMPLOYEE_DOCUMENT_TYPE_ENUM = exports.ALL_HR_SHIFT_STATUS_NAMES = exports.HR_SHIFT_STATUS_ENUM = exports.ALL_HR_SHIFT_TYPE_NAMES = exports.HR_SHIFT_TYPE_ENUM = exports.ALL_HR_BIOMETRIC_ENROLLMENT_TYPE_NAMES = exports.HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM = void 0;
|
|
8
|
+
exports.DEFAULT_HR_LEAVE_ALLOWANCE = exports.ALL_HR_LEAVE_STATUS_NAMES = exports.HR_LEAVE_STATUS_ENUM = exports.ALL_HR_LEAVE_TYPE_NAMES = exports.HR_LEAVE_TYPE_ENUM = exports.ALL_HR_POLICY_STATUS_NAMES = exports.HR_POLICY_STATUS_ENUM = exports.ALL_HR_DOCUMENT_STATUS_NAMES = exports.HR_DOCUMENT_STATUS_ENUM = exports.ALL_HR_DOCUMENT_TYPE_NAMES = exports.HR_DOCUMENT_TYPE_ENUM = exports.ALL_HR_PAYMENT_METHOD_NAMES = exports.HR_PAYMENT_METHOD_ENUM = exports.ALL_HR_PAYROLL_STATUS_NAMES = exports.HR_PAYROLL_STATUS_ENUM = exports.ALL_HR_PAY_TYPE_NAMES = exports.HR_PAY_TYPE_ENUM = exports.ALL_HR_EMPLOYEE_DOCUMENT_TYPES = exports.HR_EMPLOYEE_DOCUMENT_TYPE_ENUM = exports.ALL_HR_SHIFT_STATUS_NAMES = exports.HR_SHIFT_STATUS_ENUM = exports.ALL_HR_SHIFT_TYPE_NAMES = exports.HR_SHIFT_TYPE_ENUM = exports.ALL_HR_BIOMETRIC_ENROLLMENT_TYPE_NAMES = exports.HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM = void 0;
|
|
9
9
|
var ORDER_FROM_ENUM;
|
|
10
10
|
(function (ORDER_FROM_ENUM) {
|
|
11
11
|
ORDER_FROM_ENUM["WEB"] = "WEB";
|
|
@@ -1940,3 +1940,29 @@ var HR_POLICY_STATUS_ENUM;
|
|
|
1940
1940
|
HR_POLICY_STATUS_ENUM["ARCHIVED"] = "ARCHIVED";
|
|
1941
1941
|
})(HR_POLICY_STATUS_ENUM || (exports.HR_POLICY_STATUS_ENUM = HR_POLICY_STATUS_ENUM = {}));
|
|
1942
1942
|
exports.ALL_HR_POLICY_STATUS_NAMES = Object.values(HR_POLICY_STATUS_ENUM);
|
|
1943
|
+
var HR_LEAVE_TYPE_ENUM;
|
|
1944
|
+
(function (HR_LEAVE_TYPE_ENUM) {
|
|
1945
|
+
HR_LEAVE_TYPE_ENUM["ANNUAL"] = "ANNUAL";
|
|
1946
|
+
HR_LEAVE_TYPE_ENUM["SICK"] = "SICK";
|
|
1947
|
+
HR_LEAVE_TYPE_ENUM["CASUAL"] = "CASUAL";
|
|
1948
|
+
HR_LEAVE_TYPE_ENUM["EMERGENCY"] = "EMERGENCY";
|
|
1949
|
+
HR_LEAVE_TYPE_ENUM["MATERNITY"] = "MATERNITY";
|
|
1950
|
+
HR_LEAVE_TYPE_ENUM["PATERNITY"] = "PATERNITY";
|
|
1951
|
+
})(HR_LEAVE_TYPE_ENUM || (exports.HR_LEAVE_TYPE_ENUM = HR_LEAVE_TYPE_ENUM = {}));
|
|
1952
|
+
exports.ALL_HR_LEAVE_TYPE_NAMES = Object.values(HR_LEAVE_TYPE_ENUM);
|
|
1953
|
+
var HR_LEAVE_STATUS_ENUM;
|
|
1954
|
+
(function (HR_LEAVE_STATUS_ENUM) {
|
|
1955
|
+
HR_LEAVE_STATUS_ENUM["PENDING"] = "PENDING";
|
|
1956
|
+
HR_LEAVE_STATUS_ENUM["APPROVED"] = "APPROVED";
|
|
1957
|
+
HR_LEAVE_STATUS_ENUM["REJECTED"] = "REJECTED";
|
|
1958
|
+
HR_LEAVE_STATUS_ENUM["CANCELLED"] = "CANCELLED";
|
|
1959
|
+
})(HR_LEAVE_STATUS_ENUM || (exports.HR_LEAVE_STATUS_ENUM = HR_LEAVE_STATUS_ENUM = {}));
|
|
1960
|
+
exports.ALL_HR_LEAVE_STATUS_NAMES = Object.values(HR_LEAVE_STATUS_ENUM);
|
|
1961
|
+
exports.DEFAULT_HR_LEAVE_ALLOWANCE = {
|
|
1962
|
+
ANNUAL: 21,
|
|
1963
|
+
SICK: 10,
|
|
1964
|
+
CASUAL: 7,
|
|
1965
|
+
EMERGENCY: 5,
|
|
1966
|
+
MATERNITY: 90,
|
|
1967
|
+
PATERNITY: 14,
|
|
1968
|
+
};
|
|
@@ -1,2 +1,41 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
1
2
|
import { IDelivery, IDeliveryOrder } from '../../schemas';
|
|
2
3
|
export declare function getDeliveryWithPrice<T extends IDelivery | IDeliveryOrder | Partial<IDelivery> | Partial<IDeliveryOrder>>(delivery: T, writeable?: boolean): T;
|
|
4
|
+
/**
|
|
5
|
+
* Calculate the expected delivery time for a delivery order.
|
|
6
|
+
*
|
|
7
|
+
* Priority:
|
|
8
|
+
* 1. `order.delivery_details.estimated_delivery_time` - the promised ETA.
|
|
9
|
+
* 2. ASAP orders (null ETA): `createdAt` + the tenant's default `delivery_time` in milliseconds -
|
|
10
|
+
* the same value used as `now + delivery_time` when the order is punched.
|
|
11
|
+
* 3. Distance-based fallback (only when the tenant setting is unavailable): travel time at
|
|
12
|
+
* 2 minutes per km plus the tenant's default `default_prep_minutes`; a flat 25 minutes when
|
|
13
|
+
* the distance is unknown (0 m).
|
|
14
|
+
*
|
|
15
|
+
* @param deliveryTimeMs Tenant's default `delivery_time` settings value, in milliseconds.
|
|
16
|
+
* @param prepMinutes Tenant's default `default_prep_minutes` settings value, in minutes - added
|
|
17
|
+
* to the distance-based travel estimate.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getDeliveryExpectedTime: (delivery: IDeliveryOrder, deliveryTimeMs?: number | null, prepMinutes?: number | null) => {
|
|
20
|
+
expectedTime: moment.Moment;
|
|
21
|
+
isCalculated: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Completion tag for a finished delivery, based on how `updatedAt` (treated as the completion
|
|
25
|
+
* time) compares to the expected delivery time from `getDeliveryExpectedTime`.
|
|
26
|
+
*
|
|
27
|
+
* - Completed at least 1 minute before the expected time -> "Good" (success).
|
|
28
|
+
* - Completed within 1 minute of the expected time -> "Slight Delay" (warning).
|
|
29
|
+
* - Completed more than 1 minute after the expected time -> "Late" (error).
|
|
30
|
+
*
|
|
31
|
+
* `completionTime` is the total delivery duration (`updatedAt` - `createdAt`) formatted as
|
|
32
|
+
* `Xm` or `Xh Ym`. Returns `null` for deliveries that are not completed.
|
|
33
|
+
*
|
|
34
|
+
* @param deliveryTimeMs Tenant's default `delivery_time` settings value, in milliseconds.
|
|
35
|
+
* @param prepMinutes Tenant's default `default_prep_minutes` settings value, in minutes.
|
|
36
|
+
*/
|
|
37
|
+
export declare const getDeliveryCompletionTag: (delivery: IDeliveryOrder, deliveryTimeMs?: number | null, prepMinutes?: number | null) => {
|
|
38
|
+
label: string;
|
|
39
|
+
color: "success" | "warning" | "error";
|
|
40
|
+
completionTime: string;
|
|
41
|
+
} | null;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDeliveryCompletionTag = exports.getDeliveryExpectedTime = void 0;
|
|
3
7
|
exports.getDeliveryWithPrice = getDeliveryWithPrice;
|
|
8
|
+
const moment_1 = __importDefault(require("moment"));
|
|
9
|
+
const constants_1 = require("../../constants");
|
|
4
10
|
const price_conversion_1 = require("./price-conversion");
|
|
5
11
|
function getDeliveryWithPrice(delivery, writeable) {
|
|
6
12
|
const convertToPrice = writeable ? price_conversion_1.convertPriceToCents : price_conversion_1.convertPriceFromCents;
|
|
@@ -13,3 +19,78 @@ function getDeliveryWithPrice(delivery, writeable) {
|
|
|
13
19
|
: {}),
|
|
14
20
|
};
|
|
15
21
|
}
|
|
22
|
+
/** Distance-based fallback: 0 m -> 25 minutes; otherwise prep minutes + 2 minutes per km. */
|
|
23
|
+
const FALLBACK_ZERO_DISTANCE_MINUTES = 25;
|
|
24
|
+
const FALLBACK_MINUTES_PER_KM = 2;
|
|
25
|
+
/**
|
|
26
|
+
* Calculate the expected delivery time for a delivery order.
|
|
27
|
+
*
|
|
28
|
+
* Priority:
|
|
29
|
+
* 1. `order.delivery_details.estimated_delivery_time` - the promised ETA.
|
|
30
|
+
* 2. ASAP orders (null ETA): `createdAt` + the tenant's default `delivery_time` in milliseconds -
|
|
31
|
+
* the same value used as `now + delivery_time` when the order is punched.
|
|
32
|
+
* 3. Distance-based fallback (only when the tenant setting is unavailable): travel time at
|
|
33
|
+
* 2 minutes per km plus the tenant's default `default_prep_minutes`; a flat 25 minutes when
|
|
34
|
+
* the distance is unknown (0 m).
|
|
35
|
+
*
|
|
36
|
+
* @param deliveryTimeMs Tenant's default `delivery_time` settings value, in milliseconds.
|
|
37
|
+
* @param prepMinutes Tenant's default `default_prep_minutes` settings value, in minutes - added
|
|
38
|
+
* to the distance-based travel estimate.
|
|
39
|
+
*/
|
|
40
|
+
const getDeliveryExpectedTime = (delivery, deliveryTimeMs, prepMinutes) => {
|
|
41
|
+
const expectedTimeValue = delivery.order?.delivery_details?.estimated_delivery_time;
|
|
42
|
+
if (expectedTimeValue) {
|
|
43
|
+
return { expectedTime: (0, moment_1.default)(expectedTimeValue), isCalculated: false };
|
|
44
|
+
}
|
|
45
|
+
const createdAt = (0, moment_1.default)(delivery.createdAt);
|
|
46
|
+
// ASAP case: same value used when punching the order (now + delivery_time).
|
|
47
|
+
if (deliveryTimeMs != null && deliveryTimeMs > 0) {
|
|
48
|
+
return { expectedTime: createdAt.clone().add(deliveryTimeMs, 'milliseconds'), isCalculated: true };
|
|
49
|
+
}
|
|
50
|
+
const distanceInMeters = delivery.order?.delivery_details?.distance_in_meters_from_store || 0;
|
|
51
|
+
const prepOffsetMinutes = prepMinutes != null && prepMinutes > 0 ? prepMinutes : 0;
|
|
52
|
+
const deliveryMinutes = distanceInMeters === 0
|
|
53
|
+
? FALLBACK_ZERO_DISTANCE_MINUTES
|
|
54
|
+
: prepOffsetMinutes + (distanceInMeters / 1000) * FALLBACK_MINUTES_PER_KM;
|
|
55
|
+
return { expectedTime: createdAt.clone().add(deliveryMinutes, 'minutes'), isCalculated: true };
|
|
56
|
+
};
|
|
57
|
+
exports.getDeliveryExpectedTime = getDeliveryExpectedTime;
|
|
58
|
+
/**
|
|
59
|
+
* Completion tag for a finished delivery, based on how `updatedAt` (treated as the completion
|
|
60
|
+
* time) compares to the expected delivery time from `getDeliveryExpectedTime`.
|
|
61
|
+
*
|
|
62
|
+
* - Completed at least 1 minute before the expected time -> "Good" (success).
|
|
63
|
+
* - Completed within 1 minute of the expected time -> "Slight Delay" (warning).
|
|
64
|
+
* - Completed more than 1 minute after the expected time -> "Late" (error).
|
|
65
|
+
*
|
|
66
|
+
* `completionTime` is the total delivery duration (`updatedAt` - `createdAt`) formatted as
|
|
67
|
+
* `Xm` or `Xh Ym`. Returns `null` for deliveries that are not completed.
|
|
68
|
+
*
|
|
69
|
+
* @param deliveryTimeMs Tenant's default `delivery_time` settings value, in milliseconds.
|
|
70
|
+
* @param prepMinutes Tenant's default `default_prep_minutes` settings value, in minutes.
|
|
71
|
+
*/
|
|
72
|
+
const getDeliveryCompletionTag = (delivery, deliveryTimeMs, prepMinutes) => {
|
|
73
|
+
if (delivery.status !== constants_1.DELIVERY_STATUS_ENUM.COMPLETED)
|
|
74
|
+
return null;
|
|
75
|
+
const completedAt = (0, moment_1.default)(delivery.updatedAt);
|
|
76
|
+
const createdAt = (0, moment_1.default)(delivery.createdAt);
|
|
77
|
+
const { expectedTime } = (0, exports.getDeliveryExpectedTime)(delivery, deliveryTimeMs, prepMinutes);
|
|
78
|
+
const diffMinutes = completedAt.diff(expectedTime, 'minutes');
|
|
79
|
+
const totalSeconds = completedAt.diff(createdAt, 'seconds');
|
|
80
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
81
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
82
|
+
const completionTime = hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`;
|
|
83
|
+
if (diffMinutes <= -1) {
|
|
84
|
+
// Completed before expected time by at least 1 minute.
|
|
85
|
+
return { label: 'Good', color: 'success', completionTime };
|
|
86
|
+
}
|
|
87
|
+
else if (diffMinutes <= 1) {
|
|
88
|
+
// Completed within 1 minute of expected time.
|
|
89
|
+
return { label: 'Slight Delay', color: 'warning', completionTime };
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// Completed after expected time by more than 1 minute.
|
|
93
|
+
return { label: 'Late', color: 'error', completionTime };
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
exports.getDeliveryCompletionTag = getDeliveryCompletionTag;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HR_LEAVE_TYPE_ENUM } from '../../constants';
|
|
1
2
|
import { ITenantHrEmployee, ITenantHrPayroll } from '../../schemas';
|
|
2
3
|
export interface IHrPayrollPriceFields {
|
|
3
4
|
salary_per_hour?: number | null;
|
|
@@ -24,6 +25,7 @@ export interface IHrEmployeePriceFields {
|
|
|
24
25
|
hr_working_days_per_month?: number | null;
|
|
25
26
|
hr_hours_per_working_day?: number | null;
|
|
26
27
|
hr_overtime_multiplier?: number | null;
|
|
28
|
+
leave_allowance?: Partial<Record<HR_LEAVE_TYPE_ENUM, number>> | null;
|
|
27
29
|
}
|
|
28
30
|
export declare function getHrEmployeeWithPrice<T extends IHrEmployeePriceFields>(employee: T, writeable?: boolean): T;
|
|
29
31
|
export declare function getHrEmployeesFetchedData(data: ITenantHrEmployee[]): ITenantHrEmployee[];
|
|
@@ -38,6 +38,14 @@ function getHrEmployeeWithPrice(employee, writeable) {
|
|
|
38
38
|
const convert = writeable ? price_conversion_1.convertDecimalToInt : price_conversion_1.convertIntToDecimal;
|
|
39
39
|
return {
|
|
40
40
|
...employee,
|
|
41
|
+
...(employee.leave_allowance
|
|
42
|
+
? {
|
|
43
|
+
leave_allowance: Object.fromEntries(Object.entries(employee.leave_allowance).map(([leave_type, days]) => [
|
|
44
|
+
leave_type,
|
|
45
|
+
typeof days === 'number' ? convert(days) : days,
|
|
46
|
+
])),
|
|
47
|
+
}
|
|
48
|
+
: {}),
|
|
41
49
|
...(employee.salary_per_hour != null ? { salary_per_hour: convert(employee.salary_per_hour) } : {}),
|
|
42
50
|
...(employee.monthly_salary != null ? { monthly_salary: convert(employee.monthly_salary) } : {}),
|
|
43
51
|
...(employee.hr_working_days_per_month != null
|
|
@@ -56,6 +56,7 @@ export * from './tenant_hr_biometric_enrollments';
|
|
|
56
56
|
export * from './tenant_hr_departments';
|
|
57
57
|
export * from './tenant_hr_documents';
|
|
58
58
|
export * from './tenant_hr_employees';
|
|
59
|
+
export * from './tenant_hr_leave_requests';
|
|
59
60
|
export * from './tenant_hr_payrolls';
|
|
60
61
|
export * from './tenant_hr_policies';
|
|
61
62
|
export * from './tenant_hr_positions';
|
|
@@ -72,6 +72,7 @@ __exportStar(require("./tenant_hr_biometric_enrollments"), exports);
|
|
|
72
72
|
__exportStar(require("./tenant_hr_departments"), exports);
|
|
73
73
|
__exportStar(require("./tenant_hr_documents"), exports);
|
|
74
74
|
__exportStar(require("./tenant_hr_employees"), exports);
|
|
75
|
+
__exportStar(require("./tenant_hr_leave_requests"), exports);
|
|
75
76
|
__exportStar(require("./tenant_hr_payrolls"), exports);
|
|
76
77
|
__exportStar(require("./tenant_hr_policies"), exports);
|
|
77
78
|
__exportStar(require("./tenant_hr_positions"), exports);
|
|
@@ -24,6 +24,7 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
|
|
|
24
24
|
salary_per_hour: number;
|
|
25
25
|
monthly_salary: number;
|
|
26
26
|
pay_type: HR_PAY_TYPE_ENUM;
|
|
27
|
+
leave_allowance: Map<string, number>;
|
|
27
28
|
hr_working_days_per_month: number;
|
|
28
29
|
hr_hours_per_working_day: number;
|
|
29
30
|
hr_overtime_multiplier: number;
|
|
@@ -349,6 +350,7 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
|
|
|
349
350
|
salary_per_hour: number;
|
|
350
351
|
monthly_salary: number;
|
|
351
352
|
pay_type: HR_PAY_TYPE_ENUM;
|
|
353
|
+
leave_allowance: Map<string, number>;
|
|
352
354
|
hr_working_days_per_month: number;
|
|
353
355
|
hr_hours_per_working_day: number;
|
|
354
356
|
hr_overtime_multiplier: number;
|
|
@@ -674,6 +676,7 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
|
|
|
674
676
|
salary_per_hour: number;
|
|
675
677
|
monthly_salary: number;
|
|
676
678
|
pay_type: HR_PAY_TYPE_ENUM;
|
|
679
|
+
leave_allowance: Map<string, number>;
|
|
677
680
|
hr_working_days_per_month: number;
|
|
678
681
|
hr_hours_per_working_day: number;
|
|
679
682
|
hr_overtime_multiplier: number;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { HR_LEAVE_STATUS_ENUM } from '../../constants';
|
|
3
|
+
export declare const TenantHrLeaveRequestSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
4
|
+
timestamps: true;
|
|
5
|
+
versionKey: false;
|
|
6
|
+
minimize: false;
|
|
7
|
+
}, {
|
|
8
|
+
createdAt: NativeDate;
|
|
9
|
+
updatedAt: NativeDate;
|
|
10
|
+
} & {
|
|
11
|
+
_id: import("mongoose").Types.ObjectId;
|
|
12
|
+
tenant_id: string;
|
|
13
|
+
reason: string;
|
|
14
|
+
createdAt: NativeDate;
|
|
15
|
+
updatedAt: NativeDate;
|
|
16
|
+
start_date: NativeDate;
|
|
17
|
+
end_date: NativeDate;
|
|
18
|
+
status: HR_LEAVE_STATUS_ENUM;
|
|
19
|
+
employee_id: string;
|
|
20
|
+
leave_type: import("../../constants").HR_LEAVE_TYPE_ENUM;
|
|
21
|
+
is_half_day: boolean;
|
|
22
|
+
total_days: number;
|
|
23
|
+
reviewed_by: string;
|
|
24
|
+
reviewed_at: NativeDate;
|
|
25
|
+
rejection_reason: string;
|
|
26
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
27
|
+
createdAt: NativeDate;
|
|
28
|
+
updatedAt: NativeDate;
|
|
29
|
+
} & {
|
|
30
|
+
_id: import("mongoose").Types.ObjectId;
|
|
31
|
+
tenant_id: string;
|
|
32
|
+
reason: string;
|
|
33
|
+
createdAt: NativeDate;
|
|
34
|
+
updatedAt: NativeDate;
|
|
35
|
+
start_date: NativeDate;
|
|
36
|
+
end_date: NativeDate;
|
|
37
|
+
status: HR_LEAVE_STATUS_ENUM;
|
|
38
|
+
employee_id: string;
|
|
39
|
+
leave_type: import("../../constants").HR_LEAVE_TYPE_ENUM;
|
|
40
|
+
is_half_day: boolean;
|
|
41
|
+
total_days: number;
|
|
42
|
+
reviewed_by: string;
|
|
43
|
+
reviewed_at: NativeDate;
|
|
44
|
+
rejection_reason: string;
|
|
45
|
+
}>> & import("mongoose").FlatRecord<{
|
|
46
|
+
createdAt: NativeDate;
|
|
47
|
+
updatedAt: NativeDate;
|
|
48
|
+
} & {
|
|
49
|
+
_id: import("mongoose").Types.ObjectId;
|
|
50
|
+
tenant_id: string;
|
|
51
|
+
reason: string;
|
|
52
|
+
createdAt: NativeDate;
|
|
53
|
+
updatedAt: NativeDate;
|
|
54
|
+
start_date: NativeDate;
|
|
55
|
+
end_date: NativeDate;
|
|
56
|
+
status: HR_LEAVE_STATUS_ENUM;
|
|
57
|
+
employee_id: string;
|
|
58
|
+
leave_type: import("../../constants").HR_LEAVE_TYPE_ENUM;
|
|
59
|
+
is_half_day: boolean;
|
|
60
|
+
total_days: number;
|
|
61
|
+
reviewed_by: string;
|
|
62
|
+
reviewed_at: NativeDate;
|
|
63
|
+
rejection_reason: string;
|
|
64
|
+
}> & Required<{
|
|
65
|
+
_id: import("mongoose").Types.ObjectId;
|
|
66
|
+
}> & {
|
|
67
|
+
__v: number;
|
|
68
|
+
}>;
|
|
69
|
+
export declare const TENANT_HR_LEAVE_REQUESTS_COLLECTION_NAME = "tenant_hr_leave_requests";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TENANT_HR_LEAVE_REQUESTS_COLLECTION_NAME = exports.TenantHrLeaveRequestSchema = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
exports.TenantHrLeaveRequestSchema = new mongoose_1.Schema({
|
|
7
|
+
_id: {
|
|
8
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
9
|
+
required: true,
|
|
10
|
+
immutable: true,
|
|
11
|
+
},
|
|
12
|
+
tenant_id: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
immutable: true,
|
|
16
|
+
ref: 'tenants',
|
|
17
|
+
},
|
|
18
|
+
employee_id: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
immutable: true,
|
|
22
|
+
ref: 'tenant_hr_employees',
|
|
23
|
+
},
|
|
24
|
+
leave_type: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
enum: constants_1.ALL_HR_LEAVE_TYPE_NAMES,
|
|
28
|
+
},
|
|
29
|
+
start_date: {
|
|
30
|
+
type: mongoose_1.Schema.Types.Date,
|
|
31
|
+
required: true,
|
|
32
|
+
},
|
|
33
|
+
end_date: {
|
|
34
|
+
type: mongoose_1.Schema.Types.Date,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
is_half_day: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: false,
|
|
40
|
+
},
|
|
41
|
+
total_days: {
|
|
42
|
+
type: Number,
|
|
43
|
+
required: true,
|
|
44
|
+
},
|
|
45
|
+
reason: {
|
|
46
|
+
type: String,
|
|
47
|
+
required: true,
|
|
48
|
+
},
|
|
49
|
+
status: {
|
|
50
|
+
type: String,
|
|
51
|
+
required: true,
|
|
52
|
+
enum: constants_1.ALL_HR_LEAVE_STATUS_NAMES,
|
|
53
|
+
default: constants_1.HR_LEAVE_STATUS_ENUM.PENDING,
|
|
54
|
+
},
|
|
55
|
+
reviewed_by: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: null,
|
|
58
|
+
},
|
|
59
|
+
reviewed_at: {
|
|
60
|
+
type: mongoose_1.Schema.Types.Date,
|
|
61
|
+
default: null,
|
|
62
|
+
},
|
|
63
|
+
rejection_reason: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: null,
|
|
66
|
+
},
|
|
67
|
+
createdAt: {
|
|
68
|
+
type: mongoose_1.Schema.Types.Date,
|
|
69
|
+
required: true,
|
|
70
|
+
default: () => new Date(),
|
|
71
|
+
immutable: true,
|
|
72
|
+
},
|
|
73
|
+
updatedAt: {
|
|
74
|
+
type: mongoose_1.Schema.Types.Date,
|
|
75
|
+
required: true,
|
|
76
|
+
default: () => new Date(),
|
|
77
|
+
},
|
|
78
|
+
}, {
|
|
79
|
+
timestamps: true,
|
|
80
|
+
versionKey: false,
|
|
81
|
+
minimize: false,
|
|
82
|
+
});
|
|
83
|
+
exports.TENANT_HR_LEAVE_REQUESTS_COLLECTION_NAME = 'tenant_hr_leave_requests';
|
|
@@ -63,6 +63,7 @@ export * from './tenant_hr_biometric_enrollments';
|
|
|
63
63
|
export * from './tenant_hr_departments';
|
|
64
64
|
export * from './tenant_hr_documents';
|
|
65
65
|
export * from './tenant_hr_employees';
|
|
66
|
+
export * from './tenant_hr_leave_requests';
|
|
66
67
|
export * from './tenant_hr_payrolls';
|
|
67
68
|
export * from './tenant_hr_policies';
|
|
68
69
|
export * from './tenant_hr_positions';
|
|
@@ -79,6 +79,7 @@ __exportStar(require("./tenant_hr_biometric_enrollments"), exports);
|
|
|
79
79
|
__exportStar(require("./tenant_hr_departments"), exports);
|
|
80
80
|
__exportStar(require("./tenant_hr_documents"), exports);
|
|
81
81
|
__exportStar(require("./tenant_hr_employees"), exports);
|
|
82
|
+
__exportStar(require("./tenant_hr_leave_requests"), exports);
|
|
82
83
|
__exportStar(require("./tenant_hr_payrolls"), exports);
|
|
83
84
|
__exportStar(require("./tenant_hr_policies"), exports);
|
|
84
85
|
__exportStar(require("./tenant_hr_positions"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HR_DOCUMENT_TYPE_ENUM, HR_EMPLOYMENT_STATUS_ENUM, HR_PAY_TYPE_ENUM } from '../../constants';
|
|
1
|
+
import { HR_DOCUMENT_TYPE_ENUM, HR_EMPLOYMENT_STATUS_ENUM, HR_LEAVE_TYPE_ENUM, HR_PAY_TYPE_ENUM } from '../../constants';
|
|
2
2
|
import { IItemSpecialHour } from './common';
|
|
3
3
|
export interface ITenantHrEmergencyContact {
|
|
4
4
|
name: string;
|
|
@@ -35,6 +35,7 @@ export interface ITenantHrEmployee {
|
|
|
35
35
|
hr_working_days_per_month: number;
|
|
36
36
|
hr_hours_per_working_day: number;
|
|
37
37
|
hr_overtime_multiplier: number;
|
|
38
|
+
leave_allowance?: Partial<Record<HR_LEAVE_TYPE_ENUM, number>>;
|
|
38
39
|
docs: Record<HR_DOCUMENT_TYPE_ENUM, ITenantHrEmployeeDocument>;
|
|
39
40
|
notes?: string | null;
|
|
40
41
|
createdAt: Date;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HR_LEAVE_STATUS_ENUM, HR_LEAVE_TYPE_ENUM } from '../../constants';
|
|
2
|
+
export interface ITenantHrLeaveRequest {
|
|
3
|
+
_id: string;
|
|
4
|
+
tenant_id: string;
|
|
5
|
+
employee_id: string;
|
|
6
|
+
leave_type: HR_LEAVE_TYPE_ENUM;
|
|
7
|
+
start_date: Date;
|
|
8
|
+
end_date: Date;
|
|
9
|
+
is_half_day: boolean;
|
|
10
|
+
total_days: number;
|
|
11
|
+
reason: string;
|
|
12
|
+
status: HR_LEAVE_STATUS_ENUM;
|
|
13
|
+
reviewed_by?: string | null;
|
|
14
|
+
reviewed_at?: Date | null;
|
|
15
|
+
rejection_reason?: string | null;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date | null;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const delivery_helpers_1 = require("../helpers/utils/delivery-helpers");
|
|
5
|
+
const CREATED_AT = new Date('2026-09-22T10:00:00.000Z');
|
|
6
|
+
const delivery = ({ estimatedDeliveryTime = null, distanceInMeters = 0, createdAt = CREATED_AT, updatedAt = new Date(CREATED_AT.getTime() + 20 * 60000), status = constants_1.DELIVERY_STATUS_ENUM.COMPLETED, } = {}) => ({
|
|
7
|
+
createdAt,
|
|
8
|
+
updatedAt,
|
|
9
|
+
status,
|
|
10
|
+
order: {
|
|
11
|
+
delivery_details: {
|
|
12
|
+
estimated_delivery_time: estimatedDeliveryTime,
|
|
13
|
+
distance_in_meters_from_store: distanceInMeters,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
describe('getDeliveryExpectedTime', () => {
|
|
18
|
+
it('uses the promised estimated_delivery_time as-is', () => {
|
|
19
|
+
const eta = new Date('2026-09-22T11:00:00.000Z');
|
|
20
|
+
const { expectedTime, isCalculated } = (0, delivery_helpers_1.getDeliveryExpectedTime)(delivery({ estimatedDeliveryTime: eta }), 3600000);
|
|
21
|
+
expect(expectedTime.valueOf()).toBe(eta.getTime());
|
|
22
|
+
expect(isCalculated).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
it('uses createdAt + delivery_time for ASAP orders when the tenant setting is available', () => {
|
|
25
|
+
const { expectedTime, isCalculated } = (0, delivery_helpers_1.getDeliveryExpectedTime)(delivery({ distanceInMeters: 4000 }), 45 * 60000);
|
|
26
|
+
expect(expectedTime.valueOf()).toBe(CREATED_AT.getTime() + 45 * 60000);
|
|
27
|
+
expect(isCalculated).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
it('falls back to 25 minutes for 0 distance when the tenant setting is unavailable', () => {
|
|
30
|
+
const { expectedTime, isCalculated } = (0, delivery_helpers_1.getDeliveryExpectedTime)(delivery({ distanceInMeters: 0 }));
|
|
31
|
+
expect(expectedTime.valueOf()).toBe(CREATED_AT.getTime() + 25 * 60000);
|
|
32
|
+
expect(isCalculated).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
it('falls back to 2 minutes per km when the tenant setting is unavailable', () => {
|
|
35
|
+
const { expectedTime } = (0, delivery_helpers_1.getDeliveryExpectedTime)(delivery({ distanceInMeters: 3000 }), null);
|
|
36
|
+
expect(expectedTime.valueOf()).toBe(CREATED_AT.getTime() + 6 * 60000);
|
|
37
|
+
});
|
|
38
|
+
it('ignores a zero tenant delivery_time and falls back to distance', () => {
|
|
39
|
+
const { expectedTime } = (0, delivery_helpers_1.getDeliveryExpectedTime)(delivery({ distanceInMeters: 3000 }), 0);
|
|
40
|
+
expect(expectedTime.valueOf()).toBe(CREATED_AT.getTime() + 6 * 60000);
|
|
41
|
+
});
|
|
42
|
+
it('adds the tenant prep minutes to the per-km travel estimate', () => {
|
|
43
|
+
const { expectedTime } = (0, delivery_helpers_1.getDeliveryExpectedTime)(delivery({ distanceInMeters: 3000 }), null, 15);
|
|
44
|
+
expect(expectedTime.valueOf()).toBe(CREATED_AT.getTime() + 21 * 60000);
|
|
45
|
+
});
|
|
46
|
+
it('keeps the flat default for 0 distance even when prep minutes are provided', () => {
|
|
47
|
+
const { expectedTime } = (0, delivery_helpers_1.getDeliveryExpectedTime)(delivery({ distanceInMeters: 0 }), null, 15);
|
|
48
|
+
expect(expectedTime.valueOf()).toBe(CREATED_AT.getTime() + 25 * 60000);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('getDeliveryCompletionTag', () => {
|
|
52
|
+
// With a 25 minute delivery_time the expected ETA is 10:25 for CREATED_AT.
|
|
53
|
+
const DELIVERY_TIME_MS = 25 * 60000;
|
|
54
|
+
const at = (minutes) => new Date(CREATED_AT.getTime() + minutes * 60000);
|
|
55
|
+
it('returns null for deliveries that are not completed', () => {
|
|
56
|
+
const tag = (0, delivery_helpers_1.getDeliveryCompletionTag)(delivery({ status: constants_1.DELIVERY_STATUS_ENUM.IN_PROGRESS }), DELIVERY_TIME_MS);
|
|
57
|
+
expect(tag).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
it('tags a delivery completed early as Good', () => {
|
|
60
|
+
const tag = (0, delivery_helpers_1.getDeliveryCompletionTag)(delivery({ updatedAt: at(20) }), DELIVERY_TIME_MS);
|
|
61
|
+
expect(tag).toEqual({ label: 'Good', color: 'success', completionTime: '20m' });
|
|
62
|
+
});
|
|
63
|
+
it('tags a delivery completed within one minute of the ETA as Slight Delay', () => {
|
|
64
|
+
const tag = (0, delivery_helpers_1.getDeliveryCompletionTag)(delivery({ updatedAt: at(25) }), DELIVERY_TIME_MS);
|
|
65
|
+
expect(tag).toEqual({ label: 'Slight Delay', color: 'warning', completionTime: '25m' });
|
|
66
|
+
});
|
|
67
|
+
it('tags a late delivery with the total completion time', () => {
|
|
68
|
+
const tag = (0, delivery_helpers_1.getDeliveryCompletionTag)(delivery({ updatedAt: at(51) }), DELIVERY_TIME_MS);
|
|
69
|
+
expect(tag).toEqual({ label: 'Late', color: 'error', completionTime: '51m' });
|
|
70
|
+
});
|
|
71
|
+
it('reports completion times over an hour as Xh Ym', () => {
|
|
72
|
+
const tag = (0, delivery_helpers_1.getDeliveryCompletionTag)(delivery({ updatedAt: at(65) }), DELIVERY_TIME_MS);
|
|
73
|
+
expect(tag).toEqual({ label: 'Late', color: 'error', completionTime: '1h 5m' });
|
|
74
|
+
});
|
|
75
|
+
it('includes prep minutes in the expected time used for the completion tag', () => {
|
|
76
|
+
// Expected: 10:00 + 20 prep + 2 (1 km) = 10:22; completed 10:25 -> 3 min late.
|
|
77
|
+
const tag = (0, delivery_helpers_1.getDeliveryCompletionTag)(delivery({ distanceInMeters: 1000, updatedAt: at(25) }), null, 20);
|
|
78
|
+
expect(tag).toEqual({ label: 'Late', color: 'error', completionTime: '25m' });
|
|
79
|
+
});
|
|
80
|
+
});
|