Files
fabric_trade_server/dist/common/utils/check-rass.js
T
mohmdsdgandCursor 345a4a4708 Add SMS OTP, harden auth, and fix order/checkout server bugs.
Ship 4-digit OTP with rate-limit attempts, Tehran-safe expiry/rass math, larger JSON body limit for check images, and safer order pricing/status guards. Include rebuilt dist for prebuilt deploy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 14:55:26 +03:30

39 lines
1.4 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateCheckRass = calculateCheckRass;
const tehran_time_1 = require("./tehran-time");
function calculateCheckRass(checks, baseDate = new Date()) {
if (checks.length === 0) {
return {
checkCount: 0,
totalAmount: 0,
nearestDueDate: null,
farthestDueDate: null,
rassDays: 0,
rassDate: null,
};
}
const base = (0, tehran_time_1.tehranCalendarDay)(baseDate);
let totalAmount = 0;
let weightedDays = 0;
const dueDates = [];
for (const check of checks) {
const due = (0, tehran_time_1.calendarDayOf)(check.dueDate);
dueDates.push(due);
const days = Math.max(0, (0, tehran_time_1.diffInDays)(base, due));
totalAmount += check.amount;
weightedDays += check.amount * days;
}
const rassDays = totalAmount > 0 ? Math.round(weightedDays / totalAmount) : 0;
const rassDate = (0, tehran_time_1.addDays)(base, rassDays);
dueDates.sort((a, b) => a.getTime() - b.getTime());
return {
checkCount: checks.length,
totalAmount,
nearestDueDate: dueDates[0]?.toISOString() ?? null,
farthestDueDate: dueDates[dueDates.length - 1]?.toISOString() ?? null,
rassDays,
rassDate: rassDate.toISOString(),
};
}
//# sourceMappingURL=check-rass.js.map