(key)
| 17 | } |
| 18 | |
| 19 | get(key) { |
| 20 | return db.AuthCache.findOne({ |
| 21 | where: { key }, |
| 22 | }) |
| 23 | .then((cache) => { |
| 24 | if (!cache || !cache.createdAt) { |
| 25 | return new Promise((resolve) => resolve({})); |
| 26 | } |
| 27 | this.delete(key); |
| 28 | const timeDiff = moment().diff(cache.createdAt, "minutes"); |
| 29 | // update this to match updateInterval from oneaccount library |
| 30 | // if it is changed (default value is 1 minute) |
| 31 | if (timeDiff > 1) { |
| 32 | return new Promise((resolve) => resolve({})); |
| 33 | } |
| 34 | return new Promise((resolve) => resolve(cache.toJSON().user)); |
| 35 | }) |
| 36 | .catch(() => { |
| 37 | // this operation shouldn't stop what else is running |
| 38 | return new Promise((resolve) => resolve({})); |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | delete(key) { |
| 43 | return db.AuthCache.destroy({ where: { key } }) |
no test coverage detected