Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to place resource specific logic

Can you help me please to consider where to place resource (service) specific business logic in AngularJS. I feel it should be great to create some model-like abstraction over my resource, but I'm not sure how.

API call:

> GET /customers/1
< {"first_name": "John", "last_name": "Doe", "created_at": '1342915200'}

Resource (in CoffeScript):

services = angular.module('billing.services', ['ngResource'])
services.factory('CustomerService', ['$resource', ($resource) ->
  $resource('http://virtualmaster.apiary.io/customers/:id', {}, {
    all: {method: 'GET', params: {}},
    find: {method: 'GET', params: {}, isArray: true}
  })
])

I'd like to do something like:

c = CustomerService.get(1)
c.full_name()
=> "John Doe"

c.months_since_creation()
=> '1 month'

Thanks a lot for any ideas. Adam

like image 864
netmilk Avatar asked Aug 22 '12 15:08

netmilk


People also ask

What is the way to have a dedicated logic app environment?

When you create logic apps and integration accounts that need access to this virtual network, you can select your ISE as the host location for those logic apps and integration accounts. Inside the ISE, logic apps run on dedicated resources separately from others in the multi-tenant Azure Logic Apps environment.

How do I add an existing logic app to ISE?

From the ISE menu, under Settings, select Logic apps > Add. Provide information about the logic app that you want to create, for example: Select this option so you can choose an ISE to use. From the list, select the ISE that you want to use, if not already selected.

What is ISE in Azure?

An integration service environment is a fully isolated and dedicated environment for all enterprise-scale integration needs. When you create a new integration service environment, it's injected into your Azure Virtual Network allowing you to deploy Logic Apps as a service in your VNET.


1 Answers

The best place for logic that needs to be invoked on an instance of a domain object would be a prototype of this domain object.

You could write something along those lines:

services.factory('CustomerService', ['$resource', function($resource) {

    var CustomerService = $resource('http://virtualmaster.apiary.io/customers/:id', {}, {
        all: {
            method: 'GET',
            params: {}
        }
        //more custom resources methods go here....
    });

    CustomerService.prototype.fullName = function(){
       return this.first_name + ' ' + this.last_name;
    };

    //more prototype methods go here....

    return CustomerService;    

}]);
like image 139
pkozlowski.opensource Avatar answered Sep 20 '22 10:09

pkozlowski.opensource