Skip to content

Commit

Permalink
debug api connections
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnil-ahlawat committed Mar 29, 2021
1 parent 48944ba commit 9e6ba8b
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 73 deletions.
8 changes: 6 additions & 2 deletions Backend/controllers/package-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ const scanPackage= async(req, res, next) => {
const identifiedPackage = await Package.findOne({serialNumber}).exec().catch((error) => {
return next(error);
});
if(!identifiedPackage){
res.sendStatus(404);
}
let userPhoneNo= identifiedPackage.userPhoneNo;
identifiedPackage.userPhoneNo= phoneNo;
identifiedPackage.packageTag= packageTag;
identifiedPackage.save();

console.log(userPhoneNo);
res.json({
message: 'Tag changed sucessfully!',
userPhoneNo: userPhoneNo
Expand Down Expand Up @@ -42,6 +45,7 @@ const addPackage= async(req, res, next) => {

res.json({
message: 'Added the packages successfully!',
restaurant: identifiedRestaurant.name
});
}

Expand All @@ -50,7 +54,7 @@ const removePackage = async(req, res, next) => {
const {serialNumber} = req.body;
await Package.deleteOne({serialNumber}, function(error) {
if(error){
sendStatus(404);
res.sendStatus(404);
}
})

Expand Down
8 changes: 5 additions & 3 deletions Backend/controllers/user-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ const User = require('../database/User');
const Order= require('../database/Order');

const placeOrder= async(req, res, next) =>{
const {reusablePackageFlag, restaurantPhoneNo, restaurantCourier, orderItems, customer, walletUsed, total} = req.body;
let order={customerName:customer.name, customerAddress: customer.address, customerPhoneNo: customer.phoneNo, reusablePackageFlag, foodItems: orderItems}
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();

Expand Down Expand Up @@ -85,6 +84,9 @@ const addWalletMoney= async(req, res, next) =>{
let identifiedUser= await User.findOne({phoneNo, userType:"Customer"}).exec().catch((error) => {
return next(error);
});
if(!identifiedUser){
res.sendStatus(404);
}
let money= identifiedUser.wallet;
money+= parseFloat(amount);
identifiedUser.wallet= money;
Expand Down
9 changes: 8 additions & 1 deletion Backend/database/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const order = new mongoose.Schema({
price:{
type: Float, required: true
}
}]
},
],
total:{
type:Number,
},
subtotal:{
type:Number
}
});

module.exports = Order = mongoose.model('Order', order);
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://2fe833c33bc6.ngrok.io"
export const LINK= "https://882406c64343.ngrok.io"
export const COLORS = {
// base colors
primary: "#3FC060", // green
Expand Down
12 changes: 11 additions & 1 deletion Frontend/screens/Cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ const Order = ({ route, navigation }) => {
}
function renderPlaceOrderButton(){
const placeOrderHandler = async () => {
let hello={reusablePackageFlag: reusablePackage,
restaurantPhoneNo: restaurant.phoneNo,
restaurantCourier: restaurant.courier.name,
orderItems: orderItems,
customer: global.user,
walletUsed: checked,
total: calculateTotal(),
subtotal: sumOrder()}
console.log(hello);
try {
const response = await fetch(LINK+'/user/placeOrder', {
method: 'POST',
Expand All @@ -230,7 +239,8 @@ const Order = ({ route, navigation }) => {
orderItems: orderItems,
customer: global.user,
walletUsed: checked,
total: sumOrder()
total: calculateTotal(),
subtotal: sumOrder()
})
});
const responseData = await response.json();
Expand Down
10 changes: 5 additions & 5 deletions Frontend/screens/CustomerHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const CustomerHome = ({ navigation }) => {
},
courier: {
avatar: images.avatar_2,
name: "Jackson"
name: "Piyush Maheshwari"
},
menu: [
{
Expand Down Expand Up @@ -192,7 +192,7 @@ const CustomerHome = ({ navigation }) => {
},
courier: {
avatar: images.avatar_3,
name: "James"
name: "Piyush Maheshwari"
},
menu: [
{
Expand Down Expand Up @@ -221,7 +221,7 @@ const CustomerHome = ({ navigation }) => {
},
courier: {
avatar: images.avatar_4,
name: "Ahmad"
name: "Piyush Maheshwari"
},
menu: [
{
Expand Down Expand Up @@ -250,7 +250,7 @@ const CustomerHome = ({ navigation }) => {
},
courier: {
avatar: images.avatar_4,
name: "Muthu"
name: "Piyush Maheshwari"
},
menu: [
{
Expand Down Expand Up @@ -305,7 +305,7 @@ const CustomerHome = ({ navigation }) => {
},
courier: {
avatar: images.avatar_1,
name: "Jessie"
name: "Piyush Maheshwari"
},
menu: [
{
Expand Down
24 changes: 3 additions & 21 deletions Frontend/screens/PersonnelHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import { icons, images, SIZES, COLORS, FONTS, LINK } from '../constants'

const PersonnelHome = ({ navigation }) => {

// Dummy Datas

const deliveryPersonData = {
Name: "Prakash",
}

const deliveryData = [
{
order_id: 1,
Expand All @@ -32,10 +26,6 @@ const PersonnelHome = ({ navigation }) => {
quantity: "2 items",
payment_mode: "Cash on delivery",
delivery_made: false,
location: {
latitude: 1.5347282806345879,
longitude: 110.35632207358996,
},
order_details: [
{ food_id: 1,
name: "Zinger Burger",
Expand Down Expand Up @@ -63,10 +53,6 @@ const PersonnelHome = ({ navigation }) => {
restaurant: "Amrik Sukhdev Dhaba",
order_deadline: "March 24,2019 15:42",
payment_mode: "Uber Wallet",
location: {
latitude: 1.5347282806345879,
longitude: 120.35632207358996,
},
order_details: [
{ food_id: 1,
name: "Red-sauce Pasta",
Expand Down Expand Up @@ -114,10 +100,6 @@ const PersonnelHome = ({ navigation }) => {
address: "Pacific C",
payment_mode: "Cash on delivery",
resuablePackage: true,
location: {
latitude: 1.2347282806345879,
longitude: 120.35632207358996,
},
order_details: [
{ food_id: 1,
name: "Red-sauce Pasta",
Expand All @@ -143,7 +125,7 @@ const PersonnelHome = ({ navigation }) => {
const [orders, setOrders] = useState(null)
const [fetchFlag,setFetchFlag] = useState(true)

const inFocus = navigation.addListener('focus', () => {
const inFocus = navigation.addListener('state', () => {
setFetchFlag(true)
});

Expand Down Expand Up @@ -180,7 +162,7 @@ const PersonnelHome = ({ navigation }) => {
}
} catch (err) {
console.log(err)
return null
alert("Server Unreachable.");
}
}};

Expand Down Expand Up @@ -210,7 +192,7 @@ const PersonnelHome = ({ navigation }) => {
paddingRight: SIZES.padding,
justifyContent: 'center'
}}
onPress={() => navigation.goBack()}
onPress={() => navigation.navigate("SignUp")}
>
<Image
source={icons.signOut}
Expand Down
28 changes: 12 additions & 16 deletions Frontend/screens/RestaurantHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
Platform,
StatusBar
} from "react-native";
import { icons, images, SIZES, COLORS, FONTS } from '../constants'
import { icons, images, SIZES, COLORS, FONTS, LINK } from '../constants'

const RestaurantHome = ({ navigation }) => {
const RestaurantHome = ({route, navigation }) => {

const [orders, setOrders] = useState(null)
const [fetchFlag,setFetchFlag] = useState(true)

const inFocus = navigation.addListener('focus', () => {
const inFocus = navigation.addListener('state', () => {
setFetchFlag(true)
});

Expand All @@ -27,17 +27,13 @@ const RestaurantHome = ({ navigation }) => {
};
}, [navigation]);





async function fetchOrder(){
if (fetchFlag)
{
setFetchFlag(false)
console.log(global.user.phoneNo)

var url = "https://4c77f765204e.ngrok.io/user/restaurant?phoneNo=" + global.user.phoneNo + "&userType=Restaurant"
var url = LINK+"/user/restaurant?phoneNo=" + global.user.phoneNo + "&userType=Restaurant"
console.log(url)
try {
const response = await fetch(url, {
Expand All @@ -57,8 +53,8 @@ const RestaurantHome = ({ navigation }) => {
setOrders(responseData.pendingOrders)
}
} catch (err) {
console.log(err)
return null
console.log(err);
alert("Server Unreachable.");
}
}
};
Expand Down Expand Up @@ -88,7 +84,7 @@ const RestaurantHome = ({ navigation }) => {
paddingRight: SIZES.padding,
justifyContent: 'center'
}}
onPress={() => navigation.goBack()}
onPress={() => navigation.navigate("SignUp")}
>
<Image
source={icons.signOut}
Expand Down Expand Up @@ -128,8 +124,8 @@ const RestaurantHome = ({ navigation }) => {
paddingHorizontal: SIZES.padding
}}
>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.customerName}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.foodItems.length}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item?.customerName}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item?.foodItems.length}</Text>
</View>
<View
style={{
Expand All @@ -139,7 +135,7 @@ const RestaurantHome = ({ navigation }) => {
}}
>
{/* <Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.address}</Text> */}
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.customerAddress}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item?.customerAddress}</Text>
</View>
<View
style={{
Expand All @@ -149,7 +145,7 @@ const RestaurantHome = ({ navigation }) => {
}}
>
{/* <Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.address}</Text> */}
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item.customerPhoneNo}</Text>
<Text style={{ ...FONTS.body3,color: COLORS.black }}>{item?.customerPhoneNo}</Text>
</View>

</TouchableOpacity>
Expand All @@ -160,7 +156,7 @@ const RestaurantHome = ({ navigation }) => {
<Text style={{paddingVertical:10, ...FONTS.h2,color: COLORS.white }}>In Progress ({orders?.length})</Text>
<FlatList
data={orders}
keyExtractor={item => `${item._id}`}
keyExtractor={item => `${item?._id}`}
renderItem={renderItem}
contentContainerStyle={{
paddingBottom: 30
Expand Down
Loading

0 comments on commit 9e6ba8b

Please sign in to comment.