Created
September 28, 2015 18:02
-
-
Save lefnire/82518df71a7dcecdf821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/frontend/app/scripts/services/property-service.js b/frontend/app/scripts/services/property-service.js | |
index e98d76b..1ed8a48 100755 | |
--- a/frontend/app/scripts/services/property-service.js | |
+++ b/frontend/app/scripts/services/property-service.js | |
@@ -30,9 +30,9 @@ app.service('PropertyService', ['$http', '$q', '$filter', function ($http, $q, $ | |
8: "Other" | |
}; | |
- this.propertyTypes = function () { | |
+ function _wrap(request) { | |
var d = $q.defer(); | |
- $http.get('/api/v1/master_data/property_types.json').success( | |
+ request.success( | |
function success(data, status, headers, config) { | |
if (status == 200) { | |
d.resolve(data); | |
@@ -43,76 +43,27 @@ app.service('PropertyService', ['$http', '$q', '$filter', function ($http, $q, $ | |
function error(data, status, headers, config) { | |
d.reject(data); | |
}); | |
- | |
return d.promise; | |
+ } | |
+ | |
+ this.propertyTypes = function () { | |
+ return _wrap( $http.get('/api/v1/master_data/property_types.json') ); | |
}; | |
this.features = function () { | |
- var d = $q.defer(); | |
- $http.get('/api/v1/master_data/features.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/master_data/features.json') ); | |
}; | |
this.userPropertyList = function (userId) { | |
- var d = $q.defer(); | |
- $http.get('/api/v1/users/' + userId + '/property.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/users/' + userId + '/property.json') ); | |
}; | |
this.getPartnersList = function () { | |
- var d = $q.defer(); | |
- $http.get('/api/v1/partners.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/partners.json') ); | |
}; | |
this.sendmailBuyerInformation = function (properId, buyerDetails) { | |
- var d = $q.defer(); | |
- $http.post('api/v1/property/' + properId + '/send_email.json', {'buyer_detail': buyerDetails}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('api/v1/property/' + properId + '/send_email.json', {'buyer_detail': buyerDetails}) ); | |
} | |
/** | |
@@ -122,106 +73,28 @@ app.service('PropertyService', ['$http', '$q', '$filter', function ($http, $q, $ | |
* @returns {*} | |
*/ | |
this.createProperty = function (userId, property) { | |
- var d = $q.defer(); | |
- $http.post('/api/v1/users/' + userId + '/property.json', {'property': property}).success( | |
- function success(data, status) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/users/' + userId + '/property.json', {'property': property}) ); | |
}; | |
this.updateProperty = function (property) { | |
- var d = $q.defer(); | |
- $http.put('/api/v1/property/' + property.id + '.json', {'property': property}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.put('/api/v1/property/' + property.id + '.json', {'property': property}) ); | |
}; | |
this.updateImageDescription = function (image) { | |
- var d = $q.defer(); | |
- $http.put('/api/v1/property/' + image.property_id + '/images/' + image.id, {'image': image}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.put('/api/v1/property/' + image.property_id + '/images/' + image.id, {'image': image}) ); | |
}; | |
this.updateVideoDescription = function (video) { | |
- var d = $q.defer(); | |
- $http.put('/api/v1/property/' + video.property_id + '/videos/' + video.id, {'video': video}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.put('/api/v1/property/' + video.property_id + '/videos/' + video.id, {'video': video}) ); | |
}; | |
this.deletePropertyImage = function (image) { | |
- var d = $q.defer(); | |
- $http.delete('/api/v1/property/' + image.property_id + '/images/' + image.id, {'image': image}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.delete('/api/v1/property/' + image.property_id + '/images/' + image.id, {'image': image}) ); | |
}; | |
this.deletePropertyVideo = function (video) { | |
- var d = $q.defer(); | |
- $http.delete('/api/v1/property/' + video.property_id + '/videos/' + video.id).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.delete('/api/v1/property/' + video.property_id + '/videos/' + video.id) ); | |
}; | |
this.getVideos = function (property_id) { | |
@@ -250,26 +123,12 @@ app.service('PropertyService', ['$http', '$q', '$filter', function ($http, $q, $ | |
}; | |
this.uploadFileToUrl = function (file, contact) { | |
- var d = $q.defer(); | |
var fd = new FormData(); | |
- | |
fd.append('contact[avatar]', file); | |
- $http.put('/api/v1/property/' + contact.property_id + '/contact/' + contact.id + '.json', fd, { | |
+ return _wrap( $http.put('/api/v1/property/' + contact.property_id + '/contact/' + contact.id + '.json', fd, { | |
transformRequest: angular.identity, | |
headers: {'Content-Type': undefined} | |
- }).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ }) ); | |
}; | |
@@ -296,275 +155,74 @@ app.service('PropertyService', ['$http', '$q', '$filter', function ($http, $q, $ | |
this.getProperty = function (property_id) { | |
- var d = $q.defer(); | |
- $http.get('/api/v1/property/' + property_id + '/details.json').success( | |
- function success(data, status) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/property/' + property_id + '/details.json') ); | |
}; | |
this.getPropertyBasicData = function (property_id) { | |
- var d = $q.defer(); | |
- $http.get('/api/v1/property/' + property_id + '.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/property/' + property_id + '.json') ); | |
}; | |
this.reOrderImages = function (dataimages, property_id) { | |
- var d = $q.defer(); | |
- $http.post('/api/v1/property/' + property_id + '/images/reorder_images.json', {'image_id': dataimages}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/property/' + property_id + '/images/reorder_images.json', {'image_id': dataimages}) ); | |
} | |
this.createContact = function (contact) { | |
- var d = $q.defer(); | |
- $http.post('/api/v1/property/' + contact.property_id + '/contact.json', {'contact': contact}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/property/' + contact.property_id + '/contact.json', {'contact': contact}) ); | |
}; | |
this.updateContact = function (contact) { | |
- var d = $q.defer(); | |
- $http.put('/api/v1/property/' + contact.property_id + '/contact/' + contact.id + '.json', {'contact': contact}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.put('/api/v1/property/' + contact.property_id + '/contact/' + contact.id + '.json', {'contact': contact}) ); | |
}; | |
this.getAllPropertyFeatures = function () { | |
- | |
- var d = $q.defer(); | |
//$http.get('/api/v2/constants/constant').success( | |
- $http.get('/api/v1/features/get_all').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/features/get_all') ); | |
} | |
this.setPropertyFeature = function (property_id, feature_id) { | |
- var d = $q.defer(); | |
- $http.post('/api/v1/property/' + property_id + '/features.json', {'id': feature_id}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/property/' + property_id + '/features.json', {'id': feature_id}) ); | |
}; | |
this.removePropertyFeature = function (property_id, feature_id) { | |
- var d = $q.defer(); | |
- $http.delete('/api/v1/property/' + property_id + '/features/' + feature_id + '.json', {'id': feature_id}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.delete('/api/v1/property/' + property_id + '/features/' + feature_id + '.json', {'id': feature_id}) ); | |
}; | |
this.setPropertyFeatures = function (property_id, features) { | |
- var d = $q.defer(); | |
- $http.post('/api/v1/property/' + property_id + '/features/bulk_update.json', features).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/property/' + property_id + '/features/bulk_update.json', features) ); | |
}; | |
this.getPropertyBySubdomain = function (lang) { | |
- var d = $q.defer(); | |
var lang_suffix = ''; | |
if (lang != null) { | |
lang_suffix = '?lang=' + lang | |
} | |
- $http.get('/api/v1/property_show_by_subdomain.json' + lang_suffix).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/property_show_by_subdomain.json' + lang_suffix) ); | |
}; | |
this.getAllPaymentHistory = function () { | |
- | |
- var d = $q.defer(); | |
- $http.get('/api/v1/payment_histories.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/payment_histories.json') ); | |
}; | |
this.getAllBookmarks = function () { | |
- | |
- var d = $q.defer(); | |
- $http.get('/api/v1/property/bookmarked.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/property/bookmarked.json') ); | |
}; | |
this.deleteBookmark = function (id) { | |
- | |
- var d = $q.defer(); | |
- $http.delete('/api/v1/bookmarks/' + id + '.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.delete('/api/v1/bookmarks/' + id + '.json') ); | |
}; | |
this.getSubmittedOfferStatsForProperty = function (property_id) { | |
- var d = $q.defer(); | |
- $http.get('/api/v1/property/' + property_id + '/submitted_offer_stats.json').success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.get('/api/v1/property/' + property_id + '/submitted_offer_stats.json') ); | |
}; | |
//save and update agreement | |
this.agreementSave = function (id, agreement) { | |
- var d = $q.defer(); | |
- $http.post('/api/v1/property/' + id + '/agreement.json', agreement).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/property/' + id + '/agreement.json', agreement) ); | |
}; | |
//save listing contact avatar | |
this.uploadListingAvatar = function (file, property_contact) { | |
- | |
- var d = $q.defer(); | |
var propertyJson; | |
var propertyFormrequest; | |
@@ -595,41 +253,13 @@ app.service('PropertyService', ['$http', '$q', '$filter', function ($http, $q, $ | |
// API modified as, if contact exist for property then it will update else it will create contact | |
if (typeof property_contact.id != "undefined") { | |
- | |
- $http.put('/api/v1/property_contact/' + property_contact.id + '.json', propertyJson, propertyFormrequest).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
+ return _wrap( $http.put('/api/v1/property_contact/' + property_contact.id + '.json', propertyJson, propertyFormrequest) ); | |
} else { | |
- | |
- | |
- $http.post('/api/v1/property_contact.json', propertyJson, propertyFormrequest).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
+ return _wrap($http.post('/api/v1/property_contact.json', propertyJson, propertyFormrequest)); | |
} | |
- | |
- return d.promise; | |
}; | |
- this.uploadListingAvatar_OLD = function (file, property_contact) { | |
- var d = $q.defer(); | |
+ this.uploadListingAvatar_OLD = function (file, property_contact) { | |
var propertyJson; | |
var propertyFormrequest; | |
@@ -648,74 +278,20 @@ app.service('PropertyService', ['$http', '$q', '$filter', function ($http, $q, $ | |
// API modified as, if contact exist for property then it will update else it will create contact | |
if (typeof property_contact.id != "undefined") { | |
- | |
- $http.put('/api/v1/property/' + property_contact.property_id + '/property_contact/' + property_contact.id + '.json', propertyJson, propertyFormrequest).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
+ return _wrap( $http.put('/api/v1/property/' + property_contact.property_id + '/property_contact/' + property_contact.id + '.json', propertyJson, propertyFormrequest) ); | |
} else { | |
- | |
- | |
- $http.post('/api/v1/property/' + property_contact.property_id + '/property_contact.json', propertyJson, propertyFormrequest).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
+ return _wrap($http.post('/api/v1/property/' + property_contact.property_id + '/property_contact.json', propertyJson, propertyFormrequest)); | |
} | |
- | |
- return d.promise; | |
}; | |
//delete pdf file | |
this.deletePdffile = function (property_id, doc_type_id) { | |
- var d = $q.defer(); | |
- $http.post('/api/v1/property/' + property_id + '/delete_pdf.json', {'property_document': {'id': doc_type_id}}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/property/' + property_id + '/delete_pdf.json', {'property_document': {'id': doc_type_id}}) ); | |
}; | |
//delete property from listing | |
this.deletepropertyLisiting = function (property_id) { | |
- | |
- var d = $q.defer(); | |
- $http.post('/api/v1/property/' + property_id + '/property_delete.json', {'property_id': property_id}).success( | |
- function success(data, status, headers, config) { | |
- if (status == 200) { | |
- d.resolve(data); | |
- } else { | |
- d.reject(data); | |
- } | |
- }).error( | |
- function error(data, status, headers, config) { | |
- d.reject(data); | |
- }); | |
- | |
- return d.promise; | |
+ return _wrap( $http.post('/api/v1/property/' + property_id + '/property_delete.json', {'property_id': property_id}) ); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment