diff --git a/.gitignore b/.gitignore index f2cb825..b44f069 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,9 @@ .LSOverride azure.err iisnode.yml - # Icon must ends with two \r. Icon - +node_modules # Thumbnails ._* @@ -14,8 +13,6 @@ Icon # Files that might appear on external disk .Spotlight-V100 .Trashes -node_modules/ - # Floobits .floo .floobit diff --git a/GFProj.sqlite b/GFProj.sqlite index f58525a..1769fa3 100644 Binary files a/GFProj.sqlite and b/GFProj.sqlite differ diff --git a/client/app/account/auth.js b/client/app/account/auth.js index 3b2e78c..955c1bf 100644 --- a/client/app/account/auth.js +++ b/client/app/account/auth.js @@ -11,18 +11,16 @@ angular.module('otbo5ly.auth', []) $scope.signin = function () { Auth.signin($scope.user) .then(function (data) { - //console.log(data) - if(data.status === '500'){ $scope.msg = 'Wrong password or username!' } else { $scope.msg = ''; - $window.localStorage.setItem('com.otbo5ly', data.token); var userData = {ID:data.ID, UserName: data.UserName, UserTypeName: data.UserTypeName}; + $window.localStorage.setItem('user.otbo5ly', JSON.stringify(userData)); @@ -33,9 +31,10 @@ angular.module('otbo5ly.auth', []) if(data.UserTypeName === 'cooker'){ $rootScope.isCooker = true; $location.path('/users/'+ data.UserName ); - } else { - $location.path('/'); - } + }else if(data.UserTypeName === 'user'){ + $rootScope.isUser = true; + $location.path('/userProfile/'+data.UserName); + }else{ $location.path('/') } } @@ -54,7 +53,6 @@ angular.module('otbo5ly.auth', []) } Auth.signup($scope.user) .then(function (data) { - //console.log(data) if(data.status === '500'){ $scope.msg = 'Wrong password or username!' diff --git a/client/app/app.js b/client/app/app.js index ba42bb1..e757ed4 100644 --- a/client/app/app.js +++ b/client/app/app.js @@ -4,6 +4,7 @@ angular.module('otbo5ly', [ 'otbo5ly.auth', 'otbo5ly.main', 'otbo5ly.newOrder', + 'otbo5ly.userProfile', 'ngRoute' ]) .config(function ($routeProvider, $httpProvider) { @@ -38,6 +39,10 @@ angular.module('otbo5ly', [ templateUrl: 'app/main/main.html', controller: 'MainController' }) + .when('/userProfile/:user', { + templateUrl: 'app/profile/userProfile.html', + controller: 'userProfileController' + }) .otherwise({redirectTo:'/'}); // We add our $httpInterceptor into the array diff --git a/client/app/main/main.js b/client/app/main/main.js index fa19fc0..9b3d363 100644 --- a/client/app/main/main.js +++ b/client/app/main/main.js @@ -4,7 +4,8 @@ angular.module('otbo5ly.main', []) $scope.data = {}; Users.getTodayCookings().then(function(data){ - $scope.data.cookings = data; + console.log(data) + $scope.data.cookings = data; }); // Users.getTopCookers().then(function(data){ diff --git a/client/app/order/order.js b/client/app/order/order.js index c5e73f5..620ba5c 100644 --- a/client/app/order/order.js +++ b/client/app/order/order.js @@ -1,7 +1,7 @@ angular.module('otbo5ly.newOrder', []) -.controller('NewOrderController', function ($scope, $location, Users, Auth, OrderService) { +.controller('NewOrderController', function ($scope, $location, Users, Auth, OrderService,$rootScope) { $scope.order = {}; @@ -27,7 +27,8 @@ angular.module('otbo5ly.newOrder', []) alert('Something went wrong try again'); } else { alert('your order has been sent successfully') - $location.path('/'); + $rootScope.isUser = true; + $location.path('/userProfile/:user'); } }) } diff --git a/client/app/profile/orders.html b/client/app/profile/orders.html index 39503e2..0fbc501 100644 --- a/client/app/profile/orders.html +++ b/client/app/profile/orders.html @@ -1,46 +1,94 @@ - + --> + + +




+

You Have New Order

-

+

+ +
+
+ +

Order Details

-
    + +
      +
    • Client Name:
      - {{ order.CLientFullName }}
    • -
    • Cook Name: -
      - {{ order.Name }}
      +
    • Cook Name: +
      {{ order.Name }}
      +
      - special order -- {{ order.DisheName }}

    • Amount:
      - {{ order.Quantity }}
    • -
      -
    • The Client Will Receive The Order AT : + +
    • Delivery Time :
      - {{ order.DeliveryDate }} - at {{order.DeliverTime}}
    • +
      +
    • You accepted This Order

    • +
    • Do You Agree This Order

      + + +
      +
    • +
      +

    -

-

-
-

I Can Handle It -

-
-
-
-
-

Okay, Let's Start Cooking...

-
-
-
\ No newline at end of file +
+ +
+ + +
diff --git a/client/app/profile/profile.html b/client/app/profile/profile.html index a454ced..8c115c9 100644 --- a/client/app/profile/profile.html +++ b/client/app/profile/profile.html @@ -1,10 +1,11 @@ +
+">
@@ -19,7 +20,7 @@

{{ data.FullName }}

- +asdfssdfsd

@@ -38,7 +39,7 @@

{{ data.FullName }} cooking for today is : {{ data.todayCook.Name }}, just for {{ data.todayCook.Price }} JOD! - +

@@ -50,13 +51,13 @@

-
+
-
{{ data.user.FullName }} schedule
+
{{ data.FullName }} schedule
- +
@@ -85,5 +86,6 @@

User reviews for {{ data.FullName }}

+ \ No newline at end of file diff --git a/client/app/profile/profile.js b/client/app/profile/profile.js index 3ad6ef7..1214227 100644 --- a/client/app/profile/profile.js +++ b/client/app/profile/profile.js @@ -1,6 +1,6 @@ angular.module('otbo5ly.profile', []) -.controller('ProfileController', function ($scope, $routeParams, $window, $location, Users, OrderService) { +.controller('ProfileController', function ($scope, $routeParams, $window, $location,$route, Users, OrderService,Approve) { $scope.data = {}; $scope.orders = {}; @@ -29,4 +29,25 @@ angular.module('otbo5ly.profile', []) CookNamesID: cookNameID, FullName : FullName, cookName: cookName}); } + $scope.acceptOrder = function(orderId){ + console.log(orderId) + + Approve.acceptOrder({orderId:orderId}).then(function(){ + $route.reload(); + + }) + } + $scope.cancelOrder = function(orderId){ + + Approve.cancelOrder({orderId:orderId}).then(function(){ + $route.reload(); + }) + } + + $scope.dos=function(){ + $(".no").fadeOut() +} + + + }); \ No newline at end of file diff --git a/client/app/profile/userProfile.html b/client/app/profile/userProfile.html new file mode 100644 index 0000000..cc543ca --- /dev/null +++ b/client/app/profile/userProfile.html @@ -0,0 +1,266 @@ + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ +
+ +

+ {{ data.FullName }}

+ +
+ +

+ {{ data.PhoneNumber }} +

+
+ +
+ +

{{ data.Email }}

+
+
+ + + + +
+ +

+ Want a Special Dish

+ + + + + + +
+ + +
+
+
+
+ + + + + + +
+



+ +

You Have New Order

+

+
+
+

Order Details

+ +
    + + +
  • Client Name: +
    - {{ order.CLientFullName }}
    +
  • +
  • Cook Name: +
    - {{ order.Name }}
    +
    - special order --{{ order.DisheName }}
    +
  • +
    +
  • Amount: +
    - {{ order.Quantity }}
    +
  • + +
  • You Will Receive The Order AT : +
    - {{ order.DeliveryDate }} - at {{order.DeliverTime}}
    +
  • +
    +
  • {{order.approved}}

    + + + + + + + +
  • +
    +

+ + +
+ + \ No newline at end of file diff --git a/client/app/profile/userProfile.js b/client/app/profile/userProfile.js new file mode 100644 index 0000000..b3c9e92 --- /dev/null +++ b/client/app/profile/userProfile.js @@ -0,0 +1,93 @@ +angular.module('otbo5ly.userProfile', []) + +.controller('userProfileController', function ($scope, $routeParams, $window,$route, $location, Users, OrderService,Approve,Special) { + $scope.data = {}; + $scope.orders = {}; + $scope.Sorder = { + special:'yse', + DeliveryDate:1, + UserId:1, + + }; + var getDeliveryDate = function(){ + var todayDate = new Date(); + todayDate.setDate(todayDate.getDate() + 1); + return todayDate; + } + $scope.Sorder.DeliveryDate = getDeliveryDate().toISOString().slice(0,10); + $scope.Sorder.UserId= (JSON.parse($window.localStorage.getItem('user.otbo5ly')).ID) + + + $scope.cookerName = {cookes:[]} + + + + $scope.getProfile = function(){ + Users.getUserProfile($routeParams.user).then(function(data) { + if(data.UserTypeName === 'user'){ + $scope.data = data; + } else { + $location.path('/'); + } + }); + } + $scope.getOrders = function(){ + Users.getUserOrders($routeParams.user).then(function(data){ + if(JSON.parse($window.localStorage.getItem('user.otbo5ly')).UserTypeName === "user"){ + + for(var i=0;iOtbo5ly + + + + @@ -43,8 +47,10 @@ and if user is logged in its value is set when user sign in or signup --> -
  • My Profile
  • -
  • My Orders
  • +
  • My Profile
  • +
  • My order
  • +
  • My Profile
  • +
  • Sign In
  • Sign Up
  • Sign out
  • @@ -80,11 +86,17 @@ + + + + + + diff --git a/package.json b/package.json index 4caa455..3b0a5b8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "Otbo5ly", "version": "1.1.0", "description": "Full stack application to help refugees gain money by cook and sell", - "author": "Zainab Himami, Montaser Rahmani, Saeed Alhomsi, Hadeel Baloush", + "author": "Maher ,Moath ,Abobakr", "private": true, "engines": { "node": ">=4.0.0" diff --git a/server/handlers.js b/server/handlers.js index 3a2fe63..30df0d7 100644 --- a/server/handlers.js +++ b/server/handlers.js @@ -18,7 +18,6 @@ module.exports = { res.json(Object.assign(user[0], {token: token})); } else{ - console.log('Wrong username Or password') res.status(500).json('Wrong username Or password') } } @@ -74,8 +73,11 @@ module.exports = { Object.assign(profile,{schedule:schedule}); } CookerSchedule.getCookerTodayCook(username, function(cook){ + + if(cook.length>0){ Object.assign(profile,{todayCook:cook[0]}); + } else{ Object.assign(profile,{todayCook:''}); @@ -126,6 +128,56 @@ module.exports = { CookerSchedule.getAllCookByDayNameOrderdByPrice(function(result){ res.json(result) }) + }, + //////////////////////user + getUserOrders: function(req, res){ + var username = req.params.username; + Orders.getUserOrdersByUserName(username, function(orders){ + res.json(orders); + }) + }, + getUserProfile: function(req, res){ + var username = req.params.username; + var profile = {}; + Users.getUserProfileInfo(username, function(user){ + Object.assign(profile,user[0]); + res.json(profile) + }) + }, + AcceptOrder : function(req,res){ + var OrderID = req.body.orderId; + Orders.AcceptOrder(OrderID,function(orders){ + + res.json(orders) + }) + + }, + CancelOrder : function(req,res){ + var OrderID = req.body.orderId; + Orders.CancelOrder(OrderID,function(orders){ + res.json(orders) + }) + }, + DeleteOrder : function(req,res){ + var OrderID = req.body.orderId; + Orders.DeleteOrder(OrderID,function(orders){ + res.json(orders) + }) + }, + SpecialOrder: function(req, res){ + var order = req.body; + Orders.SpecialOrder(order, function(order){ + res.json('Order Added'); + }) + }, + GetAllCookers :function(req, res){ + Users.GetAllCookers(function(cookers){ + if(cookers){ + res.json(cookers); + } + }) } -} \ No newline at end of file + +} + diff --git a/server/models/Comments.js b/server/models/Comments.js index 3385c7d..4673d89 100644 --- a/server/models/Comments.js +++ b/server/models/Comments.js @@ -40,10 +40,3 @@ exports.addComment = function (CommentObj, callback) { sequelize.query(Query, { replacements: { CookerID: CommentObj.CookerID, HTMLBody: CommentObj.HTMLBody, InsertUserID: CommentObj.InsertUserID }, type: Sequelize.QueryTypes.INSERT }) .then(callback) } - - - - - - - diff --git a/server/models/Orders.js b/server/models/Orders.js index 2d238c1..ae6aae5 100644 --- a/server/models/Orders.js +++ b/server/models/Orders.js @@ -13,17 +13,65 @@ exports.getOrdersByUserName = function (UserName, callback) { ,CookNames.Name, CookNames.ID as cookNameID \ ,Orders.DeliveryDate \ ,Orders.DeliverTime \ + ,Orders.approved\ + ,Orders.DisheName\ + ,Orders.ID as OrderID\ ,Orders.Quantity \ + ,CookNames.imgUrl as img\ from Orders \ join Users as Cooker on Cooker.ID = Orders.CookerID \ join CookNames on CookNames.ID = Orders.CookNamesID \ join Users as CLient on CLient.ID = Orders.UserID \ - where Cooker.UserName = :UserName ' + where Cooker.UserName = :UserName AND approved != "no" \ + order by DeliveryDate Desc' sequelize.query(Query, { replacements: { UserName: UserName }, type: Sequelize.QueryTypes.SELECT }) .then(callback) } +///User + +// select Users.ID as UsersID,Cooker.ID as CookerID +// ,Users.FullName as UsersFullName +// ,Cooker.FullName as CookerFullName +// ,CookNames.Name, CookNames.ID as cookNameID +// ,Orders.DeliveryDate +// ,Orders.DeliverTime , +// Orders.approved +// ,Orders.Quantity +// from Orders +// join Users on Users.ID = Orders.UserID +// join CookNames on CookNames.ID = Orders.CookNamesID +// join Users as Cooker on Cooker.ID = Orders.CookerID +// where Users.UserName = '' + +exports.getUserOrdersByUserName = function (UserName, callback) { + + var Query = ' select Users.ID as UsersID,Cooker.ID as CookerID \ + ,Users.FullName as UsersFullName\ + ,Cooker.FullName as CookerFullName \ + ,CookNames.Name, CookNames.ID as cookNameID \ + ,Orders.DeliveryDate \ + ,Orders.DeliverTime \ + ,Orders.approved\ + ,Orders.DisheName\ + ,Orders.ID as OrderID\ + ,Orders.Quantity \ + ,CookNames.imgUrl as img\ + from Orders \ + join Users on Users.ID = Orders.UserID \ + join CookNames on CookNames.ID = Orders.CookNamesID \ + join Users as Cooker on Cooker.ID = Orders.CookerID \ + where Users.UserName = :UserName \ + order by DeliveryDate Desc ' + sequelize.query(Query, { replacements: { UserName: UserName }, type: Sequelize.QueryTypes.SELECT }) + .then(callback) +} + + + +/// + exports.getOrderByID = function (ID, callback) { sequelize.query("select * from Orders where ID = :ID", { replacements: { ID: ID }, type: Sequelize.QueryTypes.SELECT }) .then(callback) @@ -35,4 +83,34 @@ exports.addOrder = function (orderObj, callback) { values (:CookerID,:UserID,:DeliveryDate,:DeliverTime, :CookNamesID, :Quantity)'; sequelize.query(Query, { replacements: { CookerID: orderObj.cookerID, UserID: orderObj.userID, DeliveryDate: orderObj.deliveryDate, DeliverTime: orderObj.deliveryTime,CookNamesID:orderObj.CookNamesID ,Quantity: orderObj.quantity }, type: Sequelize.QueryTypes.INSERT }) .then(callback) -} \ No newline at end of file +} + + +exports.AcceptOrder= function (ID, callback) { + var Query = 'UPDATE Orders SET approved = "yes" where ID = :ID'; + sequelize.query(Query, { replacements: {ID : ID}, type: Sequelize.QueryTypes.BULKUPDATE }) + .then(callback) +} + + +exports.CancelOrder= function (ID, callback) { + var Query = 'update Orders SET approved = "no" where ID = :ID'; + sequelize.query(Query, { replacements: {ID : ID}, type: Sequelize.QueryTypes.UPDATE }) + .then(callback) +} + +exports.DeleteOrder= function (ID, callback) { + var Query = 'DELETE from Orders where ID = :ID'; + sequelize.query(Query, { replacements: {ID : ID}, type: Sequelize.QueryTypes.DELETE }) + .then(callback) +} + + + +exports.SpecialOrder = function (orderObj2, callback) { + var Query = 'insert into Orders (CookerID,UserID,DeliveryDate,DeliverTime,CookNamesID,Quantity,special,DisheName) \ + values (:CookerID,:UserID,:DeliveryDate,:DeliverTime, :CookNamesID, :Quantity, :special, :DisheName)'; + sequelize.query(Query, { replacements: { CookerID: orderObj2.CookerID, UserID: orderObj2.UserId, DeliveryDate: orderObj2.DeliveryDate, DeliverTime: orderObj2.DeliveryTime,CookNamesID:4 ,Quantity: orderObj2.Quantity,special :orderObj2.special,DisheName : orderObj2.DisheName}, type: Sequelize.QueryTypes.INSERT }) + .then(callback) +} + diff --git a/server/models/Users.js b/server/models/Users.js index 533df03..834a926 100644 --- a/server/models/Users.js +++ b/server/models/Users.js @@ -35,6 +35,16 @@ exports.getUserByUsername = function (username, callback) { .then(callback) } + +// select Users.ID,Users.FullName ,Users.UserName , count(Orders.ID) as OrderNums,Users.Address +// from CookerSchedule +// join Users on Users.ID = CookerSchedule.CookerID +// join CookNames on CookNames.ID = CookerSchedule.CookNamesID +// left join Orders on Orders.CookerID = Users.ID +// group by Users.ID,Users.FullName,Users.Address +// order by count(Orders.ID) desc + + exports.getTopCookers = function (callback) { var Query = 'select Users.ID,Users.FullName ,Users.UserName , count(Orders.ID) as OrderNums,Users.Address \ from CookerSchedule \ @@ -55,6 +65,16 @@ exports.addUser = function (userObj, callback) { .then(callback) } +exports.GetAllCookers = function(callback){ + var Query = 'select * from users where UserTypeName="cooker" '; + sequelize.query(Query, { type: Sequelize.QueryTypes.SELECT }) + .then(callback) +} + +exports.GetCookerIDByUsername = function (username, callback) { + sequelize.query("select ID from Users where UserName = :UserName", { replacements: { UserName: username }, type: Sequelize.QueryTypes.SELECT }) + .then(callback) +} diff --git a/server/server.js b/server/server.js index 9d14511..c11a27e 100644 --- a/server/server.js +++ b/server/server.js @@ -21,6 +21,14 @@ app.get('/api/users/:username', handlers.getCookerProfile); app.get('/api/cookingNames', handlers.getCookingNames); app.get('/api/todayCookings', handlers.getTodayCookings); app.get('/api/topCookers', handlers.getTopCookers); +app.get('/api/userProfile/:username', handlers.getUserProfile); +app.get('/api/userOrders/:username', handlers.getUserOrders); +app.post('/api/Approve',handlers.AcceptOrder); +app.post('/api/cancelOrder',handlers.CancelOrder); +app.post('/api/DeleteOrder',handlers.DeleteOrder); +app.get('/api/getAllCookerscookers',handlers.GetAllCookers); +app.post('/api/AddSpecial',handlers.SpecialOrder) ; -app.listen(process.env.PORT || port); \ No newline at end of file +app.listen(process.env.PORT || port); +console.log('work on port '+ port ) \ No newline at end of file
    Day