0

I'm trying to understand how to properly execute async operation with google cloud functions. It's seem like I have syntax error but I'm not sure how to fix it. the rest of the code were able to compile work as intended before I added then(). please help

Error:

SyntaxError: Unexpected token )
at new Script (vm.js:51:7)
at createScript (vm.js:138:10)
at Object.runInThisContext (vm.js:199:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)

Area of possible error

if (inviterUID == partnerUID) {
  return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
  'partnerName': username,
  'browniePoints': 0
}).then(() => {
console.log('testing');
  })
})

Entire Code

exports.checkInviteRequest = functions.firestore
.document('users/{userID}/partnerInviteRequests/{inviterUID}')
.onDelete(invite => {
  const uid = invite.params.userID
  const inviterUID = invite.params.inviterUID
  const deletedInvite = invite.data.previous.data();
  const name = deletedInvite.username;
  return admin.firestore().collection('users').doc(uid).get().then(profileInfo => {
      const partnerUID = profileInfo.data().partnerUID
      const username = profileInfo.data().username

      if (inviterUID == partnerUID) {
        return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
          'partnerName': username,
          'browniePoints': 0
        }).then(() => {
          console.log('testing');
        })
      })
  })
});

1 Answer 1

1

You have closing parenthesis too much on your if statement. Specifically the last line of this block:

  if (inviterUID == partnerUID) {
    return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
      'partnerName': username,
      'browniePoints': 0
    }).then(() => {
      console.log('testing');
    })
  })

That last ) should not be there. So:

  if (inviterUID == partnerUID) {
    return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
      'partnerName': username,
      'browniePoints': 0
    }).then(() => {
      console.log('testing');
    })
  }
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your help. is there technique or software that can help me reduce these type of error?
Well... after the compiler points the problem out, I typically comment out blocks of code to see where the problem is. When the block is small enough, it's a matter of checking each parenthesis to see if it has a counter part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.