Commit 2bbbbe66 authored by Kiridena I.T.K_IT19981840's avatar Kiridena I.T.K_IT19981840

Merge branch 'user-req-acceptance-and-rejection' into 'master'

user request acceptance completed

See merge request !41
parents 453b4aac 5b953d38
...@@ -7,10 +7,14 @@ const Requests = require("./../../model/patient/request"); ...@@ -7,10 +7,14 @@ const Requests = require("./../../model/patient/request");
router.post("/", async (req, res) => { router.post("/", async (req, res) => {
//Get the payload //Get the payload
const decryptedPatientKey = req.body.patient; const decryptedPatientKey = DecryptWithServerKey(req.body.patient);
const decryptedPractitionerKey = req.body.practitionerkey; const decryptedPractitionerKey = DecryptWithServerKey(
const decryptedPractitionerSeed = req.body.practitionerseed; req.body.practitionerkey
const decryptedStatus = req.body.status; );
const decryptedPractitionerSeed = DecryptWithServerKey(
req.body.practitionerseed
);
const decryptedStatus = DecryptWithServerKey(req.body.status);
let timestamp; let timestamp;
//check the condition //check the condition
......
...@@ -2,6 +2,7 @@ import { useEffect, useState } from "react"; ...@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { LOCALBACKEND } from "../../env"; import { LOCALBACKEND } from "../../env";
import { Button, StyleSheet, View, Text } from "react-native"; import { Button, StyleSheet, View, Text } from "react-native";
import AsyncStorage from "@react-native-async-storage/async-storage"; import AsyncStorage from "@react-native-async-storage/async-storage";
import EncryptWithServerKey from "../../services/encryptByServerKey";
export default function PatientRequests() { export default function PatientRequests() {
const [data, setData] = useState([]); const [data, setData] = useState([]);
...@@ -44,18 +45,60 @@ export default function PatientRequests() { ...@@ -44,18 +45,60 @@ export default function PatientRequests() {
return ( return (
<View key={item._id}> <View key={item._id}>
<Text>Key: {item.patient}</Text> <Text>Key: {item.patient}</Text>
<Button title="Accept" onPress={() => handleAcceptance(item)}></Button> <Button
<Button title="Reject" onPress={() => handleDecline(item)}></Button> title="Accept"
onPress={() => handleAcceptance(item, "Accepted")}
></Button>
<Button
title="Reject"
onPress={() => handleAcceptance(item, "Rejected")}
></Button>
</View> </View>
); );
}; };
const handleAcceptance = async (item) => { const handleAcceptance = async (item, status) => {
console.log("Accepted"); //get the practitioner keys
}; try {
const practitionerKey = await AsyncStorage.getItem(
"practitionerStellarPublicKey"
);
const practitionerSecretKey = await AsyncStorage.getItem(
"practitionerStellarSecretKey"
);
const handleDecline = async (item) => { const encryptedPractitionerKey = EncryptWithServerKey(practitionerKey);
console.log("Rejected"); const encryptedPractitionerSeed = EncryptWithServerKey(
practitionerSecretKey
);
const encryptedPatientKey = EncryptWithServerKey(item.patient);
const encryptedStatus = EncryptWithServerKey(status);
const acceptanceObj = {
patient: encryptedPatientKey,
practitionerkey: encryptedPractitionerKey,
practitionerseed: encryptedPractitionerSeed,
status: encryptedStatus,
};
const acceptanceUrl = LOCALBACKEND + "/practitioner/request";
try {
const acceptanceResponse = await fetch(acceptanceUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(acceptanceObj),
});
const responseData = await acceptanceResponse.json();
console.log(responseData);
} catch (errorWhenSendingAcceptance) {
console.log("Error when sending payload");
}
} catch (errorWheGettingKeyPair) {
console.log("Getting key pair from async failed");
}
}; };
return ( return (
......
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