const mongoose = require('mongoose'); const defaultGuildData = { items: [{ name: 'Wallet', type: 'wallet', description: '`/wallet view` to view wallet', cash: 0.00, ID: { firstname: '', lastname: '', dob: '', addr: '', } }], lastWork: new Date('2000-01-01T00:00:00') // garantee's they can work right after inventory create, } let inventorySchema = mongoose.Schema({ inventory: { userID: String, guilds: {}, } }); inventorySchema.methods.createInventory = function (userID, guildID) { this.inventory.userID = userID; this.inventory.guilds = {}; this.inventory.guilds[guildID] = defaultGuildData; }; inventorySchema.methods.addItem = function (guildID, item) { this.inventory.guilds[guildID].items.push(item); }; /* This function is to add a new guild specific inventory to an already existing inventory document or can be used to reset a data back to default */ function addInventory(guilds, guildID, userID, client) { let updatedGuilds = guilds; updatedGuilds[guildID] = defaultGuildData; client.dbo.collection("inventories").updateOne({"inventory.userID":userID}, {$set: {"inventory.guilds": updatedGuilds}}, function(err, res) { if (err) return false }) return true } module.exports = { Inventory: mongoose.model('Inventory', inventorySchema), addInventory: addInventory, };