node.js - Async table query in sequelize getter method -


i have sequelize instance method performs db query:

getpropertydays() {     const querystring = `       select         state       property_days               date(day) = curdate() ,         property_id = :propertyid;`;      const replacements = {propertyid: this.id};     return this.sequelize.query(querystring, {replacements: replacements, type: sequelize.querytypes.select});   }, 

that gets called getter:

gettermethods: {   propertystate() {     var self = this;     const blockedday = 'x';     const unavailableday = 'u';      this.getpropertydays().then(function(result) {       var state = result[0]['state'];        if (self.prospect || state == unavailableday) {         return 'unavailable';       }       if (state == blockedday) {         return 'occupied';       }       else {         return 'available';       }     });   } }, 

the problem result returned getter undefined because he's not able solve promise before returning.

since don't have model table, how can solve issue? been around 1 day already!

thanks lot.

won't returning promise returned this.getpropertydays trick?

gettermethods: {   propertystate() {     var self = this;     const blockedday = 'x';     const unavailableday = 'u';      return this.getpropertydays().then(function(result) {       var state = result[0]['state'];        if (self.prospect || state == unavailableday) {         return 'unavailable';       }       if (state == blockedday) {         return 'occupied';       }       else {         return 'available';       }     });   } }, 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -