From d6745b661f6b6fe24e1f1f074facb20892635d0e Mon Sep 17 00:00:00 2001 From: TheTrunk Date: Thu, 27 Jul 2023 12:03:08 +0700 Subject: [PATCH] get specific message --- src/routes.js | 3 +++ src/services/permanentMessagesService.js | 28 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/routes.js b/src/routes.js index f65d775..eb6bee7 100644 --- a/src/routes.js +++ b/src/routes.js @@ -47,6 +47,9 @@ module.exports = (app) => { app.get('/fluxmessages/stats', cache('15 minutes'), (req, res) => { permanentMessages.apiStatsMessages(req, res); }); + app.get('/fluxmessages/get/:hash?/:txid?', cache('1 minute'), (req, res) => { + permanentMessages.apiStatsMessages(req, res); + }); app.get('/kadena/nodes', cache('1 minute'), (req, res) => { kadenaService.getKadenaNodes(req, res); diff --git a/src/services/permanentMessagesService.js b/src/services/permanentMessagesService.js index f3e1a6b..305e9b4 100644 --- a/src/services/permanentMessagesService.js +++ b/src/services/permanentMessagesService.js @@ -160,6 +160,33 @@ async function apiStatsMessages(req, res) { } } +async function apiGetMessage(req, res) { + try { + let { hash } = req.params; + hash = hash || req.query.hash; + let { txid } = req.params; + txid = txid || req.query.txid; + const database = db.db(config.database.flux.database); + const query = { + hash, + txid, + }; + const projection = { + projection: { + _id: 0, + }, + }; + // return latest fluxnode round + const response = await serviceHelper.findOneInDatabase(database, collection, query, projection); + const resMessage = serviceHelper.createDataMessage(response); + res.json(resMessage); + } catch (error) { + const errMessage = serviceHelper.createErrorMessage(error.message, error.name, error.code); + res.json(errMessage); + log.error(error); + } +} + async function bootstrapFluxCollection() { const database = db.db(config.database.flux.database); @@ -194,4 +221,5 @@ module.exports = { apiAllMessages, apiMissingMessages, apiStatsMessages, + apiGetMessage, };