Skip to content

Commit

Permalink
get specific message
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrunk committed Jul 27, 2023
1 parent cb49d92 commit d6745b6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/services/permanentMessagesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -194,4 +221,5 @@ module.exports = {
apiAllMessages,
apiMissingMessages,
apiStatsMessages,
apiGetMessage,
};

0 comments on commit d6745b6

Please sign in to comment.