Jump to content
McKay Development

getOffer method callback question.


Recommended Posts

Posted (edited)

I am hosting express server with steam accounts intstances abd currently having troubles with getOffer method callback. Im not experienced enough to work with callbacks, and google answers are not really suited for my problem, so I would like to ask your help here. 

The code below is the functions that is executed on a get request. It calls custom function inside account instance's

app.get('/tradeOffer', auth, async (req, res) => {
    let { offerID, username } = req.query;
    await accounts[username].getOffer(offerID)
    .then(offer => {console.log("Offer", offer)})
    .catch(error => console.log(error))
    res.status(200).json()
})

 

This code is a snippet of a methods inside account's instance

getOffer = async (offerID) => {
      console.log("Getting trade offer", offerID);
      this.manager.getOffer(offerID, (err, offer) => {
          if(err) return err;
          return offer;
      })
  }

 

The question is - how do I respond, lets say, with an offer ID on a request?

Thanks in advance

Edited by TSecret
spelling
Posted

Firstly, your getOffer function is incorrect. It should look something like this:

  getOffer = (offerID) => {
      return new Promise((resolve, reject) => {
          console.log("Getting trade offer", offerID);
          this.manager.getOffer(offerID, (err, offer) => {
              if(err) return reject(err);
              resolve(offer);
          });
      });
  }

I'm not super familiar with express, but I would imagine that you'd do something like this:

app.get('/tradeOffer', auth, async (req, res) => {
    let { offerID, username } = req.query;
    await accounts[username].getOffer(offerID)
    .then(offer => {console.log("Offer", offer); res.status(200).json({id: offer.id}); })
    .catch(error => console.log(error))
})

 

Posted
On 10/19/2020 at 10:16 PM, Dr. McKay said:

Firstly, your getOffer function is incorrect. It should look something like this:


  getOffer = (offerID) => {
      return new Promise((resolve, reject) => {
          console.log("Getting trade offer", offerID);
          this.manager.getOffer(offerID, (err, offer) => {
              if(err) return reject(err);
              resolve(offer);
          });
      });
  }

I'm not super familiar with express, but I would imagine that you'd do something like this:


app.get('/tradeOffer', auth, async (req, res) => {
    let { offerID, username } = req.query;
    await accounts[username].getOffer(offerID)
    .then(offer => {console.log("Offer", offer); res.status(200).json({id: offer.id}); })
    .catch(error => console.log(error))
})

 

Yep, that works. Thank you!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...