lib/factories/service.factory.js
function putItAllTogether(serviceInfo, resource, adapter) {
        var me = this;
        var debug = this.injector.debug;

        // loop through the methods
        _.each(resource.methods[serviceInfo.adapterName], function (method) {
            if (!adapter[method]) {
                return;
            }

            // we are going to monkey patch the target method on the adapter, so save the original method
            var origMethod = adapter[method].bind(adapter);
            var eventNameBase = {
                resource: serviceInfo.resourceName,
                adapter: serviceInfo.adapterName,
                method: method
            };

            // create the new service function
            adapter[method] = function (req) {
                req = req || {};

                // clean out request
                _.each(req, function (value, name) {
                    if (value && value === 'undefined') {
                        delete req[name];
                    }
                });

                // add event for data before anything happens (used only for debugging)
                if (debug) { me.emitEvent(req, eventNameBase, { type: 'service', timing: 'before' }); }

                // first validate the request
                return me.validateRequestParams(req, resource, method, serviceInfo.adapterName)
                    .then(function () {

                        // add event before calling the original method (used only for debugging)
                        if (debug) { me.emitEvent(req, eventNameBase, { type: 'service', timing: 'before' }); }

                        // call the original target method on the adapter
                        return origMethod(req);
                    })
                    .then(function (res) {

                        // emit event after origin method called; this is what most
                        // reactors key off of (can be disabled with noemit flag)
                        if (!req.noemit && !req.multi && method !== 'find') {
                            var payload = {
                                caller: req.caller,
                                inputId: req._id,
                                targetId: req.targetId,
                                inputData: req.data,
                                data: res
                            };
                            me.emitEvent(payload, eventNameBase, null);
                        }

                        // return the response that will go back to the calling client
                        return res;
                    });
            };
        });

        // so essentially the service is the adapter with each method bulked up with some extra stuff
        return adapter;
    }
function putItAllTogether(serviceInfo, resource, adapter) {
        var me = this;
        var debug = this.injector.debug;

        // loop through the methods
        _.each(resource.methods[serviceInfo.adapterName], function (method) {
            if (!adapter[method]) {
                return;
            }

            // we are going to monkey patch the target method on the adapter, so save the original method
            var origMethod = adapter[method].bind(adapter);
            var eventNameBase = {
                resource: serviceInfo.resourceName,
                adapter: serviceInfo.adapterName,
                method: method
            };

            // create the new service function
            adapter[method] = function (req) {
                req = req || {};

                // clean out request
                _.each(req, function (value, name) {
                    if (value && value === 'undefined') {
                        delete req[name];
                    }
                });

                // add event for data before anything happens (used only for debugging)
                if (debug) { me.emitEvent(req, eventNameBase, { type: 'service', timing: 'before' }); }

                // first validate the request
                return me.validateRequestParams(req, resource, method, serviceInfo.adapterName)
                    .then(function () {

                        // add event before calling the original method (used only for debugging)
                        if (debug) { me.emitEvent(req, eventNameBase, { type: 'service', timing: 'before' }); }

                        // call the original target method on the adapter
                        return origMethod(req);
                    })
                    .then(function (res) {

                        // emit event after origin method called; this is what most
                        // reactors key off of (can be disabled with noemit flag)
                        if (!req.noemit && !req.multi && method !== 'find') {
                            var payload = {
                                caller: req.caller,
                                inputId: req._id,
                                targetId: req.targetId,
                                inputData: req.data,
                                data: res
                            };
                            me.emitEvent(payload, eventNameBase, null);
                        }

                        // return the response that will go back to the calling client
                        return res;
                    });
            };
        });

        // so essentially the service is the adapter with each method bulked up with some extra stuff
        return adapter;
    }
function putItAllTogether ( serviceInfo , resource , adapter ) { var me = this ; var debug = this . injector . debug ; // loop through the methods _ . each ( resource . methods [ serviceInfo . adapterName ] , function ( method ) { if ( ! adapter [ method ] ) { return ; } // we are going to monkey patch the target method on the adapter, so save the original method var origMethod = adapter [ method ] . bind ( adapter ) ; var eventNameBase = { resource : serviceInfo . resourceName , adapter : serviceInfo . adapterName , method : method } ; // create the new service function adapter [ method ] = function ( req ) { req = req || { } ; // clean out request _ . each ( req , function ( value , name ) { if ( value && value === 'undefined' ) { delete req [ name ] ; } } ) ; // add event for data before anything happens (used only for debugging) if ( debug ) { me . emitEvent ( req , eventNameBase , { type : 'service' , timing : 'before' } ) ; } // first validate the request return me . validateRequestParams ( req , resource , method , serviceInfo . adapterName ) . then ( function ( ) { // add event before calling the original method (used only for debugging) if ( debug ) { me . emitEvent ( req , eventNameBase , { type : 'service' , timing : 'before' } ) ; } // call the original target method on the adapter return origMethod ( req ) ; } ) . then ( function ( res ) { // emit event after origin method called; this is what most // reactors key off of (can be disabled with noemit flag) if ( ! req . noemit && ! req . multi && method !== 'find' ) { var payload = { caller : req . caller , inputId : req . _id , targetId : req . targetId , inputData : req . data , data : res } ; me . emitEvent ( payload , eventNameBase , null ) ; } // return the response that will go back to the calling client return res ; } ) ; } ; } ) ; // so essentially the service is the adapter with each method bulked up with some extra stuff return adapter ; }
Take all the objects involved with a service and put them all together. The final service is really
just an instance of an adapter with each method enhanced to have various filters added

@param serviceInfo
@param resource
@param adapter
@returns {{}}
Take all the objects involved with a service and put them all together . The final service is really just an instance of an adapter with each method enhanced to have various filters added