Commit 5b953d38 authored by Ishini Kiridena's avatar Ishini Kiridena

user request acceptance completed

parent 453b4aac
......@@ -7,10 +7,14 @@ const Requests = require("./../../model/patient/request");
router.post("/", async (req, res) => {
//Get the payload
const decryptedPatientKey = req.body.patient;
const decryptedPractitionerKey = req.body.practitionerkey;
const decryptedPractitionerSeed = req.body.practitionerseed;
const decryptedStatus = req.body.status;
const decryptedPatientKey = DecryptWithServerKey(req.body.patient);
const decryptedPractitionerKey = DecryptWithServerKey(
req.body.practitionerkey
);
const decryptedPractitionerSeed = DecryptWithServerKey(
req.body.practitionerseed
);
const decryptedStatus = DecryptWithServerKey(req.body.status);
let timestamp;
//check the condition
......
......@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { LOCALBACKEND } from "../../env";
import { Button, StyleSheet, View, Text } from "react-native";
import AsyncStorage from "@react-native-async-storage/async-storage";
import EncryptWithServerKey from "../../services/encryptByServerKey";
export default function PatientRequests() {
const [data, setData] = useState([]);
......@@ -44,18 +45,60 @@ export default function PatientRequests() {
return (
<View key={item._id}>
<Text>Key: {item.patient}</Text>
<Button title="Accept" onPress={() => handleAcceptance(item)}></Button>
<Button title="Reject" onPress={() => handleDecline(item)}></Button>
<Button
title="Accept"
onPress={() => handleAcceptance(item, "Accepted")}
></Button>
<Button
title="Reject"
onPress={() => handleAcceptance(item, "Rejected")}
></Button>
</View>
);
};
const handleAcceptance = async (item) => {
console.log("Accepted");
};
const handleAcceptance = async (item, status) => {
//get the practitioner keys
try {
const practitionerKey = await AsyncStorage.getItem(
"practitionerStellarPublicKey"
);
const practitionerSecretKey = await AsyncStorage.getItem(
"practitionerStellarSecretKey"
);
const handleDecline = async (item) => {
console.log("Rejected");
const encryptedPractitionerKey = EncryptWithServerKey(practitionerKey);
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 (
......
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