I've been trying to figure out how to make an inventory system that shows the whole list of that categories items + a users quantity of that item, for example:
if someone does >inv fruits
, it would show:
- apple - 0
- banana - 1
- orange - 3
if they did >inv candy
, it would show a diff list of items:
- chocolate - 2
- lollipop - 0
- skittles - 0
I store the user_id
, category
, item
and quantity
in my database table and I've got the list of items in a category stored in a JSON file.
Right now I've only figured out how to pull the item and quantity that a user has from the database but how would I show the list of items and match the name of item to quantity like the examples above?
CODE SO FAR:
const ValidGroup = args[0];
getInventory(user_id = `${message.author.id}`, group_name = `${ValidGroup}`).then(([rows]) => {
const InvEmbed = new MessageEmbed()
.setAuthor(`${message.author.username} | Inventory`)
.setTimestamp();
let cardString = " ";
Object.keys(rows).forEach(function (key) {
//GET DATA
const row = rows[key];
let cardCode = row.card_name;
let cardQuan = row.quanity;
//CARD ARRAY FORMAT
let cardArray = `${Code} | ${CardFullName} - ${cardQuan}`
let invArray = cardArray.split("\n")
cardString += `\n${invArray}`
});
InvEmbed.setDescription(cardString);
message.channel.send({ embeds: [InvEmbed] });
});