3c004400cdd4d96855aedbb61ce0284274de91eb
[motion2.git] / server / api / faxInteraction / faxInteraction.events.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xe9df=['Users','map','length','catch','hook','events','../../mysqldb','setMaxListeners','update','remove','then','setDataValue'];(function(_0x53afe9,_0x2c9f40){var _0x396396=function(_0x1f574d){while(--_0x1f574d){_0x53afe9['push'](_0x53afe9['shift']());}};_0x396396(++_0x2c9f40);}(_0xe9df,0x89));var _0xfe9d=function(_0x5a600a,_0x21f21e){_0x5a600a=_0x5a600a-0x0;var _0x20fba7=_0xe9df[_0x5a600a];return _0x20fba7;};'use strict';var EventEmitter=require(_0xfe9d('0x0'));var FaxInteraction=require('../../mysqldb')['db']['FaxInteraction'];var FaxMessage=require(_0xfe9d('0x1'))['db']['FaxMessage'];var FaxInteractionEvents=new EventEmitter();FaxInteractionEvents[_0xfe9d('0x2')](0x0);var events={'afterCreate':'save','afterUpdate':_0xfe9d('0x3'),'afterDestroy':_0xfe9d('0x4')};function emitEvent(_0x3c3909){return function(_0x235ed0,_0x223ee2,_0x40b64a){_0x235ed0['getUsers']({'attributes':['id'],'raw':!![]})[_0xfe9d('0x5')](function(_0x1839f2){_0x235ed0[_0xfe9d('0x6')](_0xfe9d('0x7'),_0x1839f2[_0xfe9d('0x8')](function(_0x493858){return{'id':_0x493858['id']};}));return FaxMessage['findAll']({'where':{'FaxInteractionId':_0x235ed0['id'],'direction':'in','read':![]},'raw':!![]});})[_0xfe9d('0x5')](function(_0x48f70c){_0x235ed0[_0xfe9d('0x6')]('unreadMessages',_0x48f70c[_0xfe9d('0x9')]);FaxInteractionEvents['emit'](_0x3c3909+':'+_0x235ed0['id'],_0x235ed0);FaxInteractionEvents['emit'](_0x3c3909,_0x235ed0);_0x40b64a(null);})[_0xfe9d('0xa')](_0x40b64a(null));};}for(var e in events){if(events['hasOwnProperty'](e)){var event=events[e];FaxInteraction[_0xfe9d('0xb')](e,emitEvent(event));}}module['exports']=FaxInteractionEvents;