Problem calling a backend function

Hi everyone, I would be really happy if someone understand what’s the problem here…

I get this error everytime that I call my function from Backend :
Uncaught (in promise) TypeError: (0 , a.sending) is not a function

Here is the code :

FRONT END

import {sending} from 'backend/aModule';

//...

if (pricingPlans.length !== 0) {
        membership = planName.toString()
        price = $w('#text68').text
 let A = $w("#text30").text
 let B = $w("#input1").value
 let C =  $w("#input3").value
 let D = $w("#input4").value
        sending(A, membership, B, C, price, D)
    })
    .catch(error => {
        console.log(error);
    });

aModule.jsw

import wixUsersBackend from 'wix-users-backend';

//...

function sending (programme, membre, nom, email, prix, phone) {
 
 let mailID = "e3e5d513-4293-42e3-a28b-d0d4fb6cca5c"

wixUsersBackend.emailUser('interested', mailID, {
  variables: {
    program: programme,
    membership: membre,
    name: nom,
    email: email,
    price: prix,
    phone: phone
}})
  .catch( (error) => {
    console.log(error);
  } );

}

Thank youuuu !

See in red :

export function sending (programme, membre, nom, email, prix, phone) {
 
 let mailID = "e3e5d513-4293-42e3-a28b-d0d4fb6cca5c"

return wixUsersBackend.emailUser('interested', mailID, {
//etc....

Thank you ! I don’t have the problem anymore, however now I got undefined for the value of response , and no email is triggered.

My full updated code :

aModule.jsw

import wixUsersBackend from 'wix-users-backend';

//...

export function sending (membership, price, program, nom, email, phone) {
 
 let mailID = "e3e5d513-4293-42e3-a28b-d0d4fb6cca5c"

return wixUsersBackend.emailUser('interested', mailID, {
  variables: {
    program: program,
    membership: membership,
    name: nom,
    email: email,
    price: price,
    phone: phone
}})
  .catch( (error) => {
    console.log(error);
  } );

}

Front-end

import wixUsers from 'wix-users';
import {sending} from 'backend/aModule';

//...


 var membership;
 var price;
 
export function button3_click(event) {
 let user = wixUsers.currentUser
 
        user.getPricingPlans()
            .then( (pricingPlans) => {
                  let firstPlan = pricingPlans[0];
                  let planName = firstPlan.name;
                  
                      if (pricingPlans.length !== 0) {
                             membership = planName.toString()
                             price = $w('#text68').text
                             let program = $w("#text30").text
                             let nom = $w("#input1").value
                             let email =  $w("#input3").value
                             let phone = $w("#input4").value
                             sending(membership, price, program, nom, email, phone)
                                    .then(response => console.log(response))
                         } else {
                             membership = "no membership"
                             price = $w('#text68').text
                             let program = $w("#text30").text
                             let nom = $w("#input1").value
                             let email =  $w("#input3").value
                             let phone = $w("#input4").value
                            sending(membership, price, program, nom, email, phone)
                                .then(response => console.log(response))
                           }})
                      .catch(error => {
                             console.log(error);
                             membership = "no membership"
                             price = $w('#text68').text
                             let program = $w("#text30").text
                             let nom = $w("#input1").value
                             let email =  $w("#input3").value
                            let phone = $w("#input4").value
                            sending(membership, price, program, nom, email, phone)
                                       .then(response => console.log(response))
    });

Thank you so much !

See in red

  1. import { sending } from 'backend/aModule .jsw ’ ;

  2. return sending(membership, price, program, nom, email, phone)

and to make it written better with no extra code:

import wixUsers from 'wix-users';
import {sending} from 'backend/aModule.jsw';
//...
 var membership;
 var price;
export function button3_click(event) {
 let user = wixUsers.currentUser;
 user.getPricingPlans()
.then( (pricingPlans) => {
 let firstPlan = pricingPlans[0];
 let planName = firstPlan.name;
pricingPlans.length !== 0 ?  membership = planName.toString() : membership = "no membership";
price = $w('#text68').text;
let [program, nom, email, phone]  = [$w("#text30").text, $w("#input1").value, $w("#input3").value, $w("#input4").value];
return sending(membership, price, program, nom, email, phone);
 })
.then(response => console.log(response));
}

Wahou that’s so awesome, I will try that and study it, thank you :slight_smile: Hopefully that will work, i will let you know, thanks again!

you’re welcome :slight_smile:

@jonatandor35 Thanks again :slight_smile: Actually, on the first version, I added a .catch() function in order to run sending() with different values if no user is currently logged in.
With your version, I end up having the error Uncaught(in promise) no user is currently logged in . Is there any elegant way to code what I need without relying on .catch() ?
Thanks !

Or maybe using .catch() and copy the code is elegant enough :smiley: What would be your opinion ?

@loppe I don’t understand your code fro the catch. If the promise failed from any reason , you shouldn’t try to repeat sending it, because you’ll get an error or a rejection again.