feat: интерактивный установщик install.sh (Docker / Ubuntu, админ, БД)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
shop
2026-05-17 13:57:54 +03:00
parent dedef454c8
commit db4bc9bfe1
28 changed files with 1069 additions and 22 deletions
+66
View File
@@ -0,0 +1,66 @@
const promoService = require('./promo');
const loyaltyService = require('./loyalty');
async function buildCartPricing(items, session, userId) {
const subtotal = items.reduce((s, i) => s + i.line_total, 0);
let promo = null;
let promoDiscount = 0;
let promoError = null;
if (session.appliedPromoCode) {
promo = await promoService.findPromoByCode(session.appliedPromoCode);
const check = promoService.validatePromo(promo, subtotal);
if (!check.ok) {
promoError = check.error;
promo = null;
delete session.appliedPromoCode;
} else {
promoDiscount = promoService.calcPromoDiscountCents(promo, subtotal);
}
}
const afterPromo = Math.max(0, subtotal - promoDiscount);
let loyaltyBalance = 0;
let loyaltyDiscount = 0;
let loyaltyPointsUsed = 0;
if (userId) {
loyaltyBalance = await loyaltyService.getBalance(userId);
const requested = session.loyaltyPointsToUse ?? 0;
loyaltyDiscount = loyaltyService.calcLoyaltyDiscountCents(
requested,
loyaltyBalance,
afterPromo
);
loyaltyPointsUsed = loyaltyService.pointsForDiscount(loyaltyDiscount);
}
const total = Math.max(0, afterPromo - loyaltyDiscount);
const pointsEarned =
userId && total > 0 ? loyaltyService.calcEarnedPoints(total) : 0;
return {
subtotal,
promoDiscount,
loyaltyDiscount,
loyaltyPointsUsed,
loyaltyPointsUsedDisplay: loyaltyPointsUsed,
loyaltyBalance,
pointsEarned,
total,
promo: promo
? {
code: promo.code,
description: promo.description,
discount_type: promo.discount_type,
discount_value: promo.discount_value,
expires_at: promo.expires_at,
}
: null,
promoError,
};
}
module.exports = { buildCartPricing };