(req, res)
| 73 | * @param res {Object} - Express response object |
| 74 | */ |
| 75 | const fetchPurgedCacheMetadata = async (req, res) => { |
| 76 | try { |
| 77 | const { id } = req.userData; |
| 78 | const logs = await logsQuery.fetchCacheLogs(id); |
| 79 | if (logs.length !== 0) { |
| 80 | const latestCacheMetadata = logs[logs.length - 1]; |
| 81 | const { timestamp } = latestCacheMetadata; |
| 82 | return res.json({ |
| 83 | message: "Purged cache metadata returned successfully!", |
| 84 | remainingCount: MAX_CACHE_PURGE_COUNT - logs.length, |
| 85 | timeLastCleared: timestamp._seconds, |
| 86 | }); |
| 87 | } else if ((await logsQuery.fetchLastAddedCacheLog(id)).length !== 0) { |
| 88 | const lastLog = await logsQuery.fetchLastAddedCacheLog(id); |
| 89 | const { timestamp } = lastLog[0]; |
| 90 | return res.json({ |
| 91 | message: "Purged cache metadata returned successfully!", |
| 92 | remainingCount: MAX_CACHE_PURGE_COUNT, |
| 93 | timeLastCleared: timestamp._seconds, |
| 94 | }); |
| 95 | } else { |
| 96 | return res.json({ |
| 97 | message: "No cache is cleared yet", |
| 98 | remainingCount: MAX_CACHE_PURGE_COUNT, |
| 99 | }); |
| 100 | } |
| 101 | } catch (error) { |
| 102 | logger.error(`Error while fetching cache metadata: ${error}`); |
| 103 | return res.boom.serverUnavailable(SOMETHING_WENT_WRONG); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | module.exports = { |
| 108 | purgeCache, |
nothing calls this directly
no outgoing calls
no test coverage detected