Saving data from form
Change-Id: If78c7b7a8396a574edbc2cab3fd4150010f103b6
diff --git a/src/app/datasources/rest/model.rest.ts b/src/app/datasources/rest/model.rest.ts
index 51e41d3..8bd2c1f 100644
--- a/src/app/datasources/rest/model.rest.ts
+++ b/src/app/datasources/rest/model.rest.ts
@@ -6,7 +6,6 @@
export class ModelRest implements IXosResourceService {
static $inject = ['$resource'];
- private resource: angular.resource.IResourceClass<any>;
/** @ngInject */
constructor(
@@ -16,6 +15,18 @@
}
public getResource(url: string): ng.resource.IResourceClass<ng.resource.IResource<any>> {
- return this.resource = this.$resource(`${AppConfig.apiEndpoint}${url}/:id/`, {id: '@id'});
+ const resource: angular.resource.IResourceClass<any> = this.$resource(`${AppConfig.apiEndpoint}${url}/:id/`, {id: '@id'}, {
+ update: { method: 'PUT' }
+ });
+
+ resource.prototype.$save = function() {
+ if (this.id) {
+ return this.$update();
+ } else {
+ return resource.save(this).$promise;
+ }
+ };
+
+ return resource;
}
}