@managesome/eposmatic-toolkit 0.4.89 → 0.4.92
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/esm/constants/ENUMS.js +1 -0
- package/esm/constants/enums/storage.js +23 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/order/generate-warehouse-internal-movement.js +3 -0
- package/esm/helpers/storage/index.js +1 -0
- package/esm/helpers/storage/upload-paths.js +384 -0
- package/esm/helpers/store/common-warehouse-internal-movement-actions.js +124 -4
- package/esm/helpers/utils/discount-amounts.js +64 -0
- package/esm/helpers/utils/index.js +2 -0
- package/esm/helpers/utils/internal-movement-items.js +30 -0
- package/esm/helpers/utils/tenant-purchase-order-engine.js +10 -18
- package/esm/helpers/utils/warehouse-purchase-order-engine.js +10 -18
- package/esm/schemas/models/index.js +1 -0
- package/esm/schemas/models/pending_uploads.js +102 -0
- package/esm/schemas/models/warehouse_internal_movements.js +54 -0
- package/esm/schemas/types/index.js +1 -0
- package/esm/schemas/types/pending_uploads.js +1 -0
- package/lib/constants/ENUMS.d.ts +1 -0
- package/lib/constants/ENUMS.js +1 -0
- package/lib/constants/enums/storage.d.ts +21 -0
- package/lib/constants/enums/storage.js +26 -0
- package/lib/helpers/index.d.ts +1 -0
- package/lib/helpers/index.js +1 -0
- package/lib/helpers/order/generate-warehouse-internal-movement.js +3 -0
- package/lib/helpers/storage/index.d.ts +1 -0
- package/lib/helpers/storage/index.js +17 -0
- package/lib/helpers/storage/upload-paths.d.ts +117 -0
- package/lib/helpers/storage/upload-paths.js +394 -0
- package/lib/helpers/store/common-warehouse-internal-movement-actions.d.ts +33 -1
- package/lib/helpers/store/common-warehouse-internal-movement-actions.js +126 -3
- package/lib/helpers/utils/discount-amounts.d.ts +50 -0
- package/lib/helpers/utils/discount-amounts.js +69 -0
- package/lib/helpers/utils/index.d.ts +2 -0
- package/lib/helpers/utils/index.js +2 -0
- package/lib/helpers/utils/internal-movement-items.d.ts +35 -0
- package/lib/helpers/utils/internal-movement-items.js +36 -0
- package/lib/helpers/utils/tenant-purchase-order-engine.js +9 -17
- package/lib/helpers/utils/warehouse-purchase-order-engine.js +9 -17
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/inventories.d.ts +3 -3
- package/lib/schemas/models/inventory_transactions.d.ts +3 -3
- package/lib/schemas/models/item_transactions.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +3 -3
- package/lib/schemas/models/orders.d.ts +120 -120
- package/lib/schemas/models/pending_uploads.d.ts +118 -0
- package/lib/schemas/models/pending_uploads.js +105 -0
- package/lib/schemas/models/tenant_hr_employees.d.ts +3 -3
- package/lib/schemas/models/tenant_inventory_department_transactions.d.ts +3 -3
- package/lib/schemas/models/tenant_inventory_department_utilities.d.ts +3 -3
- package/lib/schemas/models/warehouse_internal_movements.d.ts +570 -0
- package/lib/schemas/models/warehouse_internal_movements.js +54 -0
- package/lib/schemas/models/warehouse_inventory_transactions.d.ts +3 -3
- package/lib/schemas/models/warehouse_item_transactions.d.ts +3 -3
- package/lib/schemas/models/warehouse_items.d.ts +3 -3
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/pending_uploads.d.ts +30 -0
- package/lib/schemas/types/pending_uploads.js +2 -0
- package/lib/schemas/types/warehouse_internal_movements.d.ts +17 -1
- package/lib/tests/pending-uploads-schema.test.d.ts +1 -0
- package/lib/tests/pending-uploads-schema.test.js +79 -0
- package/lib/tests/storage-upload-paths.test.d.ts +1 -0
- package/lib/tests/storage-upload-paths.test.js +198 -0
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
2
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
3
|
+
/**
|
|
4
|
+
* Resolve one line's item discount to a money amount.
|
|
5
|
+
*
|
|
6
|
+
* This is the single source of truth for the rule shared by warehouse POs,
|
|
7
|
+
* tenant POs and internal movements:
|
|
8
|
+
* - a fixed `special_discount` is **per unit**, so it scales with quantity;
|
|
9
|
+
* - a percentage applies to the line's gross value;
|
|
10
|
+
* - `total_discount` is a fallback for records without a special discount;
|
|
11
|
+
* - the result is clamped to `[0, gross]`, so a line can never go negative.
|
|
12
|
+
*
|
|
13
|
+
* The function is deliberately rounding-free: callers decide whether they work
|
|
14
|
+
* in currency decimals (`parseNum`) or warehouse wire units (integer maths).
|
|
15
|
+
* Invalid/NaN/Infinity input resolves to `0` instead of poisoning totals.
|
|
16
|
+
*/
|
|
17
|
+
export function getItemDiscountAmount({ grossAmount, quantity, details }) {
|
|
18
|
+
if (!details)
|
|
19
|
+
return 0;
|
|
20
|
+
const safeGrossAmount = isFiniteNumber(grossAmount) ? Math.max(0, grossAmount) : 0;
|
|
21
|
+
const safeQuantity = isFiniteNumber(quantity) ? Math.max(0, quantity) : 0;
|
|
22
|
+
if (!(safeGrossAmount > 0))
|
|
23
|
+
return 0;
|
|
24
|
+
const value = details.special_discount;
|
|
25
|
+
if (isFiniteNumber(value) && value > 0) {
|
|
26
|
+
const rawAmount = details.is_special_discount_percentage
|
|
27
|
+
? (safeGrossAmount * clamp(value, 0, 100)) / 100
|
|
28
|
+
: value * safeQuantity;
|
|
29
|
+
return clamp(rawAmount, 0, safeGrossAmount);
|
|
30
|
+
}
|
|
31
|
+
const fallback = details.total_discount;
|
|
32
|
+
return isFiniteNumber(fallback) ? clamp(fallback, 0, safeGrossAmount) : 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve an order-level discount to a money amount.
|
|
36
|
+
*
|
|
37
|
+
* Same value rules as `getItemDiscountAmount` (except a fixed amount is a
|
|
38
|
+
* one-off order amount, not per unit). The result is clamped to the subtotal.
|
|
39
|
+
* Rounding is left to the caller.
|
|
40
|
+
*/
|
|
41
|
+
export function getOrderDiscountAmount({ baseAmount, details }) {
|
|
42
|
+
if (!details)
|
|
43
|
+
return 0;
|
|
44
|
+
const base = isFiniteNumber(baseAmount) ? Math.max(0, baseAmount) : 0;
|
|
45
|
+
if (!(base > 0))
|
|
46
|
+
return 0;
|
|
47
|
+
const value = details.special_discount;
|
|
48
|
+
if (isFiniteNumber(value) && value > 0) {
|
|
49
|
+
const rawAmount = details.is_special_discount_percentage ? (base * clamp(value, 0, 100)) / 100 : value;
|
|
50
|
+
return clamp(rawAmount, 0, base);
|
|
51
|
+
}
|
|
52
|
+
const fallback = details.total_discount;
|
|
53
|
+
return isFiniteNumber(fallback) ? clamp(fallback, 0, base) : 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Return a copy of a discount record with its resolved money value refreshed.
|
|
57
|
+
* Preserves every other field (id, name, reason, reference).
|
|
58
|
+
*/
|
|
59
|
+
export function withDiscountTotal(details, totalDiscount) {
|
|
60
|
+
return {
|
|
61
|
+
...details,
|
|
62
|
+
total_discount: totalDiscount,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -26,6 +26,7 @@ export * from './image-helpers';
|
|
|
26
26
|
export * from './image-url-helpers';
|
|
27
27
|
export * from './ingredients';
|
|
28
28
|
export * from './internal-amount-helpers';
|
|
29
|
+
export * from './internal-movement-items';
|
|
29
30
|
export * from './inventory';
|
|
30
31
|
export * from './inventory_entries';
|
|
31
32
|
export * from './inventory_transactions';
|
|
@@ -33,6 +34,7 @@ export * from './item-report-helpers';
|
|
|
33
34
|
export * from './items-comparison-report-helpers';
|
|
34
35
|
export * from './kds-helpers';
|
|
35
36
|
export * from './location-helpers';
|
|
37
|
+
export * from './discount-amounts';
|
|
36
38
|
export * from './menu-helpers';
|
|
37
39
|
export * from './minified-catalog';
|
|
38
40
|
export * from './offer-apply-helpers';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import ObjectID from 'bson-objectid';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a cart line to the document line shape.
|
|
4
|
+
*
|
|
5
|
+
* This is the single mapper used by cart summaries and by both submit flows, so
|
|
6
|
+
* a field the pricing engine reads (notably `item_discount_details`) cannot be
|
|
7
|
+
* dropped in one place and kept in another.
|
|
8
|
+
*
|
|
9
|
+
* `item_discount_details` is always present (`null` when absent): a full
|
|
10
|
+
* document edit must be able to clear a discount by sending an explicit null.
|
|
11
|
+
* Partial updates that omit the field are handled separately by the backend.
|
|
12
|
+
*/
|
|
13
|
+
export function buildInternalMovementItem(line, options) {
|
|
14
|
+
const parsedQuantity = Number(line.quantity);
|
|
15
|
+
const quantity = Number.isFinite(parsedQuantity) ? Math.max(0, parsedQuantity) : 0;
|
|
16
|
+
const parsedUnitPrice = line.unit_price != null ? Number(line.unit_price) : undefined;
|
|
17
|
+
const unitPrice = parsedUnitPrice != null && Number.isFinite(parsedUnitPrice) ? parsedUnitPrice : undefined;
|
|
18
|
+
const notes = line.notes?.trim();
|
|
19
|
+
return {
|
|
20
|
+
_id: line._id?.trim() || ObjectID().toHexString(),
|
|
21
|
+
item_id: line.item_id,
|
|
22
|
+
inventory_code: line.inventory_code?.trim() || options?.inventoryCodeFallback?.trim() || line.item_id,
|
|
23
|
+
item_name: line.name,
|
|
24
|
+
quantity,
|
|
25
|
+
received_qty: 0,
|
|
26
|
+
...(unitPrice != null ? { unit_price: unitPrice } : {}),
|
|
27
|
+
item_discount_details: line.item_discount_details ?? null,
|
|
28
|
+
...(notes ? { notes } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseNum } from './common';
|
|
2
|
+
import { getItemDiscountAmount, withDiscountTotal } from './discount-amounts';
|
|
2
3
|
// ==========================================================><====================================================
|
|
3
4
|
/**
|
|
4
5
|
* Total item-level discount for a tenant purchase order line, in money.
|
|
@@ -16,19 +17,13 @@ import { getPercentageAmount, parseNum } from './common';
|
|
|
16
17
|
* a line negative.
|
|
17
18
|
*/
|
|
18
19
|
export function getTenantPurchaseOrderItemDiscountAmount(orderItem) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return parseNum(Math.max(0, Math.min(grossAmount, details.total_discount ?? 0)));
|
|
27
|
-
}
|
|
28
|
-
const discountAmount = details.is_special_discount_percentage
|
|
29
|
-
? getPercentageAmount(grossAmount, value)
|
|
30
|
-
: value * quantity;
|
|
31
|
-
return parseNum(Math.min(grossAmount, Math.max(0, discountAmount)));
|
|
20
|
+
// Shared rule with warehouse POs and internal movements; this wrapper keeps
|
|
21
|
+
// the tenant PO's currency-decimal rounding.
|
|
22
|
+
return parseNum(getItemDiscountAmount({
|
|
23
|
+
grossAmount: parseNum((orderItem.price ?? 0) * (orderItem.quantity ?? 0)),
|
|
24
|
+
quantity: orderItem.quantity,
|
|
25
|
+
details: orderItem.item_discount_details,
|
|
26
|
+
}));
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
29
|
* Refreshes `total_discount` on a line's discount record so the amount it
|
|
@@ -40,8 +35,5 @@ export function withResolvedTenantItemDiscountTotal(orderItem) {
|
|
|
40
35
|
const details = orderItem.item_discount_details;
|
|
41
36
|
if (!details)
|
|
42
37
|
return null;
|
|
43
|
-
return
|
|
44
|
-
...details,
|
|
45
|
-
total_discount: getTenantPurchaseOrderItemDiscountAmount(orderItem),
|
|
46
|
-
};
|
|
38
|
+
return withDiscountTotal(details, getTenantPurchaseOrderItemDiscountAmount(orderItem));
|
|
47
39
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ObjectID from 'bson-objectid';
|
|
2
|
-
import {
|
|
2
|
+
import { parseNum } from './common';
|
|
3
|
+
import { getItemDiscountAmount, withDiscountTotal } from './discount-amounts';
|
|
3
4
|
// ==========================================================><====================================================
|
|
4
5
|
/**
|
|
5
6
|
* Total item-level discount for a purchase order line, in money.
|
|
@@ -16,19 +17,13 @@ import { getPercentageAmount, parseNum } from './common';
|
|
|
16
17
|
* line negative.
|
|
17
18
|
*/
|
|
18
19
|
export function getWarehousePurchaseOrderItemDiscountAmount(orderItem) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return parseNum(Math.max(0, Math.min(grossAmount, details.total_discount ?? 0)));
|
|
27
|
-
}
|
|
28
|
-
const discountAmount = details.is_special_discount_percentage
|
|
29
|
-
? getPercentageAmount(grossAmount, value)
|
|
30
|
-
: value * quantity;
|
|
31
|
-
return parseNum(Math.min(grossAmount, Math.max(0, discountAmount)));
|
|
20
|
+
// Shared rule with tenant POs and internal movements; this wrapper keeps the
|
|
21
|
+
// warehouse PO's currency-decimal rounding.
|
|
22
|
+
return parseNum(getItemDiscountAmount({
|
|
23
|
+
grossAmount: parseNum((orderItem.price ?? 0) * (orderItem.quantity ?? 0)),
|
|
24
|
+
quantity: orderItem.quantity,
|
|
25
|
+
details: orderItem.item_discount_details,
|
|
26
|
+
}));
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
29
|
* Refreshes `total_discount` on a line's discount record so the amount it
|
|
@@ -40,10 +35,7 @@ export function withResolvedWarehouseItemDiscountTotal(orderItem) {
|
|
|
40
35
|
const details = orderItem.item_discount_details;
|
|
41
36
|
if (!details)
|
|
42
37
|
return null;
|
|
43
|
-
return
|
|
44
|
-
...details,
|
|
45
|
-
total_discount: getWarehousePurchaseOrderItemDiscountAmount(orderItem),
|
|
46
|
-
};
|
|
38
|
+
return withDiscountTotal(details, getWarehousePurchaseOrderItemDiscountAmount(orderItem));
|
|
47
39
|
}
|
|
48
40
|
export function convertWarehouseItemToPurchaseOrderItem({ vendorId, item, orderItem, }) {
|
|
49
41
|
const { _id = ObjectID().toHexString(), price = item.purchase_price?.[vendorId] ?? item.purchase_price?.BASE_PRICE ?? 0, quantity = 1, special_instructions = '', is_ready, } = orderItem ?? {};
|
|
@@ -61,6 +61,7 @@ export * from './offers';
|
|
|
61
61
|
export * from './offers_fingerprints';
|
|
62
62
|
export * from './operational_roles';
|
|
63
63
|
export * from './orders';
|
|
64
|
+
export * from './pending_uploads';
|
|
64
65
|
export * from './printer_settings';
|
|
65
66
|
export * from './public_holidays';
|
|
66
67
|
export * from './reservations';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { ALL_PENDING_UPLOAD_REF_TYPES, ALL_PENDING_UPLOAD_STAGES } from '../../constants/enums/storage';
|
|
3
|
+
import { STORAGE_UPLOAD_KIND } from '../../helpers/storage/upload-paths';
|
|
4
|
+
export const PENDING_UPLOADS_COLLECTION_NAME = 'pending_uploads';
|
|
5
|
+
/**
|
|
6
|
+
* Ledger for server-signed uploads.
|
|
7
|
+
*
|
|
8
|
+
* Standard collection timestamps: `createdAt` / `updatedAt` (timestamps: true).
|
|
9
|
+
* The TTL index is the audit boundary: rows are retained for 30 days after
|
|
10
|
+
* creation, then removed. A discarded or committed row is kept until then so
|
|
11
|
+
* a late discard/confirm can still answer deterministically.
|
|
12
|
+
*
|
|
13
|
+
* A repeated `/sign` for the same deterministic path supersedes the row with
|
|
14
|
+
* `findOneAndReplace`, so the standard timestamps and lifecycle fields restart
|
|
15
|
+
* for the new attempt.
|
|
16
|
+
*/
|
|
17
|
+
export const PendingUploadSchema = new Schema({
|
|
18
|
+
path: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
immutable: true,
|
|
22
|
+
},
|
|
23
|
+
uid: {
|
|
24
|
+
type: String,
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
kind: {
|
|
28
|
+
type: String,
|
|
29
|
+
required: true,
|
|
30
|
+
enum: Object.values(STORAGE_UPLOAD_KIND),
|
|
31
|
+
},
|
|
32
|
+
ref_type: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true,
|
|
35
|
+
enum: ALL_PENDING_UPLOAD_REF_TYPES,
|
|
36
|
+
},
|
|
37
|
+
ref_id: {
|
|
38
|
+
type: String,
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
stage: {
|
|
42
|
+
type: String,
|
|
43
|
+
enum: ALL_PENDING_UPLOAD_STAGES,
|
|
44
|
+
},
|
|
45
|
+
mime: { type: String, required: true },
|
|
46
|
+
max_bytes: { type: Number, required: true },
|
|
47
|
+
uploaded_at: { type: Date, default: null },
|
|
48
|
+
committed_at: { type: Date, default: null },
|
|
49
|
+
discarded_at: { type: Date, default: null },
|
|
50
|
+
expires_at: { type: Date, required: true },
|
|
51
|
+
size: { type: Number, default: null },
|
|
52
|
+
content_type: { type: String, default: null },
|
|
53
|
+
generation: { type: String, default: null },
|
|
54
|
+
createdAt: {
|
|
55
|
+
type: Date,
|
|
56
|
+
required: true,
|
|
57
|
+
immutable: true,
|
|
58
|
+
default: () => new Date(),
|
|
59
|
+
},
|
|
60
|
+
updatedAt: {
|
|
61
|
+
type: Date,
|
|
62
|
+
required: true,
|
|
63
|
+
default: () => new Date(),
|
|
64
|
+
},
|
|
65
|
+
}, {
|
|
66
|
+
collection: PENDING_UPLOADS_COLLECTION_NAME,
|
|
67
|
+
timestamps: true,
|
|
68
|
+
versionKey: false,
|
|
69
|
+
minimize: false,
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* Describes the indexes for `pending_uploads`. Values are Mongo key patterns
|
|
73
|
+
* that can be passed to `.hint()`; creation must use
|
|
74
|
+
* `PENDING_UPLOADS_INDEX_OPTIONS`.
|
|
75
|
+
*/
|
|
76
|
+
export const PENDING_UPLOADS_COLLECTION_INDEXES = {
|
|
77
|
+
_id: { _id: 1 }, // Unique Index
|
|
78
|
+
path: { path: 1 }, // unique server-built upload path
|
|
79
|
+
uid__createdAt: { uid: 1, createdAt: -1 }, // per-user upload history
|
|
80
|
+
expires_at: { expires_at: 1 }, // TTL audit cleanup
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Index OPTIONS the owner must CREATE. This is declared in the toolkit and
|
|
84
|
+
* applied by a separate migration/deploy step; it is never created by a read
|
|
85
|
+
* at runtime (services connect with `autoIndex: false`).
|
|
86
|
+
*/
|
|
87
|
+
export const PENDING_UPLOADS_INDEX_OPTIONS = [
|
|
88
|
+
{
|
|
89
|
+
key: { path: 1 },
|
|
90
|
+
name: 'path',
|
|
91
|
+
unique: true,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: { uid: 1, createdAt: -1 },
|
|
95
|
+
name: 'uid__createdAt',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
key: { expires_at: 1 },
|
|
99
|
+
name: 'expires_at_ttl',
|
|
100
|
+
expireAfterSeconds: 0,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
@@ -16,6 +16,30 @@ const WarehouseInternalMovementActorSchema = new Schema({
|
|
|
16
16
|
_id: false,
|
|
17
17
|
minimize: false,
|
|
18
18
|
});
|
|
19
|
+
const WarehouseInternalMovementDiscountDetailsSchema = new Schema({
|
|
20
|
+
special_discount: {
|
|
21
|
+
type: Number,
|
|
22
|
+
},
|
|
23
|
+
special_discount_id: {
|
|
24
|
+
type: String,
|
|
25
|
+
},
|
|
26
|
+
special_discount_name: {
|
|
27
|
+
type: String,
|
|
28
|
+
},
|
|
29
|
+
is_special_discount_percentage: {
|
|
30
|
+
type: Boolean,
|
|
31
|
+
},
|
|
32
|
+
special_discount_reason: {
|
|
33
|
+
type: String,
|
|
34
|
+
},
|
|
35
|
+
special_reference_number: {
|
|
36
|
+
type: String,
|
|
37
|
+
},
|
|
38
|
+
total_discount: {
|
|
39
|
+
type: Number,
|
|
40
|
+
required: true,
|
|
41
|
+
},
|
|
42
|
+
}, { _id: false, minimize: false });
|
|
19
43
|
const WarehouseInternalMovementItemSchema = new Schema({
|
|
20
44
|
_id: {
|
|
21
45
|
type: Schema.Types.ObjectId,
|
|
@@ -57,6 +81,10 @@ const WarehouseInternalMovementItemSchema = new Schema({
|
|
|
57
81
|
min: 0,
|
|
58
82
|
required: false,
|
|
59
83
|
},
|
|
84
|
+
item_discount_details: {
|
|
85
|
+
type: WarehouseInternalMovementDiscountDetailsSchema,
|
|
86
|
+
default: null,
|
|
87
|
+
},
|
|
60
88
|
notes: {
|
|
61
89
|
type: String,
|
|
62
90
|
required: false,
|
|
@@ -120,6 +148,19 @@ export const WarehouseInternalMovementIterationSchema = new Schema({
|
|
|
120
148
|
min: 0,
|
|
121
149
|
required: false,
|
|
122
150
|
},
|
|
151
|
+
order_discount_details: {
|
|
152
|
+
type: WarehouseInternalMovementDiscountDetailsSchema,
|
|
153
|
+
required: false,
|
|
154
|
+
},
|
|
155
|
+
total_discount_applied: {
|
|
156
|
+
type: Number,
|
|
157
|
+
min: 0,
|
|
158
|
+
required: false,
|
|
159
|
+
},
|
|
160
|
+
exclude_discount_from_gst: {
|
|
161
|
+
type: Boolean,
|
|
162
|
+
required: false,
|
|
163
|
+
},
|
|
123
164
|
labor_charges: { type: Number, min: 0, required: false },
|
|
124
165
|
labor_charges_amount: { type: Number, min: 0, required: false },
|
|
125
166
|
is_labor_charges_percentage: { type: Boolean, required: false },
|
|
@@ -266,6 +307,19 @@ export const WarehouseInternalMovementsSchema = new Schema({
|
|
|
266
307
|
min: 0,
|
|
267
308
|
required: false,
|
|
268
309
|
},
|
|
310
|
+
order_discount_details: {
|
|
311
|
+
type: WarehouseInternalMovementDiscountDetailsSchema,
|
|
312
|
+
required: false,
|
|
313
|
+
},
|
|
314
|
+
total_discount_applied: {
|
|
315
|
+
type: Number,
|
|
316
|
+
min: 0,
|
|
317
|
+
required: false,
|
|
318
|
+
},
|
|
319
|
+
exclude_discount_from_gst: {
|
|
320
|
+
type: Boolean,
|
|
321
|
+
required: false,
|
|
322
|
+
},
|
|
269
323
|
labor_charges: { type: Number, min: 0, required: false },
|
|
270
324
|
labor_charges_amount: { type: Number, min: 0, required: false },
|
|
271
325
|
is_labor_charges_percentage: { type: Boolean, required: false },
|
|
@@ -66,6 +66,7 @@ export * from './offers';
|
|
|
66
66
|
export * from './offers_fingerprints';
|
|
67
67
|
export * from './operational_roles';
|
|
68
68
|
export * from './orders';
|
|
69
|
+
export * from './pending_uploads';
|
|
69
70
|
export * from './printer_settings';
|
|
70
71
|
export * from './public_holidays';
|
|
71
72
|
export * from './reservations';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/constants/ENUMS.d.ts
CHANGED
package/lib/constants/ENUMS.js
CHANGED
|
@@ -31,5 +31,6 @@ __exportStar(require("./enums/order"), exports);
|
|
|
31
31
|
__exportStar(require("./enums/payments"), exports);
|
|
32
32
|
__exportStar(require("./enums/platform"), exports);
|
|
33
33
|
__exportStar(require("./enums/printing"), exports);
|
|
34
|
+
__exportStar(require("./enums/storage"), exports);
|
|
34
35
|
__exportStar(require("./enums/users"), exports);
|
|
35
36
|
__exportStar(require("./enums/wallet"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum PENDING_UPLOAD_REF_TYPE_ENUM {
|
|
2
|
+
TENANT = "TENANT",
|
|
3
|
+
BRAND = "BRAND",
|
|
4
|
+
WAREHOUSE = "WAREHOUSE",
|
|
5
|
+
EMPLOYEE = "EMPLOYEE",
|
|
6
|
+
DELIVERY = "DELIVERY",
|
|
7
|
+
RIDER = "RIDER",
|
|
8
|
+
RESTAURANT = "RESTAURANT",
|
|
9
|
+
EXPENSE = "EXPENSE"
|
|
10
|
+
}
|
|
11
|
+
export declare const ALL_PENDING_UPLOAD_REF_TYPES: PENDING_UPLOAD_REF_TYPE_ENUM[];
|
|
12
|
+
/**
|
|
13
|
+
* Delivery proof stage. Enum values are upper-case by enum convention;
|
|
14
|
+
* the path builder lower-cases them into the storage leaf
|
|
15
|
+
* (`pickup_food_image_url.<ext>` / `dropoff_food_image_url.<ext>`).
|
|
16
|
+
*/
|
|
17
|
+
export declare enum PENDING_UPLOAD_STAGE_ENUM {
|
|
18
|
+
PICKUP = "PICKUP",
|
|
19
|
+
DROPOFF = "DROPOFF"
|
|
20
|
+
}
|
|
21
|
+
export declare const ALL_PENDING_UPLOAD_STAGES: PENDING_UPLOAD_STAGE_ENUM[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALL_PENDING_UPLOAD_STAGES = exports.PENDING_UPLOAD_STAGE_ENUM = exports.ALL_PENDING_UPLOAD_REF_TYPES = exports.PENDING_UPLOAD_REF_TYPE_ENUM = void 0;
|
|
4
|
+
var PENDING_UPLOAD_REF_TYPE_ENUM;
|
|
5
|
+
(function (PENDING_UPLOAD_REF_TYPE_ENUM) {
|
|
6
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["TENANT"] = "TENANT";
|
|
7
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["BRAND"] = "BRAND";
|
|
8
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["WAREHOUSE"] = "WAREHOUSE";
|
|
9
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["EMPLOYEE"] = "EMPLOYEE";
|
|
10
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["DELIVERY"] = "DELIVERY";
|
|
11
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["RIDER"] = "RIDER";
|
|
12
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["RESTAURANT"] = "RESTAURANT";
|
|
13
|
+
PENDING_UPLOAD_REF_TYPE_ENUM["EXPENSE"] = "EXPENSE";
|
|
14
|
+
})(PENDING_UPLOAD_REF_TYPE_ENUM || (exports.PENDING_UPLOAD_REF_TYPE_ENUM = PENDING_UPLOAD_REF_TYPE_ENUM = {}));
|
|
15
|
+
exports.ALL_PENDING_UPLOAD_REF_TYPES = Object.values(PENDING_UPLOAD_REF_TYPE_ENUM);
|
|
16
|
+
/**
|
|
17
|
+
* Delivery proof stage. Enum values are upper-case by enum convention;
|
|
18
|
+
* the path builder lower-cases them into the storage leaf
|
|
19
|
+
* (`pickup_food_image_url.<ext>` / `dropoff_food_image_url.<ext>`).
|
|
20
|
+
*/
|
|
21
|
+
var PENDING_UPLOAD_STAGE_ENUM;
|
|
22
|
+
(function (PENDING_UPLOAD_STAGE_ENUM) {
|
|
23
|
+
PENDING_UPLOAD_STAGE_ENUM["PICKUP"] = "PICKUP";
|
|
24
|
+
PENDING_UPLOAD_STAGE_ENUM["DROPOFF"] = "DROPOFF";
|
|
25
|
+
})(PENDING_UPLOAD_STAGE_ENUM || (exports.PENDING_UPLOAD_STAGE_ENUM = PENDING_UPLOAD_STAGE_ENUM = {}));
|
|
26
|
+
exports.ALL_PENDING_UPLOAD_STAGES = Object.values(PENDING_UPLOAD_STAGE_ENUM);
|
package/lib/helpers/index.d.ts
CHANGED
package/lib/helpers/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./rider-reports"), exports);
|
|
|
24
24
|
__exportStar(require("./order"), exports);
|
|
25
25
|
__exportStar(require("./pra"), exports);
|
|
26
26
|
__exportStar(require("./srb"), exports);
|
|
27
|
+
__exportStar(require("./storage"), exports);
|
|
27
28
|
__exportStar(require("./store"), exports);
|
|
28
29
|
__exportStar(require("./types"), exports);
|
|
29
30
|
__exportStar(require("./utils"), exports);
|
|
@@ -24,6 +24,9 @@ function generateWarehouseInternalMovementIteration(movement, partial = true) {
|
|
|
24
24
|
is_gst_inclusive: movement.is_gst_inclusive,
|
|
25
25
|
gst: movement.gst,
|
|
26
26
|
gst_amount: movement.gst_amount,
|
|
27
|
+
order_discount_details: movement.order_discount_details,
|
|
28
|
+
total_discount_applied: movement.total_discount_applied,
|
|
29
|
+
exclude_discount_from_gst: movement.exclude_discount_from_gst,
|
|
27
30
|
labor_charges: movement.labor_charges,
|
|
28
31
|
labor_charges_amount: movement.labor_charges_amount,
|
|
29
32
|
is_labor_charges_percentage: movement.is_labor_charges_percentage,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './upload-paths';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./upload-paths"), exports);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-owned Cloud Storage upload path registry.
|
|
3
|
+
*
|
|
4
|
+
* The client sends a `kind` plus entity ids and file metadata. This module is
|
|
5
|
+
* the only place that turns those inputs into a bucket-relative object path.
|
|
6
|
+
* Nothing here performs I/O, so both backend services can import it and the
|
|
7
|
+
* toolkit build stays usable in browser contexts.
|
|
8
|
+
*
|
|
9
|
+
* Security invariants:
|
|
10
|
+
* - every kind is in a closed registry;
|
|
11
|
+
* - every client-supplied id is a single, validated path segment;
|
|
12
|
+
* - only `images/` and `documents/` roots are reachable;
|
|
13
|
+
* - the final path is re-validated after construction.
|
|
14
|
+
*/
|
|
15
|
+
import { PENDING_UPLOAD_REF_TYPE_ENUM, PENDING_UPLOAD_STAGE_ENUM } from '../../constants/enums/storage';
|
|
16
|
+
export declare const IMAGE_MAX_BYTES: number;
|
|
17
|
+
export declare const DOCUMENT_MAX_BYTES: number;
|
|
18
|
+
export declare const IMAGE_MIME_EXTENSIONS: Record<string, string>;
|
|
19
|
+
export declare const DOCUMENT_MIME_EXTENSIONS: Record<string, readonly string[]>;
|
|
20
|
+
export declare const STORAGE_UPLOAD_KIND: {
|
|
21
|
+
readonly BRAND_CATEGORY_BANNER: "brand.category_banner";
|
|
22
|
+
readonly BRAND_CATEGORY_IMAGE: "brand.category";
|
|
23
|
+
readonly BRAND_HALF_HALF_IMAGE: "brand.halfhalf";
|
|
24
|
+
readonly BRAND_IMAGE: "brand.image";
|
|
25
|
+
readonly BRAND_ITEM_IMAGE: "brand.item";
|
|
26
|
+
readonly BRAND_OFFER_IMAGE: "brand.offer";
|
|
27
|
+
readonly BRAND_SPECIAL_IMAGE: "brand.special";
|
|
28
|
+
readonly BRAND_WAREHOUSE_CATEGORY_IMAGE: "brand.warehouse.category";
|
|
29
|
+
readonly BRAND_WAREHOUSE_ITEM_IMAGE: "brand.warehouse.item";
|
|
30
|
+
readonly DELIVERY_PROOF: "delivery.proof";
|
|
31
|
+
readonly DOCUMENT_HR: "document.hr";
|
|
32
|
+
readonly DOCUMENT_POLICY: "document.policy";
|
|
33
|
+
readonly INTERNAL_EXPENSE_IMAGE: "internal.expense";
|
|
34
|
+
readonly INTERNAL_RESTAURANT_IMAGE: "internal.restaurant";
|
|
35
|
+
readonly RIDER_IMAGE: "rider.image";
|
|
36
|
+
readonly TENANT_DEPARTMENT_IMAGE: "tenant.department";
|
|
37
|
+
readonly TENANT_DIGITAL_MENU: "tenant.digital_menu";
|
|
38
|
+
readonly TENANT_EXPENSE_IMAGE: "tenant.expense";
|
|
39
|
+
readonly TENANT_IMAGE: "tenant.image";
|
|
40
|
+
readonly TENANT_INVENTORY_IMAGE: "tenant.inventory";
|
|
41
|
+
readonly TENANT_MARKETING_IMAGE: "tenant.marketing";
|
|
42
|
+
readonly TENANT_SLIDER: "tenant.slider";
|
|
43
|
+
readonly TENANT_STAFF_IMAGE: "tenant.staff";
|
|
44
|
+
readonly TENANT_WEB_COVER: "tenant.web_cover";
|
|
45
|
+
readonly TENANT_WEB_FAVICON: "tenant.web_favicon";
|
|
46
|
+
readonly WAREHOUSE_EXPENSE_IMAGE: "warehouse.expense";
|
|
47
|
+
readonly WAREHOUSE_IMAGE: "warehouse.image";
|
|
48
|
+
readonly WAREHOUSE_INVENTORY_IMAGE: "warehouse.inventory";
|
|
49
|
+
readonly WAREHOUSE_STAFF_IMAGE: "warehouse.staff";
|
|
50
|
+
};
|
|
51
|
+
export type TStorageUploadKind = (typeof STORAGE_UPLOAD_KIND)[keyof typeof STORAGE_UPLOAD_KIND];
|
|
52
|
+
export type TStorageUploadRoute = 'items' | 'operations' | 'riders';
|
|
53
|
+
export type TStorageUploadOwner = 'tenant' | 'brand' | 'warehouse' | 'document' | 'internal' | 'rider' | 'delivery';
|
|
54
|
+
export type TStorageUploadIdentity = 'tenant_staff' | 'tenant_staff_hr' | 'warehouse_staff' | 'internal' | 'rider' | 'delivery_rider';
|
|
55
|
+
export type TStorageUploadMedia = 'image' | 'document';
|
|
56
|
+
export type TStorageUploadExtension = 'mime' | 'filename';
|
|
57
|
+
export type TStorageUploadLeaf = 'fixed' | 'record' | 'uuid';
|
|
58
|
+
export type TStorageUploadStage = PENDING_UPLOAD_STAGE_ENUM;
|
|
59
|
+
export type TStorageUploadIdField = 'brand_id' | 'tenant_id' | 'warehouse_id' | 'employee_id' | 'delivery_id' | 'record_id' | 'resource_id';
|
|
60
|
+
export interface IStorageUploadIds {
|
|
61
|
+
brand_id?: string;
|
|
62
|
+
tenant_id?: string;
|
|
63
|
+
warehouse_id?: string;
|
|
64
|
+
employee_id?: string;
|
|
65
|
+
delivery_id?: string;
|
|
66
|
+
record_id?: string;
|
|
67
|
+
resource_id?: string;
|
|
68
|
+
stage?: TStorageUploadStage;
|
|
69
|
+
}
|
|
70
|
+
export interface IStorageUploadDefinition {
|
|
71
|
+
kind: TStorageUploadKind;
|
|
72
|
+
routes: readonly TStorageUploadRoute[];
|
|
73
|
+
owner: TStorageUploadOwner;
|
|
74
|
+
identities: readonly TStorageUploadIdentity[];
|
|
75
|
+
media: TStorageUploadMedia;
|
|
76
|
+
maxBytes: number;
|
|
77
|
+
extension: TStorageUploadExtension;
|
|
78
|
+
leaf: TStorageUploadLeaf;
|
|
79
|
+
baseName?: (ids: IStorageUploadIds) => string;
|
|
80
|
+
requiredIds: readonly TStorageUploadIdField[];
|
|
81
|
+
requiredStage?: boolean;
|
|
82
|
+
requiresUid?: boolean;
|
|
83
|
+
build: (ids: IStorageUploadIds, fileName: string, uid: string) => string;
|
|
84
|
+
}
|
|
85
|
+
export interface IBuildStorageUploadPathInput {
|
|
86
|
+
kind: TStorageUploadKind;
|
|
87
|
+
ids: IStorageUploadIds;
|
|
88
|
+
mime: string;
|
|
89
|
+
filename?: string;
|
|
90
|
+
uuid?: string;
|
|
91
|
+
uid?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface IBuildStorageUploadPathResult {
|
|
94
|
+
path: string;
|
|
95
|
+
extension: string;
|
|
96
|
+
maxBytes: number;
|
|
97
|
+
contentType: string;
|
|
98
|
+
refType: PENDING_UPLOAD_REF_TYPE_ENUM;
|
|
99
|
+
refId: string;
|
|
100
|
+
}
|
|
101
|
+
export type TStorageUploadValidationCode = 'INVALID_KIND' | 'INVALID_ID' | 'INVALID_MIME' | 'INVALID_FILENAME' | 'INVALID_UUID' | 'INVALID_STAGE' | 'INVALID_PATH' | 'MISSING_FIELD';
|
|
102
|
+
export declare class StorageUploadValidationError extends Error {
|
|
103
|
+
readonly code: TStorageUploadValidationCode;
|
|
104
|
+
constructor(code: TStorageUploadValidationCode, message: string);
|
|
105
|
+
}
|
|
106
|
+
export declare function normalizeStorageMime(mime: string): string;
|
|
107
|
+
export declare function isStorageUploadKind(value: unknown): value is TStorageUploadKind;
|
|
108
|
+
export declare function getStorageUploadDefinition(kind: TStorageUploadKind): IStorageUploadDefinition;
|
|
109
|
+
export declare function getStorageUploadKinds(): readonly TStorageUploadKind[];
|
|
110
|
+
export declare function getStorageUploadKindsForRoute(route: TStorageUploadRoute): readonly TStorageUploadKind[];
|
|
111
|
+
/**
|
|
112
|
+
* Builds the bucket-relative object path for a validated upload request.
|
|
113
|
+
*
|
|
114
|
+
* Throws `StorageUploadValidationError` for every caller error. The route
|
|
115
|
+
* should map that error to HTTP 400 (or 415 for an unsupported MIME).
|
|
116
|
+
*/
|
|
117
|
+
export declare function buildStorageUploadPath(input: IBuildStorageUploadPathInput): IBuildStorageUploadPathResult;
|