Skip to content

Commit

Permalink
Fix how to get customer details
Browse files Browse the repository at this point in the history
  • Loading branch information
meisyal committed Jan 11, 2016
1 parent 42953fd commit a9ff56b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
22 changes: 7 additions & 15 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,13 @@ MIM.controller('CustomerController', function($scope, $ionicPlatform, $cordovaSQ
};
});

MIM.controller('CustomerDetailController', function($scope, $ionicPlatform, $cordovaSQLite, $stateParams) {
$ionicPlatform.ready(function() {
var query = 'SELECT name, address, telephone_number, DATETIME(created_at, \'localtime\') ' +
'AS joined_date, DATETIME(updated_at, \'localtime\') AS updated_date FROM Customers WHERE id = ?';
$cordovaSQLite.execute(db, query, [$stateParams.customerId]).then(function(res) {
if (res.rows.length) {
$scope.customer_name = res.rows.item(0).name;
$scope.customer_address = res.rows.item(0).address;
$scope.customer_phone = res.rows.item(0).telephone_number;
$scope.customer_joined = res.rows.item(0).joined_date;
$scope.customer_updated = res.rows.item(0).updated_date;
}
}, function(error) {
console.error(error);
});
MIM.controller('CustomerDetailController', function($scope, $stateParams, Customer) {
Customer.get($stateParams.customerId).then(function(customerDetail) {
$scope.customer_name = customerDetail.name;
$scope.customer_address = customerDetail.address;
$scope.customer_phone = customerDetail.telephone_number;
$scope.customer_joined = customerDetail.joined_date;
$scope.customer_updated = customerDetail.updated_date;
});
});

Expand Down
6 changes: 4 additions & 2 deletions www/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ MIM.factory('Customer', function($cordovaSQLite, DB) {

this.get = function(customerId) {
var parameters = [customerId];
return DB.queryStatement("SELECT id, name, address, telephone_number FROM " +
"Customers WHERE id = ?", parameters).then(function(res) {
return DB.queryStatement("SELECT id, name, address, telephone_number, " +
"DATETIME(created_at, \'localtime\') AS joined_date, " +
"DATETIME(updated_at, \'localtime\') AS updated_date FROM Customers " +
"WHERE id = ?", parameters).then(function(res) {
return DB.getById(res);
});
};
Expand Down

0 comments on commit a9ff56b

Please sign in to comment.