Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnil-ahlawat committed Mar 29, 2021
1 parent 5d0adf4 commit 121ab4e
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 46 deletions.
2 changes: 2 additions & 0 deletions Backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const userRouter = require('./routes/user-routes');
const packageRouter = require('./routes/package-routes');

const app = express();
//This is the initial database that has been added to the User database.
//This is required as there is no SignUp functionality in out app right now.
/*
const DUMMY_USERS = [
{
Expand Down
1 change: 1 addition & 0 deletions Backend/controllers/login-controllers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require('mongoose');
const User = require('../database/User');

//controller for signing in the app
const login = async (req, res, next) => {
const { phoneNo, password, userType } = req.body;
const identifiedUser = await User.find({ phoneNo, password, userType })
Expand Down
3 changes: 3 additions & 0 deletions Backend/controllers/package-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const mongoose = require('mongoose');
const Package = require('../database/Package');
const User = require('../database/User');

//controller for scaning and changing userPhoneNo, packageTag or count of Package
const scanPackage = async (req, res, next) => {
const { serialNumber, phoneNo, packageTag } = req.body;

Expand Down Expand Up @@ -31,6 +32,7 @@ const scanPackage = async (req, res, next) => {
});
};

//controller to add package to database
const addPackage = async (req, res, next) => {
const { lotNumber, numPackages } = req.body;
for (i = 0; i < parseInt(numPackages); i++) {
Expand All @@ -46,6 +48,7 @@ const addPackage = async (req, res, next) => {
});
};

//controller to assign numPackages packages at warehouse to some restaurant
const sendPackage = async (req, res, next) => {
const { phoneNo, numPackages } = req.body;
let identifiedRestaurant = await User.findOne({
Expand Down
11 changes: 10 additions & 1 deletion Backend/controllers/user-controllers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const mongoose = require('mongoose');
const User = require('../database/User');
const Order = require('../database/Order');

/*
controller to place order:-
1. creates a new order
2. adds orderID to restaurant's pending orders array
3. adds orderID to delivery personnel's pending orders array
*/
const placeOrder = async (req, res, next) => {
const {
reusablePackageFlag,
Expand Down Expand Up @@ -71,6 +76,7 @@ const placeOrder = async (req, res, next) => {
});
};

//controller to get pending orders of restaurant/delivery personnel
const getOrders = async (req, res, next) => {
const phoneNo = req.query.phoneNo;
const userType = req.query.userType;
Expand Down Expand Up @@ -105,6 +111,7 @@ const getOrders = async (req, res, next) => {
});
};

//controller to remove order from restaurant/delivery personnel's order array
const removeOrder = async (req, res, next) => {
const { orderID, phoneNo } = req.body;

Expand All @@ -124,6 +131,7 @@ const removeOrder = async (req, res, next) => {
});
};

//controller to add money to user wallet
const addWalletMoney = async (req, res, next) => {
const { phoneNo, amount } = req.body;

Expand All @@ -147,6 +155,7 @@ const addWalletMoney = async (req, res, next) => {
});
};

//controller to add discound voucher to use promo codes
const givePromoReward = async (req, res, next) => {
const { phoneNo } = req.body;

Expand Down
1 change: 1 addition & 0 deletions Backend/database/Order.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require('mongoose');
var Float = require('mongoose-float').loadType(mongoose, 2);

//schema for orders
const order = new mongoose.Schema({
customerName: {
type: String,
Expand Down
8 changes: 7 additions & 1 deletion Backend/database/Package.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const mongoose = require('mongoose');

/*
Schema for package
serialNumber: unique ID of package,
userPhoneNo: phone Number of user who has this package currently
packageTag: tag to see progress of package in distribution cycle
count: how many times the package has been used till now
*/
const package = new mongoose.Schema({
serialNumber: {
type: String,
Expand Down
1 change: 1 addition & 0 deletions Backend/database/User.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require('mongoose');
var Float = require('mongoose-float').loadType(mongoose, 2);

//schema for users
const user = new mongoose.Schema({
name: {
type: String,
Expand Down
3 changes: 3 additions & 0 deletions Frontend/navigation/customerTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { COLORS, icons } from '../constants';

const Tab = createBottomTabNavigator();

//Button for Styling
const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
var isSelected = accessibilityState.selected;

Expand Down Expand Up @@ -63,6 +64,7 @@ const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
}
};

//Bar for Styling
const CustomTabBar = (props) => {
if (isIphoneX()) {
return (
Expand All @@ -85,6 +87,7 @@ const CustomTabBar = (props) => {
}
};

// tab navigation area
const CustomerTabs = () => {
return (
<Tab.Navigator
Expand Down
3 changes: 3 additions & 0 deletions Frontend/navigation/personnelTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { COLORS, icons } from '../constants';

const Tab = createBottomTabNavigator();

//Button for styling
const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
var isSelected = accessibilityState.selected;

Expand Down Expand Up @@ -63,6 +64,7 @@ const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
}
};

//Bar Styling
const CustomTabBar = (props) => {
if (isIphoneX()) {
return (
Expand All @@ -85,6 +87,7 @@ const CustomTabBar = (props) => {
}
};

// tab navigation area
const PersonnelTabs = () => {
return (
<Tab.Navigator
Expand Down
3 changes: 3 additions & 0 deletions Frontend/navigation/restaurantTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { COLORS, icons } from '../constants';

const Tab = createBottomTabNavigator();

// button for styling
const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
var isSelected = accessibilityState.selected;

Expand Down Expand Up @@ -63,6 +64,7 @@ const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
}
};

// bar for styling
const CustomTabBar = (props) => {
if (isIphoneX()) {
return (
Expand All @@ -85,6 +87,7 @@ const CustomTabBar = (props) => {
}
};

// tab navigation area
const RestaurantTabs = () => {
return (
<Tab.Navigator
Expand Down
3 changes: 3 additions & 0 deletions Frontend/navigation/warehouseTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { COLORS, icons } from '../constants';

const Tab = createBottomTabNavigator();

// button for styling
const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
var isSelected = accessibilityState.selected;

Expand Down Expand Up @@ -63,6 +64,7 @@ const TabBarCustomButton = ({ accessibilityState, children, onPress }) => {
}
};

// bar for styling
const CustomTabBar = (props) => {
if (isIphoneX()) {
return (
Expand All @@ -85,6 +87,7 @@ const CustomTabBar = (props) => {
}
};

// tab navigation area
const WarehouseTabs = () => {
return (
<Tab.Navigator
Expand Down
19 changes: 17 additions & 2 deletions Frontend/screens/Cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {

import { icons, COLORS, SIZES, FONTS, LINK } from '../constants';

// Order Summary Screen
const Order = ({ route, navigation }) => {
const [restaurant, setRestaurant] = useState(null);
const [orderItems, setOrderItems] = useState([]);
Expand All @@ -32,7 +33,8 @@ const Order = ({ route, navigation }) => {
}
});

const placeOrderHandler = async () => {
//handler to send place order request to server
async function placeOrderHandler() {
try {
const response = await fetch(LINK + '/user/placeOrder', {
method: 'POST',
Expand Down Expand Up @@ -66,7 +68,9 @@ const Order = ({ route, navigation }) => {
} catch (err) {
alert('Error in placing order. Please try again later.');
}
};
}

//renders header
function renderHeader() {
return (
<View style={{ flexDirection: 'row' }}>
Expand Down Expand Up @@ -112,6 +116,7 @@ const Order = ({ route, navigation }) => {
);
}

//renders Restaurant and Customer Details
function renderInfo() {
return (
<View style={{ margin: SIZES.padding * 2, marginBottom: SIZES.padding }}>
Expand Down Expand Up @@ -151,6 +156,8 @@ const Order = ({ route, navigation }) => {
</View>
);
}

//renders Order items
function renderOrderInfo() {
const renderItem = ({ item }) => (
<View
Expand Down Expand Up @@ -225,6 +232,8 @@ const Order = ({ route, navigation }) => {
let total = sumOrder();
return (0.18 * total).toFixed(2);
}

//adds reusable package line on screen if selected
function reusablePackageFee() {
if (reusablePackage) {
return (
Expand Down Expand Up @@ -263,6 +272,8 @@ const Order = ({ route, navigation }) => {
parseFloat(reusablePackage ? 4.0 : 0.0);
return total.toFixed(2);
}

//renders final amounts like tax, subtotal, total, reusable package fee
function renderTotal() {
return (
<View style={{ marginHorizontal: SIZES.padding * 2 }}>
Expand Down Expand Up @@ -359,6 +370,7 @@ const Order = ({ route, navigation }) => {
);
}

//render buttons for payment mode
function renderPaymentMode() {
return (
<View
Expand Down Expand Up @@ -432,6 +444,8 @@ const Order = ({ route, navigation }) => {
</View>
);
}

//renders place order button
function renderPlaceOrderButton() {
return (
<TouchableOpacity
Expand All @@ -458,6 +472,7 @@ const Order = ({ route, navigation }) => {
);
}

//modal for order confirmation
function renderPlaceOrderModal() {
return (
<Modal animationType="slide" transparent={true} visible={modalVisible}>
Expand Down
22 changes: 1 addition & 21 deletions Frontend/screens/CustomerHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

import { icons, images, SIZES, COLORS, FONTS } from '../constants';

//First screen where customer comes on signing in
const CustomerHome = ({ navigation }) => {
const categoryData = [
{
Expand Down Expand Up @@ -252,27 +253,6 @@ const CustomerHome = ({ navigation }) => {
</Text>
</View>
</View>

{/* <TouchableOpacity
style={{
width: 50,
paddingRight: SIZES.padding * 2,
justifyContent: 'center'
}}
onPress={() => navigation.navigate("Cart", {
orderItems: global.orderItems
})}
>
<Image
source={icons.basket}
resizeMode="contain"
style={{
width: 30,
height: 30
}}
/>
</TouchableOpacity> */}
</SafeAreaView>
);
}
Expand Down
3 changes: 3 additions & 0 deletions Frontend/screens/DeliverOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DeliverOrder = ({ route, navigation }) => {
setOrder(item);
});

//function to delete order from personnel's pending order array
async function deleteOrder() {
var url = LINK + '/user/removeOrder';
try {
Expand Down Expand Up @@ -231,6 +232,7 @@ const DeliverOrder = ({ route, navigation }) => {
</View>
);
}

function renderButton() {
return (
<View>
Expand All @@ -253,6 +255,7 @@ const DeliverOrder = ({ route, navigation }) => {
</View>
);
}

function renderModeModal() {
return (
<Modal animationType="slide" transparent={true} visible={modalVisible}>
Expand Down
14 changes: 8 additions & 6 deletions Frontend/screens/Order.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import {
StyleSheet,
FlatList,
Expand All @@ -16,17 +16,20 @@ import {

import { icons, COLORS, SIZES, FONTS, LINK } from '../constants';

// Screen on which complete selected pending order is displayed
const Order = ({ route, navigation }) => {
const [order, setOrder] = React.useState(null);
const [isSelected, setSelection] = React.useState(false);
const [modalVisible, setModalVisible] = React.useState(false);
const [order, setOrder] = useState(null);
const [isSelected, setSelection] = useState(false);
const [modalVisible, setModalVisible] = useState(false);

React.useEffect(() => {
useEffect(() => {
let { item } = route.params;

setOrder(item);
setSelection(order?.reusablePackageFlag);
});

//request to delete order from restaurant's pending orders list
async function deleteOrder() {
var url = LINK + '/user/removeOrder';
try {
Expand Down Expand Up @@ -228,7 +231,6 @@ const Order = ({ route, navigation }) => {
style={{
height: 25,
width: 25,
// tintColor: COLORS.primary
}}
/>
</View>
Expand Down
Loading

0 comments on commit 121ab4e

Please sign in to comment.