mecjos
1 month ago

Using Condition in Promise

Posted 1 month ago by mecjos

Hi. I want to use condition for promise response.. How Can I use conditions in promise? My codes are as follows. That doesn't work...

this.$store.dispatch('CreateJob', params).then(response => {
        if (response.warnings.length > 0) {
          this.$q.notify({
            type: 'negative',
            message: 'Some warnings.',
            position: 'top',
            timeout: 2000
          })
        }
      }).then(response => {
        if (response.someOtherWarning.length > 0) {
          this.$q.notify({
            type: 'negative',
            message: 'Some other warnings.',
            position: 'top',
            timeout: 2000
          })
        }
      }).then(response => {
        if (response.job.length > 0) {
          this.$q.notify({
            type: 'positive',
            message: 'Well done.',
            position: 'top',
            timeout: 2000
          })
        }
      }).catch(error => {
        this.$q.notify({
          type: 'negative',
          message: error.response.data.message,
          position: 'top',
          timeout: 2000
        })
      })

dispatch('createJob') runs a promise..

Please sign in or create an account to participate in this conversation.