diff --git a/routes/adminroutes.js b/routes/adminroutes.js index ff3cfed5..13ed1f97 100644 --- a/routes/adminroutes.js +++ b/routes/adminroutes.js @@ -90,7 +90,7 @@ router.post("/adminlogin", async function (req, res, next) { console.log("admin : ", admin); if (!admin) { - return res.status(400).json({ + return res.status(404).json({ success: true, message: "Admin don't exist against this username", }); @@ -98,7 +98,7 @@ router.post("/adminlogin", async function (req, res, next) { const validPassword = bcrypt.compareSync(req.body.password, admin.password); // user password is stored as hashed if (!validPassword) { - return res.status(400).json("Incorrect password entered"); + return res.status(403).json("Incorrect password entered"); } let payload; diff --git a/routes/afterDeploymentroutes.js b/routes/afterDeploymentroutes.js index 453b45b5..0198abdd 100644 --- a/routes/afterDeploymentroutes.js +++ b/routes/afterDeploymentroutes.js @@ -29,16 +29,27 @@ router let contractHash = req.body.contractHash.toLowerCase(); let packageHash = req.body.packageHash.toLowerCase(); - var newpair = new hashesofpairsModel({ + let pairData = await hashesofpairsModel.findOne({ contractHash: contractHash, packageHash: packageHash, }); - await hashesofpairsModel.create(newpair); + if (pairData == null) { + var newpair = new hashesofpairsModel({ + contractHash: contractHash, + packageHash: packageHash, + }); + await hashesofpairsModel.create(newpair); - return res.status(200).json({ - success: true, - message: "Pair's Contract and Package Hash are Succefully stored.", - }); + return res.status(200).json({ + success: true, + message: "Pair's Contract and Package Hash are Succefully stored.", + }); + } else { + return res.status(406).json({ + success: false, + message: "These Pair's Contract and Package Hash are already added.", + }); + } } catch (error) { console.log("error (try-catch) : " + error); return res.status(500).json({ @@ -67,16 +78,27 @@ router let contractHash = req.body.contractHash.toLowerCase(); let packageHash = req.body.packageHash.toLowerCase(); - var newpair = new allcontractsDataModel({ + let contractsData = await allcontractsDataModel.findOne({ contractHash: contractHash, packageHash: packageHash, }); - await allcontractsDataModel.create(newpair); + if (contractsData == null) { + var newpair = new allcontractsDataModel({ + contractHash: contractHash, + packageHash: packageHash, + }); + await allcontractsDataModel.create(newpair); - return res.status(200).json({ - success: true, - message: "Contract and Package Hash are Succefully stored.", - }); + return res.status(200).json({ + success: true, + message: "Contract and Package Hash are Succefully stored.", + }); + } else { + return res.status(406).json({ + success: false, + message: "These Contract and Package Hash are already stored.", + }); + } } catch (error) { console.log("error (try-catch) : " + error); return res.status(500).json({ @@ -96,15 +118,23 @@ router message: "tokensList not found in the request Body.", }); } - let newData = new tokensListModel({ - data: req.body.tokensList, - }); - await tokensListModel.create(newData); + let result = await tokensListModel.find({}); + if (result.length == 0) { + let newData = new tokensListModel({ + data: req.body.tokensList, + }); + await tokensListModel.create(newData); - return res.status(200).json({ - success: true, - message: "Token List Data SuccessFully Saved.", - }); + return res.status(200).json({ + success: true, + message: "Token List Data SuccessFully added.", + }); + } else { + return res.status(406).json({ + success: false, + message: "Tokens List Data already added.", + }); + } } catch (error) { console.log("error (try-catch) : " + error); return res.status(500).json({