Refactor sellAllProducts method in FalukantService to ensure atomic transactions for selling products, updating inventory, and handling financial transactions. Implement batch processing for sell items and enhance error handling for inventory deletions. Update updateFalukantUserMoney function to support transactions, improving consistency and reliability in financial operations.

This commit is contained in:
Torsten Schulz (local)
2025-12-20 22:04:29 +01:00
parent 533171135a
commit d801a26417
2 changed files with 145 additions and 127 deletions

View File

@@ -401,7 +401,7 @@ const updateSchema = async (models) => {
console.log('✅ Datenbankschema aktualisiert');
};
async function updateFalukantUserMoney(falukantUserId, moneyChange, activity, changedBy = null) {
async function updateFalukantUserMoney(falukantUserId, moneyChange, activity, changedBy = null, transaction = null) {
try {
const result = await sequelize.query(
`SELECT falukant_data.update_money(
@@ -418,6 +418,7 @@ async function updateFalukantUserMoney(falukantUserId, moneyChange, activity, ch
changedBy,
},
type: sequelize.QueryTypes.SELECT,
transaction: transaction || undefined,
}
);
return {