Skip to content

Commit

Permalink
Add validations to search functionality blockId and blockRange
Browse files Browse the repository at this point in the history
Signed-off-by: ArchanaArige <nigam_archana@yahoo.co.in>
  • Loading branch information
ArchanaArige committed May 29, 2023
1 parent 6cbccae commit e386317
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions app/rest/platformroutes.ts
Expand Up @@ -4,6 +4,8 @@

import * as requtil from './requestutils';



/**
*
*
Expand Down Expand Up @@ -190,15 +192,18 @@ export async function platformroutes(
router.get('/fetchDataByBlockNo/:channel_genesis_hash/:blockNo', (req, res) => {
const blockNo = parseInt(req.params.blockNo);
const channel_genesis_hash = req.params.channel_genesis_hash;
if (!isNaN(blockNo) && channel_genesis_hash) {
proxy.fetchDataByBlockNo(req.network, channel_genesis_hash, blockNo).then((data: any) => {
if (data != "response_payloads is null") {
res.send({ status: 200, data: data });
}
else{
} else {
res.send({ status: 404, data: "Block not found" });
}
});
});
} else {
return requtil.invalidRequest(req, res);
}
});

/**
* *
Expand All @@ -210,21 +215,25 @@ export async function platformroutes(
const startBlockNo = parseInt(req.params.startBlockNo);
const endBlockNo = parseInt(req.params.endBlockNo);
const channel_genesis_hash = req.params.channel_genesis_hash;
if (startBlockNo < endBlockNo) {
if (
startBlockNo <= endBlockNo &&
startBlockNo >= 0 &&
endBlockNo >= 0 &&
!isNaN(startBlockNo) &&
!isNaN(endBlockNo) &&
channel_genesis_hash
) {
proxy.fetchDataByBlockRange(req.network, channel_genesis_hash, startBlockNo, endBlockNo).then((data: any) => {
if (data != "response_payloads is null") {
res.send({ status: 200, data: data });
}
else{
} else {
res.send({ status: 404, data: "Block(s) not found" });
}
});
}
else {
} else {
return requtil.invalidRequest(req, res);
}

});
});


/**
Expand Down

0 comments on commit e386317

Please sign in to comment.