From fba3fb97f108442461291bea874b669454194e72 Mon Sep 17 00:00:00 2001 From: Hammad-Mubeen Date: Thu, 30 Dec 2021 21:48:41 +0500 Subject: [PATCH] pairList added --- app.js | 2 + routes/pairslist.js | 133 +++++++++++++++++++++++++++++++++++++++++++ routes/tokenslist.js | 98 ------------------------------- 3 files changed, 135 insertions(+), 98 deletions(-) create mode 100644 routes/pairslist.js diff --git a/app.js b/app.js index 1d86163c..250cae0d 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,7 @@ const { graphqlHTTP } = require("express-graphql"); const schema = require("./graphql/schema"); var listenerRouter = require('./routes/listenerroutes'); var tokensListRouter = require('./routes/tokenslist'); +var pairsListRouter = require('./routes/pairslist'); var coinsmarketcapapiRouter = require('./routes/coinsmarketcapapi'); // view engine setup @@ -68,6 +69,7 @@ app.get("/", (req, res) => { }); app.use('/', listenerRouter); app.use('/', tokensListRouter); +app.use('/', pairsListRouter); app.use('/', coinsmarketcapapiRouter); app.use('/graphql', graphqlHTTP({ diff --git a/routes/pairslist.js b/routes/pairslist.js new file mode 100644 index 00000000..0c5c3381 --- /dev/null +++ b/routes/pairslist.js @@ -0,0 +1,133 @@ +require('dotenv').config() +var express = require('express'); +var router = express.Router(); +var pairModel=require('../models/pair'); +var hashesofpairsModel=require('../models/hashesofpairs'); + +router.route("/getpairagainsttokens").post(async function (req, res, next) { + try { + + if(!req.body.token0) + { + return res.status(400).json({ + success: false, + message: "token0 not found in the body.", + }); + } + if(!req.body.token1) + { + return res.status(400).json({ + success: false, + message: "token1 not found in the body.", + }); + } + + var pairresult= await pairModel.find({}); + if(pairresult.length==0) + { + return res.status(400).json({ + success: false, + message: "There is no pair in the database.", + }); + } + else + { + let paircontractHash=null; + for(var i=0;i