UNPKG

saksh-wallet

Version:

A Node.js library for managing user wallets, including functionalities for crediting, debiting, and converting currencies, as well as retrieving balances and transaction reports.

39 lines (31 loc) 1.04 kB
const EventEmitter = require('events'); const mongoose = require('mongoose'); const Transaction = require('./models/Transaction'); const WalletUser = require('./models/WalletUser'); const RecurringPayment = require('./models/RecurringPayment'); class SakshUserManagement { constructor(userModel = WalletUser) { this.User = userModel; } async sakshSetAdmin(adminUserId) { this.adminUserId = adminUserId; } async sakshSetLimit(nolimit) { this.nolimit = nolimit; } async sakshGetBalance(userId, currency) { let user = await this.User.findOne({ userId }); if (!user) { user = new this.User({ userId }); } return user.balances.get(currency) || 0; } async sakshGetBalanceSummary(userId) { let user = await this.User.findOne({ userId }); if (!user) { user = new this.User({ userId }); } return user.balances; } } module.exports = SakshUserManagement;