Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
status codes changed for swagger Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed May 19, 2022
1 parent e79c299 commit e100944
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
4 changes: 2 additions & 2 deletions routes/adminroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ 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",
});
}

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;
Expand Down
70 changes: 50 additions & 20 deletions routes/afterDeploymentroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand Down

0 comments on commit e100944

Please sign in to comment.