Skip to content

Commit

Permalink
Refactor js services to work with function expression
Browse files Browse the repository at this point in the history
  • Loading branch information
mfahim committed Jun 12, 2014
1 parent 7172199 commit b797dea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
24 changes: 15 additions & 9 deletions Termeh.Web/Scripts/app/services/jobs/job.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
app.factory('jobSvc', ['$resource', '$q', 'serviceHelperSvc', function ($resource, $q, serviceHelper) {
(function () {
var jobSvc = function($resource, $q, serviceHelper) {
var jobServiceInstance = serviceHelper.Job;

return {
getTopFiveJobs: function () {
getTopFiveJobs: function() {
return jobServiceInstance.query({ count: 5 });
},
getJobs: function () {
getJobs: function() {
return jobServiceInstance.query();
},
deleteJob: function (jobId) {
deleteJob: function(jobId) {
return jobServiceInstance.delete({ jobId: jobId }).$promise;
},
addJob: function (job) {
addJob: function(job) {
return jobServiceInstance.save(job).$promise;
},
editJob: function (job) {
editJob: function(job) {
return jobServiceInstance.update(job).$promise;
},
getJob: function (id) {
getJob: function(id) {
return jobServiceInstance.get({ jobId: id });
},
createJobEditFormModel: function (jobId) {
createJobEditFormModel: function(jobId) {
var singleJob = $q.all([this.getJob(jobId).$promise]);
singleJob.then(function(data) {
return data;
});
return singleJob;
}
};
}]);

};

jobSvc.$inject = ['$resource', '$q', 'serviceHelperSvc'];
app.factory('jobSvc', jobSvc);
}());
17 changes: 11 additions & 6 deletions Termeh.Web/Scripts/app/services/jobs/jobAttachment.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
app.factory('jobAttachmentSvc', ['$resource', '$q', 'serviceHelperSvc', function ($resource, $q, serviceHelper) {
(function () {
var jobAttachmentSvc = function ($resource, $q, serviceHelper) {
var jobAttachService = serviceHelper.JobAttachment;

return {
getAttachmentsForAJob: function (jobId) {
getAttachmentsForAJob: function(jobId) {
return jobAttachService.query({ jobId: jobId });
},
deleteJobAttachment: function (attachmentId) {
deleteJobAttachment: function(attachmentId) {
return jobAttachService.delete({ attachmentId: attachmentId }).$promise;
},
addJobAttachment: function (jobAttachment) {
addJobAttachment: function(jobAttachment) {
return jobAttachService.save({ jobAttachmentId: jobAttachment.Id }, jobAttachment).$promise;
},
getJobAttachment: function (attachmentId) {
getJobAttachment: function(attachmentId) {
return jobAttachService.get({ jobAttachmentId: attachmentId });
}
};
}]);
};

jobAttachmentSvc.$inject = ['$resource', '$q', 'serviceHelperSvc'];
app.factory('jobAttachmentSvc', ['$resource', '$q', 'serviceHelperSvc'], jobAttachmentSvc);
}());
11 changes: 9 additions & 2 deletions Termeh.Web/Scripts/app/services/jobs/jobStatus.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
app.factory('jobStatusSvc', ['$resource', 'serviceHelperSvc', function ($resource, serviceHelper) {
(function () {

var jobStatusSvc = function ($resource, serviceHelper) {
var JobStatus = serviceHelper.JobStatus;

return {
get: function () {
return JobStatus.query();
}
};
}]);
};

jobStatusSvc.$inject = ['$resource', 'serviceHelperSvc'];
app.factory('jobStatusSvc', jobStatusSvc);

}());

0 comments on commit b797dea

Please sign in to comment.