@shopfront/bridge 2.0.0 → 2.0.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/.idea/codeStyles/Project.xml +10 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/git_toolbox_blame.xml +6 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.idea/inspectionProfiles/Project_Default.xml +5 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/.idea/php.xml +15 -0
- package/lib/APIs/Database/BaseDatabase.d.ts +28 -0
- package/lib/APIs/Database/BaseDatabase.js +5 -0
- package/lib/APIs/Database/Database.d.ts +19 -7
- package/lib/APIs/Database/Database.js +22 -12
- package/lib/APIs/Database/types/BaseBarcodeTemplateRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseBarcodeTemplateRepository.js +1 -0
- package/lib/APIs/Database/types/BaseClassificationRepository.d.ts +11 -0
- package/lib/APIs/Database/types/BaseClassificationRepository.js +1 -0
- package/lib/APIs/Database/types/BaseCustomerDisplayRepository.d.ts +10 -0
- package/lib/APIs/Database/types/BaseCustomerDisplayRepository.js +1 -0
- package/lib/APIs/Database/types/BaseCustomerGroupRepository.d.ts +24 -0
- package/lib/APIs/Database/types/BaseCustomerGroupRepository.js +1 -0
- package/lib/APIs/Database/types/BaseCustomerRepository.d.ts +76 -0
- package/lib/APIs/Database/types/BaseCustomerRepository.js +1 -0
- package/lib/APIs/Database/types/BaseEnterpriseRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseEnterpriseRepository.js +1 -0
- package/lib/APIs/Database/types/BaseGiftCardRepository.d.ts +18 -0
- package/lib/APIs/Database/types/BaseGiftCardRepository.js +1 -0
- package/lib/APIs/Database/types/BaseKitchenOrderRepository.d.ts +41 -0
- package/lib/APIs/Database/types/BaseKitchenOrderRepository.js +1 -0
- package/lib/APIs/Database/types/BaseKitchenScreenRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseKitchenScreenRepository.js +1 -0
- package/lib/APIs/Database/types/BaseLockedResourceRepository.d.ts +12 -0
- package/lib/APIs/Database/types/BaseLockedResourceRepository.js +1 -0
- package/lib/APIs/Database/types/BaseLoyaltyRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseLoyaltyRepository.js +1 -0
- package/lib/APIs/Database/types/BaseMovementRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseMovementRepository.js +1 -0
- package/lib/APIs/Database/types/BaseOutletRepository.d.ts +19 -0
- package/lib/APIs/Database/types/BaseOutletRepository.js +1 -0
- package/lib/APIs/Database/types/BasePaymentMethodRepository.d.ts +27 -0
- package/lib/APIs/Database/types/BasePaymentMethodRepository.js +1 -0
- package/lib/APIs/Database/types/BasePriceListRepository.d.ts +40 -0
- package/lib/APIs/Database/types/BasePriceListRepository.js +1 -0
- package/lib/APIs/Database/types/BasePriceSetRepository.d.ts +6 -0
- package/lib/APIs/Database/types/BasePriceSetRepository.js +1 -0
- package/lib/APIs/Database/types/BaseProductRepository.d.ts +160 -0
- package/lib/APIs/Database/types/BaseProductRepository.js +1 -0
- package/lib/APIs/Database/types/BasePromotionCategoryRepository.d.ts +10 -0
- package/lib/APIs/Database/types/BasePromotionCategoryRepository.js +1 -0
- package/lib/APIs/Database/types/BasePromotionRepository.d.ts +72 -0
- package/lib/APIs/Database/types/BasePromotionRepository.js +1 -0
- package/lib/APIs/Database/types/BaseReceiptRepository.d.ts +31 -0
- package/lib/APIs/Database/types/BaseReceiptRepository.js +1 -0
- package/lib/APIs/Database/types/BaseRegisterRepository.d.ts +56 -0
- package/lib/APIs/Database/types/BaseRegisterRepository.js +1 -0
- package/lib/APIs/Database/types/BaseRepository.d.ts +41 -0
- package/lib/APIs/Database/types/BaseRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSalesKeyRepository.d.ts +37 -0
- package/lib/APIs/Database/types/BaseSalesKeyRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSalesRepository.d.ts +123 -0
- package/lib/APIs/Database/types/BaseSalesRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSearchableRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseSearchableRepository.js +1 -0
- package/lib/APIs/Database/types/BaseStocktakeAccumulatedRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseStocktakeAccumulatedRepository.js +1 -0
- package/lib/APIs/Database/types/BaseStocktakeRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseStocktakeRepository.js +1 -0
- package/lib/APIs/Database/types/BaseStocktakeScannedRepository.d.ts +24 -0
- package/lib/APIs/Database/types/BaseStocktakeScannedRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSupplierRepository.d.ts +35 -0
- package/lib/APIs/Database/types/BaseSupplierRepository.js +1 -0
- package/lib/APIs/Database/types/BaseTakingsRepository.d.ts +13 -0
- package/lib/APIs/Database/types/BaseTakingsRepository.js +1 -0
- package/lib/APIs/Database/types/BaseTaxRateRepository.d.ts +9 -0
- package/lib/APIs/Database/types/BaseTaxRateRepository.js +1 -0
- package/lib/APIs/Database/types/BaseTransfereeRepository.d.ts +12 -0
- package/lib/APIs/Database/types/BaseTransfereeRepository.js +1 -0
- package/lib/APIs/Database/types/BaseVendorConnectionRepository.d.ts +7 -0
- package/lib/APIs/Database/types/BaseVendorConnectionRepository.js +1 -0
- package/lib/APIs/Database/types/DataSourceTables.d.ts +61 -0
- package/lib/APIs/Database/types/DataSourceTables.js +1 -0
- package/lib/APIs/Fulfilment/FulfilmentTypes.d.ts +2 -2
- package/lib/APIs/Fulfilment/FulfilmentTypes.js +1 -2
- package/lib/APIs/InternalMessages/InternalMessageSource.d.ts +6 -3
- package/lib/APIs/InternalMessages/InternalMessageSource.js +6 -7
- package/lib/APIs/Sale/BaseCurrentSale.d.ts +83 -0
- package/lib/APIs/Sale/BaseCurrentSale.js +13 -0
- package/lib/APIs/Sale/BaseSale.d.ts +3 -38
- package/lib/APIs/Sale/BaseSale.js +1 -40
- package/lib/APIs/Sale/CurrentSale.d.ts +19 -84
- package/lib/APIs/Sale/CurrentSale.js +32 -102
- package/lib/APIs/Sale/Exceptions.d.ts +3 -0
- package/lib/APIs/Sale/Exceptions.js +7 -7
- package/lib/APIs/Sale/Sale.d.ts +39 -7
- package/lib/APIs/Sale/Sale.js +41 -13
- package/lib/APIs/Sale/SaleCustomer.d.ts +0 -2
- package/lib/APIs/Sale/SaleCustomer.js +1 -7
- package/lib/APIs/Sale/SalePayment.d.ts +3 -22
- package/lib/APIs/Sale/SalePayment.js +7 -33
- package/lib/APIs/Sale/SaleProduct.d.ts +6 -46
- package/lib/APIs/Sale/SaleProduct.js +6 -53
- package/lib/APIs/Sale/ShopfrontSaleState.d.ts +7 -9
- package/lib/APIs/Sale/ShopfrontSaleState.js +1 -2
- package/lib/APIs/Sale/index.d.ts +9 -9
- package/lib/APIs/Sale/index.js +7 -39
- package/lib/Actions/BaseAction.d.ts +21 -5
- package/lib/Actions/BaseAction.js +155 -97
- package/lib/Actions/Button.d.ts +2 -2
- package/lib/Actions/Button.js +3 -7
- package/lib/Actions/CustomerListOption.d.ts +2 -2
- package/lib/Actions/CustomerListOption.js +2 -6
- package/lib/Actions/Dialog.d.ts +4 -4
- package/lib/Actions/Dialog.js +2 -6
- package/lib/Actions/Redirect.d.ts +2 -2
- package/lib/Actions/Redirect.js +7 -9
- package/lib/Actions/SaleKey.d.ts +2 -2
- package/lib/Actions/SaleKey.js +3 -7
- package/lib/Actions/SaleUpdate.d.ts +3 -3
- package/lib/Actions/SaleUpdate.js +3 -7
- package/lib/Actions/Toast.d.ts +3 -3
- package/lib/Actions/Toast.js +2 -6
- package/lib/Application.d.ts +114 -78
- package/lib/Application.js +207 -160
- package/lib/ApplicationEvents.d.ts +66 -53
- package/lib/ApplicationEvents.js +10 -6
- package/lib/BaseApplication.d.ts +169 -0
- package/lib/BaseApplication.js +40 -0
- package/lib/BaseBridge.d.ts +33 -0
- package/lib/BaseBridge.js +16 -0
- package/lib/Bridge.d.ts +46 -9
- package/lib/Bridge.js +42 -54
- package/lib/Common/EventEmitter.d.ts +10 -1
- package/lib/Common/EventEmitter.js +10 -5
- package/lib/Common/Serializable.d.ts +8 -6
- package/lib/Common/Serializable.js +1 -2
- package/lib/EmitableEvents/BaseEmitableEvent.d.ts +7 -1
- package/lib/EmitableEvents/BaseEmitableEvent.js +7 -5
- package/lib/EmitableEvents/Fulfilment/Options.d.ts +1 -1
- package/lib/EmitableEvents/Fulfilment/Options.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrderCancel.d.ts +1 -1
- package/lib/EmitableEvents/Fulfilment/OrderCancel.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrderCreate.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/OrderCreate.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrderUpdate.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/OrderUpdate.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrdersSync.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/OrdersSync.js +4 -8
- package/lib/EmitableEvents/Fulfilment/RegisterIntent.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/RegisterIntent.js +4 -8
- package/lib/EmitableEvents/Fulfilment/index.d.ts +7 -7
- package/lib/EmitableEvents/Fulfilment/index.js +6 -15
- package/lib/EmitableEvents/InternalMessage.d.ts +2 -2
- package/lib/EmitableEvents/InternalMessage.js +4 -8
- package/lib/EmitableEvents/SellScreenOption.d.ts +2 -2
- package/lib/EmitableEvents/SellScreenOption.js +7 -11
- package/lib/EmitableEvents/SellScreenPromotionApplicable.d.ts +1 -1
- package/lib/EmitableEvents/SellScreenPromotionApplicable.js +4 -8
- package/lib/EmitableEvents/TableUpdate.d.ts +2 -2
- package/lib/EmitableEvents/TableUpdate.js +4 -8
- package/lib/Events/AudioPermissionChange.d.ts +5 -2
- package/lib/Events/AudioPermissionChange.js +6 -7
- package/lib/Events/AudioReady.d.ts +5 -2
- package/lib/Events/AudioReady.js +6 -7
- package/lib/Events/BaseEvent.d.ts +8 -3
- package/lib/Events/BaseEvent.js +1 -6
- package/lib/Events/Callback.d.ts +5 -2
- package/lib/Events/Callback.js +5 -6
- package/lib/Events/FormatIntegratedProduct.d.ts +27 -32
- package/lib/Events/FormatIntegratedProduct.js +12 -9
- package/lib/Events/FulfilmentCollectOrder.d.ts +5 -2
- package/lib/Events/FulfilmentCollectOrder.js +5 -6
- package/lib/Events/FulfilmentCompleteOrder.d.ts +5 -2
- package/lib/Events/FulfilmentCompleteOrder.js +5 -6
- package/lib/Events/FulfilmentGetOrder.d.ts +12 -6
- package/lib/Events/FulfilmentGetOrder.js +10 -8
- package/lib/Events/FulfilmentOrderApproval.d.ts +5 -2
- package/lib/Events/FulfilmentOrderApproval.js +5 -6
- package/lib/Events/FulfilmentProcessOrder.d.ts +12 -10
- package/lib/Events/FulfilmentProcessOrder.js +7 -8
- package/lib/Events/FulfilmentVoidOrder.d.ts +5 -2
- package/lib/Events/FulfilmentVoidOrder.js +5 -6
- package/lib/Events/GiftCardCodeCheck.d.ts +19 -0
- package/lib/Events/GiftCardCodeCheck.js +23 -0
- package/lib/Events/InternalPageMessage.d.ts +10 -4
- package/lib/Events/InternalPageMessage.js +12 -10
- package/lib/Events/PaymentMethodsEnabled.d.ts +16 -11
- package/lib/Events/PaymentMethodsEnabled.js +10 -8
- package/lib/Events/Ready.d.ts +12 -7
- package/lib/Events/Ready.js +5 -6
- package/lib/Events/RegisterChanged.d.ts +12 -6
- package/lib/Events/RegisterChanged.js +6 -7
- package/lib/Events/RequestButtons.d.ts +17 -12
- package/lib/Events/RequestButtons.js +13 -11
- package/lib/Events/RequestCustomerListOptions.d.ts +11 -5
- package/lib/Events/RequestCustomerListOptions.js +12 -11
- package/lib/Events/RequestSaleKeys.d.ts +12 -6
- package/lib/Events/RequestSaleKeys.js +13 -11
- package/lib/Events/RequestSellScreenOptions.d.ts +18 -5
- package/lib/Events/RequestSellScreenOptions.js +17 -9
- package/lib/Events/RequestSettings.d.ts +11 -5
- package/lib/Events/RequestSettings.js +12 -10
- package/lib/Events/RequestTableColumns.d.ts +16 -11
- package/lib/Events/RequestTableColumns.js +12 -9
- package/lib/Events/SaleComplete.d.ts +15 -18
- package/lib/Events/SaleComplete.js +6 -7
- package/lib/Events/UIPipeline.d.ts +17 -5
- package/lib/Events/UIPipeline.js +17 -10
- package/lib/Mocks/APIs/Sale/MockCurrentSale.d.ts +99 -0
- package/lib/Mocks/APIs/Sale/MockCurrentSale.js +326 -0
- package/lib/Mocks/Database/MockDatabase.d.ts +96 -0
- package/lib/Mocks/Database/MockDatabase.js +89 -0
- package/lib/Mocks/MockApplication.d.ts +154 -0
- package/lib/Mocks/MockApplication.js +481 -0
- package/lib/Mocks/MockBridge.d.ts +31 -0
- package/lib/Mocks/MockBridge.js +77 -0
- package/lib/Mocks/index.d.ts +7 -0
- package/lib/Mocks/index.js +15 -0
- package/lib/Utilities/ActionEventRegistrar.d.ts +19 -4
- package/lib/Utilities/ActionEventRegistrar.js +19 -3
- package/lib/Utilities/MiscTypes.d.ts +6 -4
- package/lib/Utilities/MiscTypes.js +1 -2
- package/lib/Utilities/SaleCreate.d.ts +6 -2
- package/lib/Utilities/SaleCreate.js +10 -6
- package/lib/Utilities/Static.d.ts +3 -0
- package/lib/Utilities/Static.js +5 -7
- package/lib/Utilities/UUID.d.ts +9 -3
- package/lib/Utilities/UUID.js +10 -7
- package/lib/index.d.ts +16 -14
- package/lib/index.js +14 -49
- package/package.json +3 -2
- package/lib/APIs/CurrentSale/Exceptions.d.ts +0 -6
- package/lib/APIs/CurrentSale/Exceptions.js +0 -15
- package/lib/APIs/CurrentSale/Sale.d.ts +0 -182
- package/lib/APIs/CurrentSale/Sale.js +0 -290
- package/lib/APIs/CurrentSale/SaleCustomer.d.ts +0 -10
- package/lib/APIs/CurrentSale/SaleCustomer.js +0 -17
- package/lib/APIs/CurrentSale/SalePayment.d.ts +0 -68
- package/lib/APIs/CurrentSale/SalePayment.js +0 -99
- package/lib/APIs/CurrentSale/SaleProduct.d.ts +0 -121
- package/lib/APIs/CurrentSale/SaleProduct.js +0 -167
- package/lib/APIs/CurrentSale/ShopfrontSaleState.d.ts +0 -53
- package/lib/APIs/CurrentSale/ShopfrontSaleState.js +0 -2
- package/lib/APIs/CurrentSale/index.d.ts +0 -6
- package/lib/APIs/CurrentSale/index.js +0 -37
- /package/.idea/{embedded-bridge.iml → shopfront-embedded-bridge.iml} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Bridge } from "../Bridge";
|
|
4
|
-
import { MaybePromise } from "../Utilities/MiscTypes";
|
|
1
|
+
import { FromShopfrontCallbacks, FromShopfrontReturns, UIPipelineBaseContext, UIPipelineContext, UIPipelineResponse } from "../ApplicationEvents.js";
|
|
2
|
+
import { BaseBridge } from "../BaseBridge.js";
|
|
3
|
+
import { Bridge } from "../Bridge.js";
|
|
4
|
+
import { MaybePromise } from "../Utilities/MiscTypes.js";
|
|
5
|
+
import { BaseEvent } from "./BaseEvent.js";
|
|
5
6
|
interface UIPPipelineIncomingData {
|
|
6
7
|
data: Array<UIPipelineResponse>;
|
|
7
8
|
context: UIPipelineBaseContext;
|
|
@@ -9,7 +10,18 @@ interface UIPPipelineIncomingData {
|
|
|
9
10
|
}
|
|
10
11
|
export declare class UIPipeline extends BaseEvent<UIPPipelineIncomingData, MaybePromise<FromShopfrontReturns["UI_PIPELINE"]>, FromShopfrontReturns["UI_PIPELINE"], Array<UIPipelineResponse>, UIPipelineContext> {
|
|
11
12
|
constructor(callback: FromShopfrontCallbacks["UI_PIPELINE"]);
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
* @param data
|
|
16
|
+
* @param bridge
|
|
17
|
+
*/
|
|
12
18
|
emit(data: UIPPipelineIncomingData, bridge: Bridge): Promise<FromShopfrontReturns["UI_PIPELINE"]>;
|
|
13
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Sends the response data to Shopfront
|
|
21
|
+
* @param bridge
|
|
22
|
+
* @param data
|
|
23
|
+
* @param id
|
|
24
|
+
*/
|
|
25
|
+
static respond(bridge: BaseBridge, data: FromShopfrontReturns["UI_PIPELINE"], id: string): Promise<void>;
|
|
14
26
|
}
|
|
15
27
|
export {};
|
package/lib/Events/UIPipeline.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const BaseEvent_1 = require("./BaseEvent");
|
|
5
|
-
const ApplicationEvents_1 = require("../ApplicationEvents");
|
|
6
|
-
class UIPipeline extends BaseEvent_1.BaseEvent {
|
|
1
|
+
import { ToShopfront, } from "../ApplicationEvents.js";
|
|
2
|
+
import { BaseEvent } from "./BaseEvent.js";
|
|
3
|
+
export class UIPipeline extends BaseEvent {
|
|
7
4
|
constructor(callback) {
|
|
8
5
|
super(callback);
|
|
9
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* @inheritDoc
|
|
9
|
+
* @param data
|
|
10
|
+
* @param bridge
|
|
11
|
+
*/
|
|
10
12
|
async emit(data, bridge) {
|
|
11
13
|
const context = {
|
|
12
|
-
...data.context
|
|
14
|
+
...data.context,
|
|
13
15
|
};
|
|
14
16
|
if (typeof data.pipelineId === "string") {
|
|
15
17
|
context.trigger = () => {
|
|
16
|
-
bridge.sendMessage(
|
|
18
|
+
bridge.sendMessage(ToShopfront.PIPELINE_TRIGGER, {
|
|
17
19
|
id: data.pipelineId,
|
|
18
20
|
});
|
|
19
21
|
};
|
|
@@ -24,8 +26,13 @@ class UIPipeline extends BaseEvent_1.BaseEvent {
|
|
|
24
26
|
}
|
|
25
27
|
return result;
|
|
26
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Sends the response data to Shopfront
|
|
31
|
+
* @param bridge
|
|
32
|
+
* @param data
|
|
33
|
+
* @param id
|
|
34
|
+
*/
|
|
27
35
|
static async respond(bridge, data, id) {
|
|
28
|
-
bridge.sendMessage(
|
|
36
|
+
bridge.sendMessage(ToShopfront.RESPONSE_UI_PIPELINE, data, id);
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
|
-
exports.UIPipeline = UIPipeline;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { BaseCurrentSale } from "../../../APIs/Sale/BaseCurrentSale.js";
|
|
2
|
+
import { SaleCustomer, SalePayment, SaleProduct, ShopfrontSaleState } from "../../../APIs/Sale/index.js";
|
|
3
|
+
import { DirectShopfrontEvent } from "../../../ApplicationEvents.js";
|
|
4
|
+
import { MockApplication } from "../../MockApplication.js";
|
|
5
|
+
export declare class MockCurrentSale extends BaseCurrentSale {
|
|
6
|
+
constructor(application: MockApplication, saleState?: ShopfrontSaleState);
|
|
7
|
+
/**
|
|
8
|
+
* Fires the event trigger
|
|
9
|
+
*/
|
|
10
|
+
protected triggerEvent(event: DirectShopfrontEvent): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
|
|
13
|
+
*/
|
|
14
|
+
protected checkIfCancelled(): void;
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
refreshSale(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
cancelSale(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Round the price to the specified decimal place
|
|
25
|
+
*/
|
|
26
|
+
protected roundNumber(price: number, precision?: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Updates the sale total by adding the specified `amount`
|
|
29
|
+
*/
|
|
30
|
+
protected updateSaleTotal(amount: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* Updates the paid total by adding the specified `amount`
|
|
33
|
+
*/
|
|
34
|
+
protected updatePaidTotal(amount: number): void;
|
|
35
|
+
/**
|
|
36
|
+
* Updates the sale total when a product's price is changed
|
|
37
|
+
*/
|
|
38
|
+
protected handleSaleProductPriceChange(index: number, currentPrice: number, newPrice: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
*/
|
|
42
|
+
addProduct(product: SaleProduct): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* @inheritDoc
|
|
45
|
+
*/
|
|
46
|
+
removeProduct(product: SaleProduct): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* @inheritDoc
|
|
49
|
+
*/
|
|
50
|
+
addPayment(payment: SalePayment): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* @inheritDoc
|
|
53
|
+
*/
|
|
54
|
+
reversePayment(payment: SalePayment): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* @inheritDoc
|
|
57
|
+
*/
|
|
58
|
+
addCustomer(customer: SaleCustomer): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* @inheritDoc
|
|
61
|
+
*/
|
|
62
|
+
removeCustomer(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* @inheritDoc
|
|
65
|
+
*/
|
|
66
|
+
setExternalNote(note: string, append?: boolean): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* @inheritDoc
|
|
69
|
+
*/
|
|
70
|
+
setInternalNote(note: string, append?: boolean): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
*/
|
|
74
|
+
setOrderReference(reference: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
*/
|
|
78
|
+
setMetaData(metaData: Record<string, unknown>): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* @inheritDoc
|
|
81
|
+
*/
|
|
82
|
+
updateProduct(product: SaleProduct): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the index of a product in the sale
|
|
85
|
+
*/
|
|
86
|
+
protected getIndexOfProduct(product: SaleProduct): number;
|
|
87
|
+
/**
|
|
88
|
+
* Clones a sale product so it can be added to the sale
|
|
89
|
+
*/
|
|
90
|
+
protected cloneProduct(product: SaleProduct): SaleProduct;
|
|
91
|
+
/**
|
|
92
|
+
* Clones a sale payment so it can be added to the sale
|
|
93
|
+
*/
|
|
94
|
+
protected clonePayment(payment: SalePayment, reverse?: boolean): SalePayment;
|
|
95
|
+
/**
|
|
96
|
+
* Clear the sale data
|
|
97
|
+
*/
|
|
98
|
+
clearSale(): void;
|
|
99
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { BaseCurrentSale } from "../../../APIs/Sale/BaseCurrentSale.js";
|
|
2
|
+
import { ProductNotExistsError, SaleCancelledError } from "../../../APIs/Sale/Exceptions.js";
|
|
3
|
+
import { SalePayment, SaleProduct, } from "../../../APIs/Sale/index.js";
|
|
4
|
+
import { MockApplication } from "../../MockApplication.js";
|
|
5
|
+
const emptySaleState = {
|
|
6
|
+
clientId: undefined,
|
|
7
|
+
register: undefined,
|
|
8
|
+
products: [],
|
|
9
|
+
customer: false,
|
|
10
|
+
payments: [],
|
|
11
|
+
notes: {
|
|
12
|
+
sale: "",
|
|
13
|
+
internal: "",
|
|
14
|
+
},
|
|
15
|
+
totals: {
|
|
16
|
+
sale: 0,
|
|
17
|
+
paid: 0,
|
|
18
|
+
savings: 0,
|
|
19
|
+
discount: 0,
|
|
20
|
+
},
|
|
21
|
+
linkedTo: "",
|
|
22
|
+
orderReference: "",
|
|
23
|
+
refundReason: "",
|
|
24
|
+
priceSet: null,
|
|
25
|
+
metaData: {},
|
|
26
|
+
};
|
|
27
|
+
export class MockCurrentSale extends BaseCurrentSale {
|
|
28
|
+
constructor(application, saleState) {
|
|
29
|
+
super(application, saleState ?? emptySaleState);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fires the event trigger
|
|
33
|
+
*/
|
|
34
|
+
async triggerEvent(event) {
|
|
35
|
+
if (this.application instanceof MockApplication) {
|
|
36
|
+
await this.application.fireEvent(event);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error("Manually firing events is only supported in the `MockApplication`");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
|
|
44
|
+
*/
|
|
45
|
+
checkIfCancelled() {
|
|
46
|
+
if (this.cancelled) {
|
|
47
|
+
throw new SaleCancelledError();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @inheritDoc
|
|
52
|
+
*/
|
|
53
|
+
async refreshSale() {
|
|
54
|
+
/* Do nothing */
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
59
|
+
async cancelSale() {
|
|
60
|
+
this.clearSale();
|
|
61
|
+
this.cancelled = true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Round the price to the specified decimal place
|
|
65
|
+
*/
|
|
66
|
+
roundNumber(price, precision = 2) {
|
|
67
|
+
const multiplier = Math.pow(10, precision);
|
|
68
|
+
return Math.round(price * multiplier) / multiplier;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Updates the sale total by adding the specified `amount`
|
|
72
|
+
*/
|
|
73
|
+
updateSaleTotal(amount) {
|
|
74
|
+
this.sale.totals.sale += amount;
|
|
75
|
+
this.sale.totals.sale = this.roundNumber(this.sale.totals.sale);
|
|
76
|
+
}
|
|
77
|
+
;
|
|
78
|
+
/**
|
|
79
|
+
* Updates the paid total by adding the specified `amount`
|
|
80
|
+
*/
|
|
81
|
+
updatePaidTotal(amount) {
|
|
82
|
+
this.sale.totals.paid += amount;
|
|
83
|
+
this.sale.totals.paid = this.roundNumber(this.sale.totals.paid);
|
|
84
|
+
}
|
|
85
|
+
;
|
|
86
|
+
/**
|
|
87
|
+
* Updates the sale total when a product's price is changed
|
|
88
|
+
*/
|
|
89
|
+
handleSaleProductPriceChange(index, currentPrice, newPrice) {
|
|
90
|
+
// Editing the property directly to avoid triggering the `wasPriceModified` flag
|
|
91
|
+
this.products[index]["price"] = newPrice;
|
|
92
|
+
const difference = newPrice - currentPrice;
|
|
93
|
+
this.updateSaleTotal(difference);
|
|
94
|
+
}
|
|
95
|
+
;
|
|
96
|
+
/**
|
|
97
|
+
* @inheritDoc
|
|
98
|
+
*/
|
|
99
|
+
async addProduct(product) {
|
|
100
|
+
this.checkIfCancelled();
|
|
101
|
+
// Check if product already exists in the sale
|
|
102
|
+
try {
|
|
103
|
+
// If it does, update it
|
|
104
|
+
const index = this.getIndexOfProduct(product);
|
|
105
|
+
// TODO: Does not currently support not consolidating
|
|
106
|
+
// If a product is added again with a different price, the new price is ignored
|
|
107
|
+
// This behaviour was taken from the `addProductToSale` function in the POS
|
|
108
|
+
const currentPrice = this.products[index].getPrice() || 0;
|
|
109
|
+
const currentRate = currentPrice / this.products[index].getQuantity();
|
|
110
|
+
// Editing the property directly to avoid triggering the `wasQuantityModified` flag
|
|
111
|
+
this.products[index]["quantity"] += product.getQuantity();
|
|
112
|
+
const newPrice = this.roundNumber(currentRate * this.products[index].getQuantity());
|
|
113
|
+
this.handleSaleProductPriceChange(index, currentPrice, newPrice);
|
|
114
|
+
await this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
// We want to throw the error unless it's because the product isn't in the sale
|
|
119
|
+
if (!(e instanceof ProductNotExistsError)) {
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
product["indexAddress"] = this.products.length === 0 ? [0] : [this.products.length];
|
|
124
|
+
product["edited"] = false;
|
|
125
|
+
this.products.push(this.cloneProduct(product));
|
|
126
|
+
this.updateSaleTotal(product.getPrice() || 0);
|
|
127
|
+
await this.triggerEvent("SALE_ADD_PRODUCT");
|
|
128
|
+
await this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @inheritDoc
|
|
132
|
+
*/
|
|
133
|
+
async removeProduct(product) {
|
|
134
|
+
this.checkIfCancelled();
|
|
135
|
+
if (this.products.length === 1 && this.sale.totals.paid !== 0) {
|
|
136
|
+
throw new Error("Cannot remove the last product from the sale if the sale contains an outstanding balance");
|
|
137
|
+
}
|
|
138
|
+
const index = this.getIndexOfProduct(product);
|
|
139
|
+
this.products.splice(index, 1);
|
|
140
|
+
this.updateSaleTotal((product.getPrice() || 0) * -1);
|
|
141
|
+
// Reshuffle the index addresses
|
|
142
|
+
for (let i = 0, l = this.products.length; i < l; i++) {
|
|
143
|
+
this.products[i]["indexAddress"] = [i];
|
|
144
|
+
}
|
|
145
|
+
await this.triggerEvent("SALE_REMOVE_PRODUCT");
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @inheritDoc
|
|
149
|
+
*/
|
|
150
|
+
async addPayment(payment) {
|
|
151
|
+
this.checkIfCancelled();
|
|
152
|
+
this.payments.push(this.clonePayment(payment));
|
|
153
|
+
if (payment.getStatus() === "cancelled" || payment.getStatus() === "failed") {
|
|
154
|
+
// No need to update any of the totals
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.updatePaidTotal(payment.getAmount() - (payment.getCashout() || 0));
|
|
158
|
+
const remaining = this.roundNumber(this.sale.totals.sale - this.sale.totals.paid);
|
|
159
|
+
if (remaining <= 0) {
|
|
160
|
+
this.clearSale();
|
|
161
|
+
await this.triggerEvent("SALE_CLEAR");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @inheritDoc
|
|
166
|
+
*/
|
|
167
|
+
async reversePayment(payment) {
|
|
168
|
+
this.checkIfCancelled();
|
|
169
|
+
// Should not be reverse-able past 0
|
|
170
|
+
if (this.sale.totals.paid - payment.getAmount() < 0) {
|
|
171
|
+
throw new Error("The paid total cannot be less than 0");
|
|
172
|
+
}
|
|
173
|
+
const reversed = this.clonePayment(payment, true);
|
|
174
|
+
this.payments.push(reversed);
|
|
175
|
+
if (payment.getStatus() === "cancelled" || payment.getStatus() === "failed") {
|
|
176
|
+
// No need to update any of the totals
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
this.updatePaidTotal(reversed.getAmount());
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* @inheritDoc
|
|
183
|
+
*/
|
|
184
|
+
async addCustomer(customer) {
|
|
185
|
+
this.checkIfCancelled();
|
|
186
|
+
this.customer = customer;
|
|
187
|
+
await this.triggerEvent("SALE_ADD_CUSTOMER");
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @inheritDoc
|
|
191
|
+
*/
|
|
192
|
+
async removeCustomer() {
|
|
193
|
+
this.checkIfCancelled();
|
|
194
|
+
this.customer = null;
|
|
195
|
+
await this.triggerEvent("SALE_REMOVE_CUSTOMER");
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @inheritDoc
|
|
199
|
+
*/
|
|
200
|
+
async setExternalNote(note, append) {
|
|
201
|
+
this.checkIfCancelled();
|
|
202
|
+
let toSet;
|
|
203
|
+
if (append) {
|
|
204
|
+
toSet = `${this.sale.notes.sale}${note}`;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
toSet = note;
|
|
208
|
+
}
|
|
209
|
+
this.sale.notes.sale = toSet;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* @inheritDoc
|
|
213
|
+
*/
|
|
214
|
+
async setInternalNote(note, append) {
|
|
215
|
+
this.checkIfCancelled();
|
|
216
|
+
let toSet;
|
|
217
|
+
if (append) {
|
|
218
|
+
toSet = `${this.sale.notes.internal}${note}`;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
toSet = note;
|
|
222
|
+
}
|
|
223
|
+
this.sale.notes.internal = toSet;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* @inheritDoc
|
|
227
|
+
*/
|
|
228
|
+
async setOrderReference(reference) {
|
|
229
|
+
this.checkIfCancelled();
|
|
230
|
+
this.sale.orderReference = reference;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @inheritDoc
|
|
234
|
+
*/
|
|
235
|
+
async setMetaData(metaData) {
|
|
236
|
+
this.checkIfCancelled();
|
|
237
|
+
this.sale.metaData = metaData;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @inheritDoc
|
|
241
|
+
*/
|
|
242
|
+
async updateProduct(product) {
|
|
243
|
+
this.checkIfCancelled();
|
|
244
|
+
const index = this.getIndexOfProduct(product);
|
|
245
|
+
if (product.wasQuantityModified()) {
|
|
246
|
+
const currentPrice = this.products[index].getPrice() || 0;
|
|
247
|
+
const currentRate = this.roundNumber(currentPrice / this.products[index].getQuantity());
|
|
248
|
+
this.products[index]["quantity"] = product.getQuantity();
|
|
249
|
+
const newPrice = this.roundNumber(currentRate * product.getQuantity());
|
|
250
|
+
this.handleSaleProductPriceChange(index, currentPrice, newPrice);
|
|
251
|
+
}
|
|
252
|
+
if (product.wasPriceModified()) {
|
|
253
|
+
const currentPrice = this.products[index].getPrice() || 0;
|
|
254
|
+
const newPrice = product.getPrice() || 0;
|
|
255
|
+
this.handleSaleProductPriceChange(index, currentPrice, newPrice);
|
|
256
|
+
}
|
|
257
|
+
if (product.wasMetaDataModified()) {
|
|
258
|
+
this.products[index]["metaData"] = product.getMetaData();
|
|
259
|
+
}
|
|
260
|
+
product.clearModificationFlags();
|
|
261
|
+
await this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Retrieves the index of a product in the sale
|
|
265
|
+
*/
|
|
266
|
+
getIndexOfProduct(product) {
|
|
267
|
+
const index = this.products.findIndex((p) => p.getId() === product.getId());
|
|
268
|
+
if (index === -1) {
|
|
269
|
+
throw new ProductNotExistsError();
|
|
270
|
+
}
|
|
271
|
+
return index;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Clones a sale product so it can be added to the sale
|
|
275
|
+
*/
|
|
276
|
+
cloneProduct(product) {
|
|
277
|
+
const clone = new SaleProduct(product.getId(), product.getQuantity(), product.getPrice(), product.getIndexAddress());
|
|
278
|
+
clone["note"] = product["note"];
|
|
279
|
+
clone["contains"] = product["contains"];
|
|
280
|
+
clone["edited"] = product["edited"];
|
|
281
|
+
clone["promotions"] = product["promotions"];
|
|
282
|
+
clone["metaData"] = product["metaData"];
|
|
283
|
+
clone["quantityModified"] = product["quantityModified"];
|
|
284
|
+
clone["priceModified"] = product["priceModified"];
|
|
285
|
+
clone["metaDataModified"] = product["metaDataModified"];
|
|
286
|
+
return clone;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Clones a sale payment so it can be added to the sale
|
|
290
|
+
*/
|
|
291
|
+
clonePayment(payment, reverse = false) {
|
|
292
|
+
const updatedAmount = reverse ? payment.getAmount() * -1 : payment.getAmount();
|
|
293
|
+
const clone = new SalePayment(payment.getId(), updatedAmount, payment.getCashout(), payment.getStatus());
|
|
294
|
+
clone["metaData"] = payment["metaData"];
|
|
295
|
+
return clone;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Clear the sale data
|
|
299
|
+
*/
|
|
300
|
+
clearSale() {
|
|
301
|
+
this.products.length = 0;
|
|
302
|
+
this.products.push(...[]);
|
|
303
|
+
this.payments.length = 0;
|
|
304
|
+
this.payments.push(...[]);
|
|
305
|
+
this.customer = null;
|
|
306
|
+
this.sale = {
|
|
307
|
+
register: undefined,
|
|
308
|
+
clientId: undefined,
|
|
309
|
+
notes: {
|
|
310
|
+
sale: "",
|
|
311
|
+
internal: "",
|
|
312
|
+
},
|
|
313
|
+
totals: {
|
|
314
|
+
sale: 0,
|
|
315
|
+
paid: 0,
|
|
316
|
+
savings: 0,
|
|
317
|
+
discount: 0,
|
|
318
|
+
},
|
|
319
|
+
linkedTo: "",
|
|
320
|
+
orderReference: "",
|
|
321
|
+
refundReason: "",
|
|
322
|
+
priceSet: null,
|
|
323
|
+
metaData: {},
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { BaseDatabase, DatabaseCallReturn, DatabaseMethodName, DatabaseTable } from "../../APIs/Database/BaseDatabase.js";
|
|
2
|
+
import { LocalDatabaseBarcodeTemplate } from "../../APIs/Database/types/BaseBarcodeTemplateRepository.js";
|
|
3
|
+
import { LocalDatabaseClassification } from "../../APIs/Database/types/BaseClassificationRepository.js";
|
|
4
|
+
import { LocalDatabaseCustomerDisplay } from "../../APIs/Database/types/BaseCustomerDisplayRepository.js";
|
|
5
|
+
import { LocalDatabaseCustomerGroup } from "../../APIs/Database/types/BaseCustomerGroupRepository.js";
|
|
6
|
+
import { LocalDatabaseCustomer } from "../../APIs/Database/types/BaseCustomerRepository.js";
|
|
7
|
+
import { LocalDatabaseEnterprise } from "../../APIs/Database/types/BaseEnterpriseRepository.js";
|
|
8
|
+
import { LocalDatabaseGiftCard } from "../../APIs/Database/types/BaseGiftCardRepository.js";
|
|
9
|
+
import { LocalDatabaseLoyalty } from "../../APIs/Database/types/BaseLoyaltyRepository.js";
|
|
10
|
+
import { LocalDatabaseMovement } from "../../APIs/Database/types/BaseMovementRepository.js";
|
|
11
|
+
import { LocalDatabaseOutlet } from "../../APIs/Database/types/BaseOutletRepository.js";
|
|
12
|
+
import { LocalDatabasePaymentMethod } from "../../APIs/Database/types/BasePaymentMethodRepository.js";
|
|
13
|
+
import { LocalDatabasePriceList } from "../../APIs/Database/types/BasePriceListRepository.js";
|
|
14
|
+
import { LocalDatabasePriceSet } from "../../APIs/Database/types/BasePriceSetRepository.js";
|
|
15
|
+
import { LocalDatabaseProduct } from "../../APIs/Database/types/BaseProductRepository.js";
|
|
16
|
+
import { LocalDatabasePromotionCategory } from "../../APIs/Database/types/BasePromotionCategoryRepository.js";
|
|
17
|
+
import { LocalDatabasePromotion } from "../../APIs/Database/types/BasePromotionRepository.js";
|
|
18
|
+
import { LocalDatabaseReceipt } from "../../APIs/Database/types/BaseReceiptRepository.js";
|
|
19
|
+
import { LocalDatabaseRegister } from "../../APIs/Database/types/BaseRegisterRepository.js";
|
|
20
|
+
import { LocalDatabaseSaleKeys } from "../../APIs/Database/types/BaseSalesKeyRepository.js";
|
|
21
|
+
import { LocalDatabaseSale } from "../../APIs/Database/types/BaseSalesRepository.js";
|
|
22
|
+
import { LocalDatabaseStocktakeAccumulated } from "../../APIs/Database/types/BaseStocktakeAccumulatedRepository.js";
|
|
23
|
+
import { LocalDatabaseStocktake } from "../../APIs/Database/types/BaseStocktakeRepository.js";
|
|
24
|
+
import { LocalDatabaseStocktakeScanned } from "../../APIs/Database/types/BaseStocktakeScannedRepository.js";
|
|
25
|
+
import { LocalDatabaseSupplier } from "../../APIs/Database/types/BaseSupplierRepository.js";
|
|
26
|
+
import { LocalDatabaseTakings } from "../../APIs/Database/types/BaseTakingsRepository.js";
|
|
27
|
+
import { LocalDatabaseTaxRate } from "../../APIs/Database/types/BaseTaxRateRepository.js";
|
|
28
|
+
import { LocalDatabaseTransferee } from "../../APIs/Database/types/BaseTransfereeRepository.js";
|
|
29
|
+
import { LocalDatabaseVendorConnection } from "../../APIs/Database/types/BaseVendorConnectionRepository.js";
|
|
30
|
+
import { MockBridge } from "../MockBridge.js";
|
|
31
|
+
interface MockedDatabase {
|
|
32
|
+
products: Array<LocalDatabaseProduct>;
|
|
33
|
+
customers: Array<LocalDatabaseCustomer>;
|
|
34
|
+
customerGroups: Array<LocalDatabaseCustomerGroup>;
|
|
35
|
+
promotions: Array<LocalDatabasePromotion>;
|
|
36
|
+
promotionCategories: Array<LocalDatabasePromotionCategory>;
|
|
37
|
+
priceLists: Array<LocalDatabasePriceList>;
|
|
38
|
+
paymentMethods: Array<LocalDatabasePaymentMethod>;
|
|
39
|
+
salesKeys: Array<LocalDatabaseSaleKeys>;
|
|
40
|
+
receipts: Array<LocalDatabaseReceipt>;
|
|
41
|
+
giftCards: Array<LocalDatabaseGiftCard>;
|
|
42
|
+
loyalty: Array<LocalDatabaseLoyalty>;
|
|
43
|
+
customerDisplays: Array<LocalDatabaseCustomerDisplay>;
|
|
44
|
+
sales: Array<LocalDatabaseSale>;
|
|
45
|
+
brands: Array<LocalDatabaseClassification>;
|
|
46
|
+
categories: Array<LocalDatabaseClassification>;
|
|
47
|
+
families: Array<LocalDatabaseClassification>;
|
|
48
|
+
tags: Array<LocalDatabaseClassification>;
|
|
49
|
+
outlets: Array<LocalDatabaseOutlet>;
|
|
50
|
+
registers: Array<LocalDatabaseRegister>;
|
|
51
|
+
taxRates: Array<LocalDatabaseTaxRate>;
|
|
52
|
+
takings: Array<LocalDatabaseTakings>;
|
|
53
|
+
suppliers: Array<LocalDatabaseSupplier>;
|
|
54
|
+
priceSets: Array<LocalDatabasePriceSet>;
|
|
55
|
+
transferees: Array<LocalDatabaseTransferee>;
|
|
56
|
+
movements: Array<LocalDatabaseMovement>;
|
|
57
|
+
stocktakes: Array<LocalDatabaseStocktake>;
|
|
58
|
+
stocktakeScanned: Array<LocalDatabaseStocktakeScanned>;
|
|
59
|
+
stocktakeAccumulated: Array<LocalDatabaseStocktakeAccumulated>;
|
|
60
|
+
barcodeTemplates: Array<LocalDatabaseBarcodeTemplate>;
|
|
61
|
+
vendorConnections: Array<LocalDatabaseVendorConnection>;
|
|
62
|
+
enterprises: Array<LocalDatabaseEnterprise>;
|
|
63
|
+
}
|
|
64
|
+
export declare class MockDatabase extends BaseDatabase<MockBridge> {
|
|
65
|
+
protected mockedDatabase: MockedDatabase;
|
|
66
|
+
constructor(bridge: MockBridge);
|
|
67
|
+
/**
|
|
68
|
+
* @inheritDoc
|
|
69
|
+
*/
|
|
70
|
+
callMethod<Table extends DatabaseTable, Method extends keyof DatabaseMethodName<Table>, ExpectedResult extends DatabaseCallReturn<Table, Method>>(table: Table, method: Method, args: Array<unknown>): Promise<ExpectedResult>;
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
*/
|
|
74
|
+
all<Table extends DatabaseTable>(table: Table): Promise<DatabaseCallReturn<Table, "all">>;
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
*/
|
|
78
|
+
get<Table extends DatabaseTable>(table: Table, id: string | number): Promise<DatabaseCallReturn<Table, "get">>;
|
|
79
|
+
/**
|
|
80
|
+
* @inheritDoc
|
|
81
|
+
*/
|
|
82
|
+
count(table: DatabaseTable): Promise<number>;
|
|
83
|
+
/**
|
|
84
|
+
* Insert data into the mocked Database
|
|
85
|
+
*/
|
|
86
|
+
insertData<Table extends keyof MockedDatabase>(table: Table, rows: Array<MockedDatabase[Table]>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Clears all data from the mocked database
|
|
89
|
+
*/
|
|
90
|
+
clearDatabase(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Clears the data from a specified table
|
|
93
|
+
*/
|
|
94
|
+
clearTable<Table extends keyof MockedDatabase>(table: Table): void;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BaseDatabase, } from "../../APIs/Database/BaseDatabase.js";
|
|
2
|
+
const emptyDatabase = {
|
|
3
|
+
products: [],
|
|
4
|
+
customers: [],
|
|
5
|
+
customerGroups: [],
|
|
6
|
+
promotions: [],
|
|
7
|
+
promotionCategories: [],
|
|
8
|
+
priceLists: [],
|
|
9
|
+
paymentMethods: [],
|
|
10
|
+
salesKeys: [],
|
|
11
|
+
receipts: [],
|
|
12
|
+
giftCards: [],
|
|
13
|
+
loyalty: [],
|
|
14
|
+
customerDisplays: [],
|
|
15
|
+
sales: [],
|
|
16
|
+
brands: [],
|
|
17
|
+
categories: [],
|
|
18
|
+
families: [],
|
|
19
|
+
tags: [],
|
|
20
|
+
outlets: [],
|
|
21
|
+
registers: [],
|
|
22
|
+
taxRates: [],
|
|
23
|
+
takings: [],
|
|
24
|
+
suppliers: [],
|
|
25
|
+
priceSets: [],
|
|
26
|
+
transferees: [],
|
|
27
|
+
movements: [],
|
|
28
|
+
stocktakes: [],
|
|
29
|
+
stocktakeScanned: [],
|
|
30
|
+
stocktakeAccumulated: [],
|
|
31
|
+
barcodeTemplates: [],
|
|
32
|
+
vendorConnections: [],
|
|
33
|
+
enterprises: [],
|
|
34
|
+
};
|
|
35
|
+
export class MockDatabase extends BaseDatabase {
|
|
36
|
+
constructor(bridge) {
|
|
37
|
+
super(bridge);
|
|
38
|
+
this.mockedDatabase = emptyDatabase;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
async callMethod(table, method, args) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @inheritDoc
|
|
48
|
+
*/
|
|
49
|
+
async all(table) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @inheritDoc
|
|
54
|
+
*/
|
|
55
|
+
async get(table, id) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @inheritDoc
|
|
60
|
+
*/
|
|
61
|
+
async count(table) {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Insert data into the mocked Database
|
|
66
|
+
*/
|
|
67
|
+
insertData(table, rows) {
|
|
68
|
+
if (typeof this.mockedDatabase[table] === "undefined") {
|
|
69
|
+
throw new Error(`The table ${table} does not exist`);
|
|
70
|
+
}
|
|
71
|
+
// @ts-expect-error TypeScript resolves `MockedDatabase[Table]` as a union of arrays
|
|
72
|
+
this.mockedDatabase[table].push(...rows);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Clears all data from the mocked database
|
|
76
|
+
*/
|
|
77
|
+
clearDatabase() {
|
|
78
|
+
this.mockedDatabase = emptyDatabase;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Clears the data from a specified table
|
|
82
|
+
*/
|
|
83
|
+
clearTable(table) {
|
|
84
|
+
if (typeof this.mockedDatabase[table] === "undefined") {
|
|
85
|
+
throw new Error(`The table ${table} does not exist`);
|
|
86
|
+
}
|
|
87
|
+
this.mockedDatabase[table] = [];
|
|
88
|
+
}
|
|
89
|
+
}
|