Commit 9ab56074 authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'all-NFT-details-collection-add' into 'master'

New collections

See merge request !44
parents b1c22fc3 60a371d2
const mongoose = require("mongoose");
const AssetCodeWithPractitioner = new mongoose.Schema({
assetcode: String,
to: String,
});
module.exports = mongoose.model(
"AssetCodeWithPractitioner",
AssetCodeWithPractitioner
);
const mongoose = require("mongoose");
const AssetKeyFullInfo = new mongoose.Schema({
assetcode: String,
key: String,
to: String,
cid: String,
});
module.exports = mongoose.model("AssetKeyFullInfo", AssetKeyFullInfo);
...@@ -13,6 +13,7 @@ const RSAEncrypt = require("./../../services/rsaEncoder"); ...@@ -13,6 +13,7 @@ const RSAEncrypt = require("./../../services/rsaEncoder");
const GenerateAESKey = require("./../../services/aesKeyGenerator"); const GenerateAESKey = require("./../../services/aesKeyGenerator");
const EncryptionService = require("./../../services/encryptionservice"); const EncryptionService = require("./../../services/encryptionservice");
const AssetKey = require("./../../model/stellar/assetkeys"); const AssetKey = require("./../../model/stellar/assetkeys");
const AssetKeyFullInfo = require("./../../model/stellar/assetKeyFull");
const CreateTrustline = require("./../../services/trustlineCreator"); const CreateTrustline = require("./../../services/trustlineCreator");
const GetIssuerPair = require("./../../services/getIssuerKeyPairFromDB"); const GetIssuerPair = require("./../../services/getIssuerKeyPairFromDB");
const DoManageData = require("./../../services/manageDataForAsset"); const DoManageData = require("./../../services/manageDataForAsset");
...@@ -416,50 +417,79 @@ router.post("/", async (req, res) => { ...@@ -416,50 +417,79 @@ router.post("/", async (req, res) => {
decryptedPractitionerKey, decryptedPractitionerKey,
DecryptWithServerKey(issuerKeyPair.issuerKey) DecryptWithServerKey(issuerKeyPair.issuerKey)
) )
.then((success) => { .then(async (success) => {
if (success) { if (success) {
console.log( console.log(
"Payment operation from patient to practitioner success" "Payment operation from patient to practitioner success"
); );
//Update the NFT req collection //add to the AssetKeyFullInfoDB
UpdateNFTRequestStatus(decryptedAssetCode) const assetFullObj = new AssetKeyFullInfo({
.then((success) => { assetcode: decryptedAssetCode,
if (success) { key: encodedAesKey,
res.status(200).json({ cid: ipfsContentCID,
message: to: decryptedPractitionerKey,
"NFT EHR issued successfully", });
});
console.log( try {
"/patient/createnft - NFT creation and sharing success" const saveInFullDB =
); await assetFullObj.save();
} else { console.log(
console.log( "Full details added to collection"
"NFT Request update failed " );
); //Update the NFT req collection
console.log( UpdateNFTRequestStatus(decryptedAssetCode)
"/patient/createnft - NFT creation and sharing failed" .then((success) => {
); if (success) {
return res.status(500).json({ res.status(200).json({
message: message:
"NFT Request update failed ", "NFT EHR issued successfully",
}); });
} console.log(
}) "/patient/createnft - NFT creation and sharing success"
.catch((errorWhenUpdatingCollection) => { );
console.log( } else {
"Error updating NFT request status : ", console.log(
errorWhenUpdatingCollection "NFT Request update failed "
); );
console.log( console.log(
"/patient/createnft - NFT creation and sharing failed" "/patient/createnft - NFT creation and sharing failed"
);
return res.status(500).json({
message:
"NFT Request update failed ",
});
}
})
.catch(
(errorWhenUpdatingCollection) => {
console.log(
"Error updating NFT request status : ",
errorWhenUpdatingCollection
);
console.log(
"/patient/createnft - NFT creation and sharing failed"
);
return res.status(500).json({
message:
"Error updating NFT request status : ",
errorWhenUpdatingCollection,
});
}
); );
return res.status(500).json({ } catch (errorWhenAddingToFullInfo) {
message: console.log(
"Error updating NFT request status : ", "Adding NFT details to full info collection failed : ",
errorWhenUpdatingCollection, errorWhenAddingToFullInfo
}); );
console.log(
"/patient/createnft - NFT creation and sharing failed"
);
return res.status(500).json({
message:
"Adding NFT details to full info collection failed",
}); });
}
} else { } else {
console.log( console.log(
"NFT payment operation failed from patient to practitioner" "NFT payment operation failed from patient to practitioner"
......
const express = require("express");
const router = express.Router();
const AssetCodeWithPractitioner = require("./../../model/stellar/assetCodeWithPractitioner");
router.get("./:practitionerKey", async (req, res) => {
const practitionerKey = req.params.practitionerKey;
try {
const assetKey = await AssetCodeWithPractitioner.findOne({
to: practitionerKey,
});
console.log(assetKey);
res.status(200).json({
assetcode: assetKey.assetcode,
});
console.log(
"/practitioner/getassetcode - getting asset code for the practitioner success"
);
} catch (errorWhenGettingAssetCode) {
console.log(
"Error when getting practitioner asset code : Error : ",
errorWhenGettingAssetCode
);
console.log("/practitioner/getasssetcode - failed");
res.status(500).json({
error: "Getting all practitioners requests failed : ",
errorWhenGettingPatientRequests,
});
}
});
module.exports = router;
...@@ -5,6 +5,7 @@ const DecryptWithServerKey = require("./../../services/decryptionservice"); ...@@ -5,6 +5,7 @@ const DecryptWithServerKey = require("./../../services/decryptionservice");
const StellarSdk = require("stellar-sdk"); const StellarSdk = require("stellar-sdk");
const CreateTrustline = require("./../../services/trustlineCreator"); const CreateTrustline = require("./../../services/trustlineCreator");
const NFTRequest = require("./../../model/stellar/nftRequests"); const NFTRequest = require("./../../model/stellar/nftRequests");
const AssetCodeWithPractitioner = require("./../../model/stellar/assetCodeWithPractitioner");
const GenerateRandomAssetCode = require("./../../services/assetCodeGenerator"); const GenerateRandomAssetCode = require("./../../services/assetCodeGenerator");
require("dotenv").config(); require("dotenv").config();
...@@ -38,11 +39,31 @@ router.post("/", async (req, res) => { ...@@ -38,11 +39,31 @@ router.post("/", async (req, res) => {
}); });
try { try {
const saveRequest = await nftRequestObj.save(); const saveRequest = await nftRequestObj.save();
console.log("NFT request saved to database : " + saveRequest);
res.status(200).json({ //save the asset code details in the DB
message: "NFT request saved to database", const assetCodeVsPractitioner = new AssetCodeWithPractitioner({
assetcode: assetCode,
to: practitionerPK,
}); });
console.log("/practitioner/requestnft - requesting NFT success");
try {
const saveAssetCodeVsPrac = await assetCodeVsPractitioner.save();
console.log("NFT request saved to database : " + saveRequest);
res.status(200).json({
message: "NFT request saved to database",
});
console.log("/practitioner/requestnft - requesting NFT success");
} catch (errorWhenSavingPractitionerVsAssetCodeInDB) {
console.log(
"Error when adding asset code practitioner request to DB : ",
errorWhenSavingPractitionerVsAssetCodeInDB
);
console.log("/practitioner/requestnft - requesting NFT failed");
return res.status(500).json({
message: "Error when adding NFT request to DB : ",
errorWhenSavingPractitionerVsAssetCodeInDB,
});
}
} catch (errorWhenAddingRequestToDB) { } catch (errorWhenAddingRequestToDB) {
console.log( console.log(
"Error when adding NFT request to DB : ", "Error when adding NFT request to DB : ",
......
...@@ -63,6 +63,9 @@ app.use("/practitioner/login", practitionerLogin); ...@@ -63,6 +63,9 @@ app.use("/practitioner/login", practitionerLogin);
const treatingPatients = require("./route/practitioner-routes/get-treating-patients-route"); const treatingPatients = require("./route/practitioner-routes/get-treating-patients-route");
app.use("/practitioner/treatingPatients", treatingPatients); app.use("/practitioner/treatingPatients", treatingPatients);
const assetCodes = require("./route/practitioner-routes/get-assetcode-practitioner-route");
app.use("/practitioner/getassetcode", assetCodes);
app.listen(process.env.SERVER_PORT, () => app.listen(process.env.SERVER_PORT, () =>
console.log("Server started on port " + process.env.SERVER_PORT) console.log("Server started on port " + process.env.SERVER_PORT)
); );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment