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
Post a Comment