addio-admin-sdk 1.7.185-canary-1 → 1.7.185
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/.env +6 -5
- package/dist/lib/Cart/index.d.ts +2 -4
- package/dist/lib/Cart/index.js +44 -15
- package/dist/lib/Cart/index.js.map +1 -1
- package/dist/lib/Queue/index.d.ts +40 -0
- package/dist/lib/Queue/index.js +255 -0
- package/dist/lib/Queue/index.js.map +1 -0
- package/dist/utils/promiseToPurchase.d.ts +1 -5
- package/dist/utils/promiseToPurchase.js +1 -10
- package/dist/utils/promiseToPurchase.js.map +1 -1
- package/package.json +1 -1
- package/.claude/settings.local.json +0 -7
package/.env
CHANGED
|
@@ -2,13 +2,14 @@ NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_DEV='AIzaSyBNtwzdIe2__HJD23S87RIbWbIqKQVtFiw
|
|
|
2
2
|
NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_PROD='AIzaSyDK6WQZkCrsMGunAPHn9KkdCGPky4hTgL4'
|
|
3
3
|
NEXT_PUBLIC_MESSAGING_SENDER_ID_DEV='188490998694'
|
|
4
4
|
NEXT_PUBLIC_MESSAGING_SENDER_ID_PROD='725873016982'
|
|
5
|
-
NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
|
|
6
5
|
NEXT_PUBLIC_FIREBASE_APP_ID_PROD='1:725873016982:web:9b1f6d77819909e19102b7'
|
|
6
|
+
NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
|
|
7
7
|
NEXT_PUBLIC_MEASUREMENT_ID_DEV='G-4BB66ZRTWZ'
|
|
8
8
|
NEXT_PUBLIC_MEASUREMENT_ID_PROD='G-BB8HHZ466R'
|
|
9
|
+
|
|
9
10
|
NEXT_PUBLIC_SERVICE_DATABASE_READ_PROVIDER=nobase
|
|
10
|
-
NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase
|
|
11
|
+
NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase
|
|
11
12
|
NEXT_PUBLIC_SERVICE_DATABASE_URL=https://db-test.addiocommerce.com/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
NEXT_PUBLIC_API_URL=https://api-test.addiocommerce.com/v1
|
|
14
|
+
NEXT_PUBLIC_SERVICE_DATABASE_TOKEN='337043a374-6f0be-5eb26-05be550631'
|
|
15
|
+
LOCAL_FIRESTORE=false
|
package/dist/lib/Cart/index.d.ts
CHANGED
|
@@ -274,9 +274,8 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
274
274
|
* @param escompteItems list of discount products from the dash
|
|
275
275
|
* @param customPriceList list of products with their custom pric from G2
|
|
276
276
|
* @param banksUsedForCart Optionnal. Array of banks_used applied to cart
|
|
277
|
-
* @param isCartModification Optionnal. Is it a modification process
|
|
278
277
|
*/
|
|
279
|
-
updateWithPromiseToPurchasePrices: (escompteItems: IndexedProduct[], customPriceList?: string | ICustomPriceItem[] | undefined, banksUsedForCart?: IBankUsed[]
|
|
278
|
+
updateWithPromiseToPurchasePrices: (escompteItems: IndexedProduct[], customPriceList?: string | ICustomPriceItem[] | undefined, banksUsedForCart?: IBankUsed[]) => Promise<void>;
|
|
280
279
|
/**
|
|
281
280
|
* Function canBePaidWithMyPromiseToPurchase
|
|
282
281
|
* @description Check if a cart can be paid with a promise to purchase
|
|
@@ -307,10 +306,9 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
307
306
|
* @param customPriceList a list of custom price items
|
|
308
307
|
* @param space the space
|
|
309
308
|
* @param forcedCartType Optionnal. If provided, overrides cart type found by check cart item types.
|
|
310
|
-
* @param isCartModification Optionnal. Pass true when called from the POS order modification flow so escompte lines are rebuilt even on a paid cart.
|
|
311
309
|
* @returns the updated cart and a boolean canBePaid determining if the cart can be paid with the promise or not
|
|
312
310
|
*/
|
|
313
|
-
canBePaidWithPA: (applicableBanks: IApplicablePromiseBank[], customerID: string, customPriceList: ICustomPriceItem[], space: Space, forcedBankTypeId?: string
|
|
311
|
+
canBePaidWithPA: (applicableBanks: IApplicablePromiseBank[], customerID: string, customPriceList: ICustomPriceItem[], space: Space, forcedBankTypeId?: string) => Promise<{
|
|
314
312
|
canBePaid: boolean;
|
|
315
313
|
canBePaidReason?: ApplyBanksToCartErrorsEnum | undefined;
|
|
316
314
|
updatedCart: ICart;
|
package/dist/lib/Cart/index.js
CHANGED
|
@@ -60,6 +60,7 @@ const g2_1 = require("../../rules/GR/utils/g2");
|
|
|
60
60
|
const cart_1 = require("../../utils/cart");
|
|
61
61
|
const promiseToPurchase_1 = require("../../utils/promiseToPurchase");
|
|
62
62
|
const PromiseToPurchase_2 = require("../../Interfaces/PromiseToPurchase");
|
|
63
|
+
const products_2 = require("../../rules/GR/utils/products");
|
|
63
64
|
const baseService_1 = require("../baseService");
|
|
64
65
|
const DatabaseService_1 = __importDefault(require("../../services/database/DatabaseService"));
|
|
65
66
|
const logs_1 = require("../../services/logs");
|
|
@@ -1905,15 +1906,46 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1905
1906
|
const space = await Space_2.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
1906
1907
|
if (!!!space)
|
|
1907
1908
|
throw new Error('could not init space obj');
|
|
1908
|
-
|
|
1909
|
-
if (
|
|
1910
|
-
|
|
1911
|
-
await
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1909
|
+
// If the cart is associated to a promise
|
|
1910
|
+
if (!!options.usedPromise) {
|
|
1911
|
+
for (const bank of options.usedPromise.banks_used) {
|
|
1912
|
+
const promiseQuery = await space.promisesToPurchase.get({
|
|
1913
|
+
query: [{ field: 'id', operator: '==', value: bank.promise_id }]
|
|
1914
|
+
});
|
|
1915
|
+
// If the promise is closed or doesn't exist, we don't adjust it
|
|
1916
|
+
if (!!!promiseQuery || !!!promiseQuery.length)
|
|
1917
|
+
continue;
|
|
1918
|
+
if (!!promiseQuery[0].data().ending_date)
|
|
1919
|
+
continue;
|
|
1920
|
+
// If the bank is inactive, we don't adjust it
|
|
1921
|
+
const bankInDB = promiseQuery[0].data().banks.find((b) => b.bank_type_id === bank.bank_type_id);
|
|
1922
|
+
if (!!!bankInDB || !!!bankInDB.active)
|
|
1923
|
+
continue;
|
|
1924
|
+
let amountTotal = 0;
|
|
1925
|
+
const taxes = this.data().total - this.data().subtotal;
|
|
1926
|
+
if ((0, promiseToPurchase_1.getBankTypeName)(space.bankTypes.get(), bank.bank_type_id) === 'installation') {
|
|
1927
|
+
amountTotal = Number((0, products_2.getInstallItemPrice)('installation-gazon', itemsForInventory.filter((i) => !!i.is_service)));
|
|
1928
|
+
}
|
|
1929
|
+
else {
|
|
1930
|
+
const itemsWithoutInstallation = itemsForInventory.filter((i) => !!!i.parent_slug || !!!['installation-gazon', 'frais-de-mobilisation'].includes(i.parent_slug));
|
|
1931
|
+
itemsWithoutInstallation.map((i) => (amountTotal += (0, products_1.getLowestPrice)(i).price.amount * i.qte));
|
|
1932
|
+
amountTotal += taxes;
|
|
1933
|
+
}
|
|
1934
|
+
const adjustment = {
|
|
1935
|
+
amount: amountTotal * -1,
|
|
1936
|
+
reason: `Modification de la commande #${this.data().ref}`,
|
|
1937
|
+
issued_at: new Date(),
|
|
1938
|
+
issued_by: !!currentUser ? currentUser : (0, services_1.getDefaultSpaceUserEmail)(space.data().id)
|
|
1939
|
+
};
|
|
1940
|
+
const remainingAmount = await space.promisesToPurchase.getSpecificAvailableBankAmount(bank.promise_id, bank.bank_type_id, promiseQuery[0]);
|
|
1941
|
+
let newRemainingAmount;
|
|
1942
|
+
if (!!remainingAmount && !!remainingAmount.remaining_amount) {
|
|
1943
|
+
newRemainingAmount = (0, round_1.default)(remainingAmount.remaining_amount, 3) + (0, round_1.default)(adjustment.amount);
|
|
1944
|
+
}
|
|
1945
|
+
await promiseQuery[0].adjustAmountLeftInPromise(adjustment, bank.bank_type_id, !!newRemainingAmount && newRemainingAmount < 1);
|
|
1915
1946
|
}
|
|
1916
1947
|
}
|
|
1948
|
+
await this.save(partial, undefined, shouldSaveToDB, true);
|
|
1917
1949
|
// INVENTORY MANAGEMENT
|
|
1918
1950
|
const data = this.data();
|
|
1919
1951
|
const storeIdToUse = !!data.current_store_id
|
|
@@ -3296,14 +3328,12 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3296
3328
|
* @param escompteItems list of discount products from the dash
|
|
3297
3329
|
* @param customPriceList list of products with their custom pric from G2
|
|
3298
3330
|
* @param banksUsedForCart Optionnal. Array of banks_used applied to cart
|
|
3299
|
-
* @param isCartModification Optionnal. Is it a modification process
|
|
3300
3331
|
*/
|
|
3301
|
-
this.updateWithPromiseToPurchasePrices = async (escompteItems, customPriceList = undefined, banksUsedForCart
|
|
3332
|
+
this.updateWithPromiseToPurchasePrices = async (escompteItems, customPriceList = undefined, banksUsedForCart) => {
|
|
3302
3333
|
var _b, _c, _d, _e;
|
|
3303
3334
|
if (!!!customPriceList || typeof customPriceList == 'string')
|
|
3304
3335
|
throw new Error('CustomPriceList is undefined!');
|
|
3305
|
-
if (
|
|
3306
|
-
!!this.data().status &&
|
|
3336
|
+
if (!!this.data().status &&
|
|
3307
3337
|
this.data().status >= Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS &&
|
|
3308
3338
|
!!this.data().paid_at) {
|
|
3309
3339
|
console.log('cannot update a paid cart with a PA, returning');
|
|
@@ -3577,10 +3607,9 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3577
3607
|
* @param customPriceList a list of custom price items
|
|
3578
3608
|
* @param space the space
|
|
3579
3609
|
* @param forcedCartType Optionnal. If provided, overrides cart type found by check cart item types.
|
|
3580
|
-
* @param isCartModification Optionnal. Pass true when called from the POS order modification flow so escompte lines are rebuilt even on a paid cart.
|
|
3581
3610
|
* @returns the updated cart and a boolean canBePaid determining if the cart can be paid with the promise or not
|
|
3582
3611
|
*/
|
|
3583
|
-
this.canBePaidWithPA = async (applicableBanks, customerID, customPriceList, space, forcedBankTypeId
|
|
3612
|
+
this.canBePaidWithPA = async (applicableBanks, customerID, customPriceList, space, forcedBankTypeId) => {
|
|
3584
3613
|
const contingency = space.promisesToPurchase.getContingency();
|
|
3585
3614
|
const escomptesItems = await space.promisesToPurchase.getEscompteItems();
|
|
3586
3615
|
// Get use history for applicable banks
|
|
@@ -3611,13 +3640,13 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3611
3640
|
bank_type_id: b.bank.bank_type_id,
|
|
3612
3641
|
amount: 0
|
|
3613
3642
|
}));
|
|
3614
|
-
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, possibleBanksToUse
|
|
3643
|
+
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, possibleBanksToUse);
|
|
3615
3644
|
const canBePaidCheck = await this.canBePaidWithMyPromiseToPurchase(applicableBanks, filteredApplicableBanksHistory, customPriceList, contingency, forcedBankTypeId);
|
|
3616
3645
|
// if banks applicable length is different from banks truly applied to cart,
|
|
3617
3646
|
// adjust added escomptes with banks used for cart
|
|
3618
3647
|
if (!!this._data.promise_to_purchase &&
|
|
3619
3648
|
applicableBanks.length !== this._data.promise_to_purchase.banks_used.length) {
|
|
3620
|
-
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, this._data.promise_to_purchase.banks_used
|
|
3649
|
+
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, this._data.promise_to_purchase.banks_used);
|
|
3621
3650
|
}
|
|
3622
3651
|
const canBePaid = typeof canBePaidCheck === 'boolean';
|
|
3623
3652
|
return Object.assign(Object.assign({ canBePaid }, (!!!canBePaid ? { canBePaidReason: canBePaidCheck } : {})), { updatedCart: this.data() });
|