Sign in to follow this  
Harybo

Problem Promise async

Recommended Posts

hello, i need some help for my function, i make it returned a value under JSON.stringify but since it's an asynchronous function, it sends it to me with promise {result} so I can not use JSON.parse after.

If you have a solution to my problem, I do not mind

async getItemForPlayerMenu(id) {
        const playerItem = [];
        const data = await misc.query(`SELECT u.*, i.itemName, i.usable, i.itemcount FROM user_items u LEFT JOIN items i ON i.id = u.itemId WHERE u.charId = "${id}"`);
        for (const item of data) {
            if (item.charId !== id) continue;
            const v = {
                id: item.id,
                owner: item.charId,
                itemId: item.itemId,
                amount: item.amount,
                title: item.itemName,
                usable: item.usable,
                poids: item.itemcount
            }
            playerItem.push(v);
        }
        return JSON.stringify(playerItem);
    }
Promise {
  '[{"id":1,"owner":6,"itemId":1,"amount":10,"title":"Eau","usable":"Y","poids":1},{"id":2,"owner":6,"itemId":2,"amount":10,"title":"Sandwich","usable":"Y","poids":1}]' }

af20409ab9d659cc472cd735beebfaa9.png

81084312143d56c45b26e7005ff68d03.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.