Skip to content

Commit

Permalink
debug wallet and home errors
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnil-ahlawat committed Mar 29, 2021
1 parent 3839982 commit 46d171e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
26 changes: 17 additions & 9 deletions Backend/controllers/user-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ const Order= require('../database/Order');

const placeOrder= async(req, res, next) =>{
const {reusablePackageFlag, restaurantPhoneNo, restaurantCourier, orderItems, customer, walletUsed, total, subtotal} = req.body;
let order={customerName:customer.name, customerAddress: customer.address, customerPhoneNo: customer.phoneNo, reusablePackageFlag, foodItems: orderItems, total:total, subtotal: subtotal}
let orderModel = new Order(order);
await orderModel.save();

let identifiedRestaurant = await User.findOne({phoneNo: restaurantPhoneNo, userType: "Restaurant"}).exec().catch((error) => {
return next(error);
});
identifiedRestaurant.orders.push({orderID: orderModel._id.toString()});
await identifiedRestaurant.save();

let identifiedPersonnel = await User.findOne({name: restaurantCourier, userType: "Delivery Personnel"}).exec().catch((error) => {
return next(error);
});

identifiedPersonnel.orders.push({orderID: orderModel._id.toString()});

await identifiedPersonnel.save();
let identifiedUser = await User.findOne({phoneNo: customer.phoneNo}).exec().catch((error) => {
return next(error);
});

let order={customerName:customer.name, customerAddress: customer.address, customerPhoneNo: customer.phoneNo, restaurantName: identifiedRestaurant.name, reusablePackageFlag, foodItems: orderItems, total:total, subtotal: subtotal}
let orderModel = new Order(order);
await orderModel.save();


identifiedRestaurant.orders.push({orderID: orderModel._id.toString()});
await identifiedRestaurant.save();


identifiedPersonnel.orders.push({orderID: orderModel._id.toString()});

await identifiedPersonnel.save();

if(walletUsed){
identifiedUser.wallet = identifiedUser.wallet- parseFloat(total);
await identifiedUser.save();
Expand Down Expand Up @@ -51,7 +57,9 @@ const getOrders= async(req, res, next) =>{
}
let pendingOrders=[]
for (index = 0; index < identifiedUser.orders.length; index++) {
pendingOrders.push(await getOrderfromOrderID(identifiedUser.orders[index]));
console.log(identifiedUser.orders[index]);
let order= await getOrderfromOrderID(identifiedUser.orders[index])
pendingOrders.push(order);
}
res.json({
pendingOrders
Expand Down
3 changes: 3 additions & 0 deletions Backend/database/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const order = new mongoose.Schema({
customerPhoneNo:{
type:String
},
restaurantName:{
type:String
},
reusablePackageFlag:{
type:Boolean, default: false
},
Expand Down
2 changes: 1 addition & 1 deletion Frontend/constants/theme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dimensions } from "react-native";
const { width, height } = Dimensions.get("window");
export const LINK= "https://882406c64343.ngrok.io"
export const LINK= "https://279c1c5a3c61.ngrok.io"
export const COLORS = {
// base colors
primary: "#3FC060", // green
Expand Down
14 changes: 10 additions & 4 deletions Frontend/screens/Cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const Order = ({ route, navigation }) => {
</View>
<View style={{flexDirection: "row"}}>
<Text style={{width:"75%", color: COLORS.white, ...FONTS.body3, textAlign:"left"}}>Delivery Fee</Text>
<Text style={{width:"25%",color: COLORS.white, ...FONTS.body3, textAlign: "right"}}>$4.00</Text>
<Text style={{width:"25%",color: COLORS.white, ...FONTS.body3, textAlign: "right"}}>$5.00</Text>
</View>
{reusablePackageFee()}
<View style={{flexDirection: "row", marginVertical:SIZES.padding}}>
Expand Down Expand Up @@ -249,8 +249,13 @@ const Order = ({ route, navigation }) => {
throw new Error(responseData.message);
}
else{
global.user= responseData.user;
setModalVisible(true);
if(response.message ==="NotEnough"){
alert("Not Enough Money in Wallet!");
}
else{
setModalVisible(true);
}
global.user= responseData.user;
}
} catch (err) {
console.log(err);
Expand All @@ -271,7 +276,8 @@ const Order = ({ route, navigation }) => {

}}
onPress={() => {
if(checked && global.wallet<calculateTotal()){
console.log(global.user.wallet);
if(checked && global.user.wallet<calculateTotal()){
alert("Wallet Balance less than Order Total!")
setChecked(false);
}
Expand Down
3 changes: 1 addition & 2 deletions Frontend/screens/PersonnelHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,8 @@ const PersonnelHome = ({ navigation }) => {
}}
>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>Customer Name: <Text style = {{fontWeight: 'bold'}}>{item.customerName}</Text></Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>Restaurant: <Text style = {{fontWeight: 'bold'}}>{item.restaurant}</Text></Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>Restaurant: <Text style = {{fontWeight: 'bold'}}>{item.restaurantName}</Text></Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>Delivery Addresss: <Text style = {{fontWeight: 'bold'}}>{item.customerAddress}</Text></Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>Order Deadline: <Text style = {{fontWeight: 'bold'}}>{item.orderDeadline}</Text></Text>
</View>


Expand Down
1 change: 1 addition & 0 deletions Frontend/screens/RestaurantHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const RestaurantHome = ({route, navigation }) => {
else{
console.log(responseData)
setOrders(responseData.pendingOrders)
console.log(orders);
}
} catch (err) {
console.log(err);
Expand Down

0 comments on commit 46d171e

Please sign in to comment.