42 lines
958 B
JavaScript
42 lines
958 B
JavaScript
const mongoose = require('mongoose');
|
|
|
|
let bankSchema = mongoose.Schema({
|
|
banking: {
|
|
userID: String,
|
|
guilds: {}
|
|
}
|
|
});
|
|
|
|
bankSchema.methods.createBank = function (userID, guildID, startingBalance) {
|
|
this.banking.userID = userID;
|
|
const newGuild = {
|
|
account: {
|
|
balance: startingBalance,
|
|
cash: 0.00,
|
|
}
|
|
};
|
|
this.bank.guilds[guildID] = newGuild
|
|
};
|
|
|
|
// This function is to add a new guild specific inventory to an already existing
|
|
// inventory document
|
|
function addBank(guilds, guildID, userID, client, startingBalance) {
|
|
let updatedGuilds = guilds;
|
|
updatedGuilds[guildID] = {
|
|
account: {
|
|
balance: startingBalance,
|
|
cash: 0.00,
|
|
}
|
|
}
|
|
|
|
client.dbo.collection("banking").updateOne({"banking.userID":userID}, {$set: {"banking.guilds": updatedGuilds}}, function(err, res) {
|
|
if (err) return false
|
|
})
|
|
return true
|
|
}
|
|
|
|
module.exports = {
|
|
Bank: mongoose.model('Bank', bankSchema),
|
|
addBank: addBank,
|
|
};
|