| Total Complexity | 4 |
| Complexity/F | 1.33 |
| Lines of Code | 32 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { db } from "./db.js" |
||
| 2 | |||
| 3 | |||
| 4 | const apiKey = { |
||
| 5 | keys: [], |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Gets all active api keys from |
||
| 9 | * DB and stores in the keys array |
||
| 10 | */ |
||
| 11 | getActiveFromDB: async function() { |
||
| 12 | const result = await db.queryNoArgs(`CALL active_api_keys();`); |
||
| 13 | this.keys = result[0].map((elem) => { |
||
| 14 | return elem.key; |
||
| 15 | }) |
||
| 16 | }, |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Returns true if the key is valid and active |
||
| 20 | * @param {String} apiKey |
||
| 21 | * @returns {Promise<Boolean>} |
||
| 22 | */ |
||
| 23 | checkOne: async function(apiKey) { |
||
| 24 | if (this.keys.length === 0) { |
||
| 25 | await this.getActiveFromDB(); |
||
| 26 | } |
||
| 27 | return this.keys.includes(apiKey); |
||
| 28 | }, |
||
| 29 | |||
| 30 | }; |
||
| 31 | |||
| 32 | export default apiKey; |
||
| 33 |