Skip to content

Commit

Permalink
add addWalletMoney api to react
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnil-ahlawat committed Mar 29, 2021
1 parent a285b2a commit 48944ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Backend/controllers/package-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const scanPackage= async(req, res, next) => {
const identifiedPackage = await Package.findOne({serialNumber}).exec().catch((error) => {
return next(error);
});

let userPhoneNo= identifiedPackage.userPhoneNo;
identifiedPackage.userPhoneNo= phoneNo;
identifiedPackage.packageTag= packageTag;
identifiedPackage.save();

res.json({
message: 'Tag changed sucessfully!',
userPhoneNo: userPhoneNo
});
}

Expand Down
34 changes: 32 additions & 2 deletions Frontend/screens/Scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,34 @@ const Scan = ({route, navigation }) => {
})();
}, []);


async function addWalletMoney(){
console.log(phoneNo);
var url = LINK+"/user/addWalletMoney";
try {
const response = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
phoneNo: phoneNo,
amount: 4.00
})
});

const responseData = await response.json();
if (!response.ok) {
throw new Error(responseData.message);
}
else{
console.log(responseData.user)
setModalVisible(true);
}
} catch (err) {
alert("Can't Process Order");
}
}
async function deleteOrder(){
var url = LINK+"/user/removeOrder";
try {
Expand Down Expand Up @@ -122,6 +149,10 @@ const Scan = ({route, navigation }) => {
console.log("done");
deleteOrder();
}
else if(modeTag==="Delivery Personnel"){
setPhoneNo(responseData.userPhoneNo)
addWalletMoney();
}
else{
setModalVisible(true)
}
Expand All @@ -131,7 +162,6 @@ const Scan = ({route, navigation }) => {
alert("Cant Find Package");
setScanned(false);
setSerialNumber(null);

}
}

Expand Down

0 comments on commit 48944ba

Please sign in to comment.