created API For Aplication Absensi

This commit is contained in:
2025-10-14 14:08:11 +07:00
commit 96d206d892
56 changed files with 6533 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
const db = require('../../../../models/migration')
const Balance = db.Balance
async function updateBalance(user_id, type, amount, t) {
if (!['income', 'expanse', 'debt', 'receivable'].includes(type)) return;
const [balance, created] = await Balance.findOrCreate({
where: { user_id, type },
defaults: { amount: 0 },
transaction: t,
});
const operation = type === 'expanse' ? -1 : 1;
await balance.increment('amount', {
by: amount * operation,
transaction: t
});
await balance.reload({ transaction: t });
}