BackendService basic template

Code snippet to use as a foundation for your killer backendservice

Here comes a basic template for a BackendService. It contains "handlers" (well switch-es and case-es) for every known system event.

import { ApplicationBackendServiceBase, BackendServiceEventTypes } from '@dms';
export * from '@dms';
export * from '@dms-bo';

export default class BackendService extends ApplicationBackendServiceBase {

    public async processEvent(
         event: { eventName: string;
         eventArguments: {
                appArea: string;
                appCode: string;
                userName: string;
                request: {
                    httpMethod: string;
                    restCommand: string;
                    headers: any;
                    body: any;
                    queryStringParameters: any;
                };
          };
        }): Promise<any> {

        switch (event.eventName) {
            case "system:schedule:tick": {
                //here comes the interval based processing
                //no need to return anything
                //throw error if something is not as expected
               break;     
            }
            case "system:api:inbound": {                
                //here comes the REST API event processing
                //return some result here
                break;
            }
            case "system:packet:push": {            
                //here comes the packet push processing
                //do not return anything, just throw error if you hit something wrong
                break;
            }
            default: throw new Error("unknown system event");
        }
    }
}

You don't need to respond or process every system event type, so you may skip the case-es for system event types of no interest.

Last updated

Dynamics Mobile provided by Mobile Affairs Ltd. | 1712 Sofia, Bulgaria, Alexander Malinov 51 | sales@dynamicsmobile.com