Closed attiqeurrehman closed 9 years ago
Hi @attiqeurrehman,
What kind of object is tables
?
Also can you please edit your comment and use markdown formatting for the code block, it's pretty hard to read as plain text! Just put triple-backticks on the line before and after the code, like so:
```javascript function foo() { ... } ```
Closing this for lack of response. If you still need help let me know and I'll re-open it.
Hi,
I am having trouble converting these functions into asyncawait.
function doesUserHaveAsscess(user) { var receiptsTable = tables.getTable('receipts'); // lets find all of this users receipts first receiptsTable.where({ userId: user.userId }).read({ success: function(results) { if (results.length > 0) { // check that we have a valid receipt for this user for (var i = 0; i < results.length; i++) { if (checkIsValid(results[i])) { return true; } } } // no valid receipts found - time to pay up return false; } }); }
function checkIsValid(receipt) { var receiptDate = new Date(parseInt(receipt.purchaseDateMs, 10)); var durations = { 'com.foo.weekly': day * 7, 'com.foo.monthly': day * 31 }; var expiry = receiptDate.getTime() + durations[receipt.productId]; var expiryDate = new Date(expiry); var now = new Date(); console.log(now < expiryDate, now, expiryDate); return now < expiryDate; }
Thanks, Attiqe