Skip to content

Commit

Permalink
Update server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
piano-man authored Nov 22, 2018
1 parent 0b2674e commit 09818d0
Showing 1 changed file with 0 additions and 99 deletions.
99 changes: 0 additions & 99 deletions poolpal_backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,102 +256,3 @@ app.get('/deleteRequest/:requestid',function(req,res){
app.get('/storerating/:emailid/:rating',function(req,res){
console.log(req.params.rating)
})











///////////////////////////////////////////////////////////////////////////////////////////////////////

app.get('/getHospitals',async function(req,res){
let rel = new Array()
let db = await mongo.connect(url)
var cursor = await db.collection('hospitals').find({})
cursor.forEach(function(doc,err){
rel.push({"id":doc.id,
"pbkey":doc.pbkey})
})
setTimeout(function()
{
console.log(rel)
res.send({"result":rel})
},3000)

})

app.post('/decryptrecord',async function(req,res){
var pvtkey = req.body.pvtkey
var record = req.body.data
var fans = await decrypt(pvtkey.toString(),record.toString());
console.log(fans);
res.send({"decryptedData":fans})

})

app.post('/encryptrecord',async function(req,res){
var pbkey = req.body.pbkey;
var record = req.body.data;
var frec = JSON.stringify(record)
var ans = await encrypt(pbkey.toString(),frec.toString());
console.log("in here")
console.log(ans)
res.send({"encryptedData":ans})

})

app.post('/hospitalencrypt/:patientid/:hospitalid',async function(req,res){
console.log("working")
var publicKey
var hid = req.params.hospitalid
var patid = req.params.patientid;
var pat_record = req.body.pat;
console.log(req.body.pat)
var rel = await mapids(hid,patid)
console.log(rel)
var pbkey = await getPublicKey(patid);
console.log(pbkey)
var frec = JSON.stringify(pat_record)
//console.log(JSON.stringify(pat_record))
console.log(frec.toString())
var enc_record = await encrypt(pbkey.toString(),frec.toString());
console.log(enc_record);
res.send({"result":enc_record})
})

app.get('/hospitallogin/:id/:pwd',async function(req,res){
var id = req.params.id
var pwd = req.params.pwd
var result = await checkHospitalValidity(id,pwd)
res.send({"result":result})
})

app.post('/storehospitalkeys/:patientid/:pwd',function(req,res){
var patid = req.params.patientid;
var password = req.params.pwd;
console.log(patid)
console.log(req.body.value)
var record = {
id:patid,
login_password:password,
pbkey:req.body.pbkey,
pvtkey:req.body.value
}
mongo.connect(url,function(err,db){
db.collection('hospitals').insertOne(record,function(err,result){
if(err)
{
console.log(err)
}
else{
res.send({"response":"success"})
}
})
})

})

0 comments on commit 09818d0

Please sign in to comment.