NodeJS Promise

nodejs
products
javascript
authentication

#1

Im new to back-end developing and I have problems to find study material of moltin. Could someone help me now. I just understand the authenticate of moltin, im in trouble with promises. When I try to do anything inside the authenticate scope it says this.

"(node:5168) UnhandledPromiseRejectionWarning: Unhandled promise rejection (
rejection id: 1): TypeError: "2aef2117-b982-40ff-aa20-436fd4aafdfd}".then i
s not a function
(node:5168) [DEP0018] DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections that are not handled will ter
minate the Node.js process with a non-zero exit code."

My code:

Moltin.Authenticate().then((response) => {
  console.log('authenticated', response);
  Moltin.Products.Get('2aef2117-b982-40ff-aa20-436fd4aafdfd'.then((product) => {
    console.log(product);
  }));
});

#2

Hi @guilhermemb98

The code above doesn’t close the Get method and removing the last parentheses on that line.

Moltin.Authenticate().then((response) => {
  console.log('authenticated', response);
  
  Moltin.Products.Get('2aef2117-b982-40ff-aa20-436fd4aafdfd').then((product) => {
    console.log(product);
  });
});

Does updating this fix the issue? :slight_smile:

Please feel free to reach out if you want to talk about moltin. I’m interested to know what information you are available.


#3

Thx, that helped me. I used the get method because i wanted to test if that
was working.
I changed my code for this, and its working now.

app.get('/', function(req, res){
  const Products = Moltin.Products.All().then((products) => {
    res.render('index', {
      products: products.data
    });
  });
});

#4

I was looking for promotion system in the documentation of moltin and i
didn see the way i create the products? Can i do that in the moltin
dashboard? Or ill have to create my own HTTP request and create my Schema
to validate the promotion product?


#5

Hi @guilhermemb98

The promotions API is currently in BETA and is available via the API directly. You can see more about this in our API reference.

We don’t expect there to be any breaking changes going forward but once we’ve gathered enough feedback and people are happy with how it works, we’ll implement SDK and Dashboard support. Please feel free to add your #feedback if you’re not sure of anything.

I hope this answers your question.

Have a great day :grinning:


#6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.