refactor/remove mongoose + quality of life
This commit is contained in:
26 files changed
+235
-329
No files matched your search
@@ -0,0 +1,43 @@
|
||||
module.exports = {
|
||||
createUser: async (userID, initialGuildID, startingBalance, client) => {
|
||||
let User = {
|
||||
user: {
|
||||
userID: userID,
|
||||
guilds: {}
|
||||
}
|
||||
};
|
||||
|
||||
User.user.guilds[initialGuildID] = {
|
||||
balance: startingBalance,
|
||||
lastIncome: new Date('2000-01-01T00:00:00'),
|
||||
};
|
||||
|
||||
await client.dbo.collection("users").insertOne(User, (err, res) => {
|
||||
if (err) {
|
||||
client.error(`Failed to create user - ${err}`);
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
return User;
|
||||
},
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
addUser: async (guilds, newGuildID, userID, client, startingBalance) => {
|
||||
let updatedGuilds = guilds;
|
||||
updatedGuilds[newGuildID] = {
|
||||
balance: startingBalance,
|
||||
lastIncome: new Date('2000-01-01T00:00:00')
|
||||
}
|
||||
|
||||
await client.dbo.collection("users").updateOne({"user.userID":userID}, {$set: {"user.guilds": updatedGuilds}}, (err, res) => {
|
||||
if (err) return false
|
||||
})
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user