5.0.0 dev v3 channel / data collection tests

This commit is contained in:
SowinskiBraeden committed 2023-03-07 18:58:38 -08:00
1 parent 0bee311e22
commit a99335ef10
7 files changed
+301 -99

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
const mongoose = require('mongoose');
let userSchema = mongoose.Schema({
user: {
userID: String,
guilds: {}
},
});
userSchema.methods.createUser = function (userID, guildID, startingBalance, cash) {
this.user.userID = userID;
this.user.guilds = {};
this.user.guilds[guildID] = {
bankAccount: {
balance: startingBalance,
cash: cash,
},
faction: "",
gamertag: ""
};
};
/*
This function is to add a new guild specific user to an already existing
user document
or
can be used to reset a data back to default
*/
function addUser(guilds, guildID, userID, client, startingBalance) {
let updatedGuilds = guilds;
updatedGuilds[guildID] = {
bankAccount: {
balance: startingBalance,
cash: 0.00,
}
}
client.dbo.collection("users").updateOne({"user.userID":userID}, {$set: {"user.guilds": updatedGuilds}}, function(err, res) {
if (err) return false
})
return true
}
module.exports = {
User: mongoose.model('User', userSchema),
addUser: addUser,
};