Built motion from commit 746c7d2a.|2.5.35
[motion2.git] / server / api / chatInternalMessage / chatInternalMessage.controller.js
index 5562b0f..ebe5d97 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0b53=['squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./chatInternalMessage.socket','register','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','pick','filter','where','VIRTUAL','options','includeAll','include','ChatInternalMessage','rows','show','params','merge','find','catch','create','body','describe','get','messages','createdAt','lastMessage','lastMessageAt','format','getUsers','User','findAll','agent','admin','user','fullname','role','userpic','online','lastLoginAt','allowmessenger','VoiceQueue','VoiceQueues','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','isEmpty','resourceId','push','FromId','ToId','read','-createdAt','all','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash'];(function(_0x40d7f6,_0x489e50){var _0x2bfda6=function(_0x25af44){while(--_0x25af44){_0x40d7f6['push'](_0x40d7f6['shift']());}};_0x2bfda6(++_0x489e50);}(_0x0b53,0x1c7));var _0x30b5=function(_0x12d033,_0x25fa2f){_0x12d033=_0x12d033-0x0;var _0x3b4e80=_0x0b53[_0x12d033];return _0x3b4e80;};'use strict';var emlformat=require(_0x30b5('0x0'));var rimraf=require(_0x30b5('0x1'));var zipdir=require(_0x30b5('0x2'));var jsonpatch=require(_0x30b5('0x3'));var rp=require(_0x30b5('0x4'));var moment=require(_0x30b5('0x5'));var BPromise=require(_0x30b5('0x6'));var Mustache=require(_0x30b5('0x7'));var util=require('util');var path=require(_0x30b5('0x8'));var sox=require('sox');var csv=require(_0x30b5('0x9'));var ejs=require(_0x30b5('0xa'));var fs=require('fs');var fs_extra=require(_0x30b5('0xb'));var _=require(_0x30b5('0xc'));var squel=require(_0x30b5('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x30b5('0xe'));var toCsv=require(_0x30b5('0x9'));var querystring=require(_0x30b5('0xf'));var Papa=require(_0x30b5('0x10'));var Redis=require(_0x30b5('0x11'));var authService=require(_0x30b5('0x12'));var qs=require(_0x30b5('0x13'));var as=require(_0x30b5('0x14'));var hardwareService=require(_0x30b5('0x15'));var logger=require(_0x30b5('0x16'))(_0x30b5('0x17'));var utils=require('../../config/utils');var config=require(_0x30b5('0x18'));var licenseUtil=require(_0x30b5('0x19'));var db=require(_0x30b5('0x1a'))['db'];config['redis']=_[_0x30b5('0x1b')](config[_0x30b5('0x1c')],{'host':_0x30b5('0x1d'),'port':0x18eb});var socket=require(_0x30b5('0x1e'))(new Redis(config['redis']));require(_0x30b5('0x1f'))[_0x30b5('0x20')](socket);function respondWithStatusCode(_0x482f79,_0x48335b){_0x48335b=_0x48335b||0xcc;return function(_0x149bc9){if(_0x149bc9){return _0x482f79[_0x30b5('0x21')](_0x48335b);}return _0x482f79[_0x30b5('0x22')](_0x48335b)[_0x30b5('0x23')]();};}function respondWithResult(_0xbd5afb,_0x3d58d0){_0x3d58d0=_0x3d58d0||0xc8;return function(_0x2edc5f){if(_0x2edc5f){return _0xbd5afb[_0x30b5('0x22')](_0x3d58d0)[_0x30b5('0x24')](_0x2edc5f);}};}function respondWithFilteredResult(_0x165b8,_0xba4f57){return function(_0x274d57){if(_0x274d57){var _0x37e461=typeof _0xba4f57[_0x30b5('0x25')]===_0x30b5('0x26')&&typeof _0xba4f57['limit']===_0x30b5('0x26');var _0x3dfbaa=_0x274d57[_0x30b5('0x27')];var _0xbf157c=_0x37e461?0x0:_0xba4f57[_0x30b5('0x25')];var _0x2e5e0e=_0x37e461?_0x274d57[_0x30b5('0x27')]:_0xba4f57['offset']+_0xba4f57[_0x30b5('0x28')];var _0x452f08;if(_0x2e5e0e>=_0x3dfbaa){_0x2e5e0e=_0x3dfbaa;_0x452f08=0xc8;}else{_0x452f08=0xce;}_0x165b8[_0x30b5('0x22')](_0x452f08);return _0x165b8[_0x30b5('0x29')](_0x30b5('0x2a'),_0xbf157c+'-'+_0x2e5e0e+'/'+_0x3dfbaa)[_0x30b5('0x24')](_0x274d57);}return null;};}function patchUpdates(_0xfae486){return function(_0x3585a6){try{jsonpatch[_0x30b5('0x2b')](_0x3585a6,_0xfae486,!![]);}catch(_0x111cc9){return BPromise[_0x30b5('0x2c')](_0x111cc9);}return _0x3585a6[_0x30b5('0x2d')]();};}function saveUpdates(_0x501963,_0x2b7a7f){return function(_0xfc778e){if(_0xfc778e){return _0xfc778e[_0x30b5('0x2e')](_0x501963)[_0x30b5('0x2f')](function(_0x4cb9bc){return _0x4cb9bc;});}return null;};}function removeEntity(_0x8a2127,_0x41bb9d){return function(_0x541a80){if(_0x541a80){return _0x541a80[_0x30b5('0x30')]()[_0x30b5('0x2f')](function(){_0x8a2127[_0x30b5('0x22')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1abcc8,_0x2e2a5d){return function(_0x2b03c5){if(!_0x2b03c5){_0x1abcc8[_0x30b5('0x21')](0x194);}return _0x2b03c5;};}function handleError(_0x37be5d,_0xa9855c){_0xa9855c=_0xa9855c||0x1f4;return function(_0x1ebca8){logger['error'](_0x1ebca8[_0x30b5('0x31')]);if(_0x1ebca8[_0x30b5('0x32')]){delete _0x1ebca8[_0x30b5('0x32')];}_0x37be5d[_0x30b5('0x22')](_0xa9855c)['send'](_0x1ebca8);};}exports[_0x30b5('0x33')]=function(_0x424931,_0x4b3c25){var _0x46f0a7={},_0x20b04b={},_0x2a3d90={'count':0x0,'rows':[]};var _0x177331=_[_0x30b5('0x34')](db['ChatInternalMessage'][_0x30b5('0x35')],function(_0x3d9841){return{'name':_0x3d9841[_0x30b5('0x36')],'type':_0x3d9841[_0x30b5('0x37')][_0x30b5('0x38')]};});_0x20b04b[_0x30b5('0x39')]=_[_0x30b5('0x34')](_0x177331,_0x30b5('0x32'));_0x20b04b[_0x30b5('0x3a')]=_[_0x30b5('0x3b')](_0x424931['query']);_0x20b04b[_0x30b5('0x3c')]=_[_0x30b5('0x3d')](_0x20b04b['model'],_0x20b04b[_0x30b5('0x3a')]);_0x46f0a7['attributes']=_[_0x30b5('0x3d')](_0x20b04b[_0x30b5('0x39')],qs[_0x30b5('0x3e')](_0x424931[_0x30b5('0x3a')][_0x30b5('0x3e')]));_0x46f0a7[_0x30b5('0x3f')]=_0x46f0a7[_0x30b5('0x3f')][_0x30b5('0x40')]?_0x46f0a7[_0x30b5('0x3f')]:_0x20b04b[_0x30b5('0x39')];if(!_0x424931[_0x30b5('0x3a')]['hasOwnProperty'](_0x30b5('0x41'))){_0x46f0a7[_0x30b5('0x28')]=qs[_0x30b5('0x28')](_0x424931[_0x30b5('0x3a')][_0x30b5('0x28')]);_0x46f0a7[_0x30b5('0x25')]=qs[_0x30b5('0x25')](_0x424931[_0x30b5('0x3a')]['offset']);}_0x46f0a7[_0x30b5('0x42')]=qs[_0x30b5('0x43')](_0x424931[_0x30b5('0x3a')][_0x30b5('0x43')]);_0x46f0a7['where']=qs[_0x30b5('0x3c')](_[_0x30b5('0x44')](_0x424931[_0x30b5('0x3a')],_0x20b04b['filters']),_0x177331);if(_0x424931['query'][_0x30b5('0x45')]){_0x46f0a7['where']=_['merge'](_0x46f0a7[_0x30b5('0x46')],{'$or':_[_0x30b5('0x34')](_0x177331,function(_0x1dc443){if(_0x1dc443[_0x30b5('0x37')]!==_0x30b5('0x47')){var _0x40e174={};_0x40e174[_0x1dc443['name']]={'$like':'%'+_0x424931[_0x30b5('0x3a')][_0x30b5('0x45')]+'%'};return _0x40e174;}})});}_0x46f0a7=_['merge']({},_0x46f0a7,_0x424931[_0x30b5('0x48')]);var _0x5b9c3c={'where':_0x46f0a7[_0x30b5('0x46')]};return db['ChatInternalMessage'][_0x30b5('0x27')](_0x5b9c3c)[_0x30b5('0x2f')](function(_0x54434d){_0x2a3d90[_0x30b5('0x27')]=_0x54434d;if(_0x424931[_0x30b5('0x3a')][_0x30b5('0x49')]){_0x46f0a7[_0x30b5('0x4a')]=[{'all':!![]}];}return db[_0x30b5('0x4b')]['findAll'](_0x46f0a7);})[_0x30b5('0x2f')](function(_0x2ad42a){_0x2a3d90[_0x30b5('0x4c')]=_0x2ad42a;return _0x2a3d90;})[_0x30b5('0x2f')](respondWithFilteredResult(_0x4b3c25,_0x46f0a7))['catch'](handleError(_0x4b3c25,null));};exports[_0x30b5('0x4d')]=function(_0x4dbc5b,_0x20ecc6){var _0x11026e={'raw':!![],'where':{'id':_0x4dbc5b[_0x30b5('0x4e')]['id']}},_0x2b02e0={};_0x2b02e0[_0x30b5('0x39')]=_[_0x30b5('0x3b')](db[_0x30b5('0x4b')]['rawAttributes']);_0x2b02e0['query']=_[_0x30b5('0x3b')](_0x4dbc5b[_0x30b5('0x3a')]);_0x2b02e0['filters']=_[_0x30b5('0x3d')](_0x2b02e0[_0x30b5('0x39')],_0x2b02e0[_0x30b5('0x3a')]);_0x11026e[_0x30b5('0x3f')]=_[_0x30b5('0x3d')](_0x2b02e0[_0x30b5('0x39')],qs[_0x30b5('0x3e')](_0x4dbc5b[_0x30b5('0x3a')][_0x30b5('0x3e')]));_0x11026e[_0x30b5('0x3f')]=_0x11026e[_0x30b5('0x3f')][_0x30b5('0x40')]?_0x11026e['attributes']:_0x2b02e0['model'];if(_0x4dbc5b[_0x30b5('0x3a')][_0x30b5('0x49')]){_0x11026e[_0x30b5('0x4a')]=[{'all':!![]}];}_0x11026e=_[_0x30b5('0x4f')]({},_0x11026e,_0x4dbc5b[_0x30b5('0x48')]);return db[_0x30b5('0x4b')][_0x30b5('0x50')](_0x11026e)['then'](handleEntityNotFound(_0x20ecc6,null))[_0x30b5('0x2f')](respondWithResult(_0x20ecc6,null))[_0x30b5('0x51')](handleError(_0x20ecc6,null));};exports[_0x30b5('0x52')]=function(_0x49a07a,_0x2d798f){return db[_0x30b5('0x4b')][_0x30b5('0x52')](_0x49a07a[_0x30b5('0x53')],{})[_0x30b5('0x2f')](respondWithResult(_0x2d798f,0xc9))[_0x30b5('0x51')](handleError(_0x2d798f,null));};exports['update']=function(_0x201388,_0x4bfaed){if(_0x201388[_0x30b5('0x53')]['id']){delete _0x201388[_0x30b5('0x53')]['id'];}return db[_0x30b5('0x4b')]['find']({'where':{'id':_0x201388[_0x30b5('0x4e')]['id']}})['then'](handleEntityNotFound(_0x4bfaed,null))[_0x30b5('0x2f')](saveUpdates(_0x201388[_0x30b5('0x53')],null))['then'](respondWithResult(_0x4bfaed,null))['catch'](handleError(_0x4bfaed,null));};exports[_0x30b5('0x30')]=function(_0x32055c,_0x3cb333){return db['ChatInternalMessage'][_0x30b5('0x50')]({'where':{'id':_0x32055c['params']['id']}})[_0x30b5('0x2f')](handleEntityNotFound(_0x3cb333,null))[_0x30b5('0x2f')](removeEntity(_0x3cb333,null))[_0x30b5('0x51')](handleError(_0x3cb333,null));};exports[_0x30b5('0x54')]=function(_0x4c9acc,_0x5762fa){return db[_0x30b5('0x4b')]['describe']()[_0x30b5('0x2f')](respondWithResult(_0x5762fa,null))['catch'](handleError(_0x5762fa,null));};function wrapUser(_0x515a49){return function(_0x45d2e5){var _0x17620c=_0x515a49[_0x30b5('0x55')]({'plain':!![]});_0x17620c[_0x30b5('0x56')]=[];if(_0x45d2e5){_0x17620c['lastMessageAt']=_0x45d2e5[_0x30b5('0x57')];_0x17620c[_0x30b5('0x58')]=_0x45d2e5;}else{_0x17620c[_0x30b5('0x59')]=moment(0x0)[_0x30b5('0x5a')]('YYYY-MM-DD\x20HH:mm:ss');_0x17620c[_0x30b5('0x58')]={};}return _0x17620c;};}exports[_0x30b5('0x5b')]=function(_0x48bfbc,_0x5e9b85,_0x2e9c14){var _0x127ee7=[];return db[_0x30b5('0x5c')][_0x30b5('0x5d')]({'where':{'role':[_0x30b5('0x5e'),_0x30b5('0x5f'),_0x30b5('0x60')]},'attributes':['id',_0x30b5('0x61'),_0x30b5('0x32'),_0x30b5('0x62'),_0x30b5('0x63'),'internal',_0x30b5('0x64'),_0x30b5('0x65'),_0x30b5('0x66'),'showWebBar'],'order':qs[_0x30b5('0x43')]('-online'),'include':[{'model':db[_0x30b5('0x67')],'as':_0x30b5('0x68'),'attributes':['id',_0x30b5('0x32'),_0x30b5('0x37')],'through':{'attributes':[]}}]})['then'](function(_0x4e9c4f){if(_0x4e9c4f){var _0x586ff6=_0x48bfbc['user'][_0x30b5('0x55')]({'plain':!![]});if(!_0x586ff6)throw new Error(_0x30b5('0x69'));if(_0x586ff6[_0x30b5('0x62')]===_0x30b5('0x60')){return db[_0x30b5('0x6a')][_0x30b5('0x50')]({'where':{'name':'Agents','userProfileId':_0x586ff6[_0x30b5('0x6b')]},'raw':!![]})[_0x30b5('0x2f')](function(_0x37b7e8){if(_0x37b7e8){if(_0x37b7e8[_0x30b5('0x6c')]===0x0){return db['UserProfileResource'][_0x30b5('0x5d')]({'where':{'sectionId':_0x37b7e8['id']},'raw':!![]})[_0x30b5('0x2f')](function(_0x46c11a){var _0x205eeb=[];if(_[_0x30b5('0x6d')](_0x46c11a)){_0x205eeb=_[_0x30b5('0x45')](_0x4e9c4f,function(_0x135800){if(_0x135800[_0x30b5('0x62')]!==_0x30b5('0x5e')){return _0x135800;}});return _0x205eeb;}else{for(var _0x54a988=0x0;_0x54a988<_0x4e9c4f[_0x30b5('0x40')];_0x54a988++){var _0x3fa41e=_0x4e9c4f[_0x54a988];if(_0x3fa41e[_0x30b5('0x62')]===_0x30b5('0x5e')){var _0x184826=_[_0x30b5('0x50')](_0x46c11a,function(_0x4b900d){return _0x4b900d[_0x30b5('0x6e')]===_0x3fa41e['id'];});if(_0x184826)_0x205eeb['push'](_0x3fa41e);}else{_0x205eeb[_0x30b5('0x6f')](_0x3fa41e);}}return _0x205eeb;}});}else{return _0x4e9c4f;}}else{var _0x1713e0=_[_0x30b5('0x45')](_0x4e9c4f,function(_0xda44f8){if(_0xda44f8[_0x30b5('0x62')]!==_0x30b5('0x5e')){return _0xda44f8;}});return _0x1713e0;}});}else{return _0x4e9c4f;}}})[_0x30b5('0x2f')](function(_0x47802d){var _0x159b5f=[];if(_0x47802d){_0x127ee7=_0x47802d;for(var _0x1026ce=0x0;_0x1026ce<_0x47802d[_0x30b5('0x40')];_0x1026ce+=0x1){_0x127ee7[_0x1026ce][_0x30b5('0x56')]=[];_0x159b5f[_0x30b5('0x6f')](db[_0x30b5('0x4b')][_0x30b5('0x50')]({'where':{'FromId':[_0x48bfbc['user']['id'],_0x47802d[_0x1026ce]['id']],'ToId':[_0x48bfbc[_0x30b5('0x60')]['id'],_0x47802d[_0x1026ce]['id']],'ChatGroupId':null},'attributes':['id',_0x30b5('0x57'),_0x30b5('0x70'),_0x30b5('0x71'),_0x30b5('0x72'),_0x30b5('0x53')],'order':qs[_0x30b5('0x43')](_0x30b5('0x73')),'limit':0x1,'offset':0x0,'raw':!![]})[_0x30b5('0x2f')](wrapUser(_0x47802d[_0x1026ce])));}return BPromise[_0x30b5('0x74')](_0x159b5f);}return[];})[_0x30b5('0x2f')](function(_0x3cde6a){return{'rows':_0x3cde6a,'count':_0x3cde6a[_0x30b5('0x40')]};})[_0x30b5('0x2f')](respondWithResult(_0x5e9b85,null))[_0x30b5('0x51')](handleError(_0x5e9b85,null));};
\ No newline at end of file
+var _0x2f54=['count','includeAll','include','findAll','catch','show','params','keys','options','find','create','body','describe','get','messages','lastMessageAt','createdAt','lastMessage','YYYY-MM-DD\x20HH:mm:ss','getUsers','User','agent','admin','fullname','role','userpic','internal','online','lastLoginAt','allowmessenger','showWebBar','-online','VoiceQueue','VoiceQueues','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','Agents','userProfileId','autoAssociation','UserProfileResource','isEmpty','length','resourceId','FromId','read','all','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','defaults','redis','localhost','socket.io-emitter','./chatInternalMessage.socket','register','sendStatus','status','json','offset','limit','set','apply','reject','save','update','destroy','then','end','stack','name','send','index','map','ChatInternalMessage','rawAttributes','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL'];(function(_0x420eb0,_0x1fb312){var _0x5d80a5=function(_0x224e84){while(--_0x224e84){_0x420eb0['push'](_0x420eb0['shift']());}};_0x5d80a5(++_0x1fb312);}(_0x2f54,0x1f3));var _0x42f5=function(_0x4482af,_0x2df282){_0x4482af=_0x4482af-0x0;var _0x1874e5=_0x2f54[_0x4482af];return _0x1874e5;};'use strict';var emlformat=require(_0x42f5('0x0'));var rimraf=require(_0x42f5('0x1'));var zipdir=require(_0x42f5('0x2'));var jsonpatch=require(_0x42f5('0x3'));var rp=require(_0x42f5('0x4'));var moment=require('moment');var BPromise=require(_0x42f5('0x5'));var Mustache=require('mustache');var util=require(_0x42f5('0x6'));var path=require('path');var sox=require(_0x42f5('0x7'));var csv=require(_0x42f5('0x8'));var ejs=require(_0x42f5('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0x42f5('0xa'));var jsforce=require(_0x42f5('0xb'));var deskjs=require(_0x42f5('0xc'));var toCsv=require(_0x42f5('0x8'));var querystring=require(_0x42f5('0xd'));var Papa=require(_0x42f5('0xe'));var Redis=require(_0x42f5('0xf'));var authService=require(_0x42f5('0x10'));var qs=require(_0x42f5('0x11'));var as=require(_0x42f5('0x12'));var hardwareService=require(_0x42f5('0x13'));var logger=require(_0x42f5('0x14'))(_0x42f5('0x15'));var utils=require(_0x42f5('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x42f5('0x17'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x42f5('0x18')](config[_0x42f5('0x19')],{'host':_0x42f5('0x1a'),'port':0x18eb});var socket=require(_0x42f5('0x1b'))(new Redis(config[_0x42f5('0x19')]));require(_0x42f5('0x1c'))[_0x42f5('0x1d')](socket);function respondWithStatusCode(_0x522284,_0x29b176){_0x29b176=_0x29b176||0xcc;return function(_0x486342){if(_0x486342){return _0x522284[_0x42f5('0x1e')](_0x29b176);}return _0x522284['status'](_0x29b176)['end']();};}function respondWithResult(_0x29c00e,_0x4a4c50){_0x4a4c50=_0x4a4c50||0xc8;return function(_0x96701e){if(_0x96701e){return _0x29c00e[_0x42f5('0x1f')](_0x4a4c50)[_0x42f5('0x20')](_0x96701e);}};}function respondWithFilteredResult(_0x144675,_0xfa92ba){return function(_0x2c2387){if(_0x2c2387){var _0x5879ae=typeof _0xfa92ba[_0x42f5('0x21')]==='undefined'&&typeof _0xfa92ba['limit']==='undefined';var _0x220104=_0x2c2387['count'];var _0x2c5ec1=_0x5879ae?0x0:_0xfa92ba['offset'];var _0x1b67a7=_0x5879ae?_0x2c2387['count']:_0xfa92ba[_0x42f5('0x21')]+_0xfa92ba[_0x42f5('0x22')];var _0xf6ecff;if(_0x1b67a7>=_0x220104){_0x1b67a7=_0x220104;_0xf6ecff=0xc8;}else{_0xf6ecff=0xce;}_0x144675['status'](_0xf6ecff);return _0x144675[_0x42f5('0x23')]('Content-Range',_0x2c5ec1+'-'+_0x1b67a7+'/'+_0x220104)[_0x42f5('0x20')](_0x2c2387);}return null;};}function patchUpdates(_0x411279){return function(_0x201d15){try{jsonpatch[_0x42f5('0x24')](_0x201d15,_0x411279,!![]);}catch(_0x5cd647){return BPromise[_0x42f5('0x25')](_0x5cd647);}return _0x201d15[_0x42f5('0x26')]();};}function saveUpdates(_0xc91c7f,_0x55367c){return function(_0x6fcd13){if(_0x6fcd13){return _0x6fcd13[_0x42f5('0x27')](_0xc91c7f)['then'](function(_0x5af1e1){return _0x5af1e1;});}return null;};}function removeEntity(_0x2b8ce9,_0x34c607){return function(_0x2868b6){if(_0x2868b6){return _0x2868b6[_0x42f5('0x28')]()[_0x42f5('0x29')](function(){_0x2b8ce9[_0x42f5('0x1f')](0xcc)[_0x42f5('0x2a')]();});}};}function handleEntityNotFound(_0x1afb9f,_0x49651a){return function(_0x3fbca3){if(!_0x3fbca3){_0x1afb9f[_0x42f5('0x1e')](0x194);}return _0x3fbca3;};}function handleError(_0x5c5ba5,_0x191a95){_0x191a95=_0x191a95||0x1f4;return function(_0x5c07fa){logger['error'](_0x5c07fa[_0x42f5('0x2b')]);if(_0x5c07fa[_0x42f5('0x2c')]){delete _0x5c07fa[_0x42f5('0x2c')];}_0x5c5ba5[_0x42f5('0x1f')](_0x191a95)[_0x42f5('0x2d')](_0x5c07fa);};}exports[_0x42f5('0x2e')]=function(_0x571bd3,_0x57b1ce){var _0x31c055={},_0xbee25={},_0x5b5d66={'count':0x0,'rows':[]};var _0x2a0763=_[_0x42f5('0x2f')](db[_0x42f5('0x30')][_0x42f5('0x31')],function(_0xba9b3d){return{'name':_0xba9b3d['fieldName'],'type':_0xba9b3d[_0x42f5('0x32')][_0x42f5('0x33')]};});_0xbee25[_0x42f5('0x34')]=_[_0x42f5('0x2f')](_0x2a0763,_0x42f5('0x2c'));_0xbee25[_0x42f5('0x35')]=_['keys'](_0x571bd3[_0x42f5('0x35')]);_0xbee25[_0x42f5('0x36')]=_[_0x42f5('0x37')](_0xbee25[_0x42f5('0x34')],_0xbee25[_0x42f5('0x35')]);_0x31c055[_0x42f5('0x38')]=_['intersection'](_0xbee25['model'],qs[_0x42f5('0x39')](_0x571bd3[_0x42f5('0x35')]['fields']));_0x31c055[_0x42f5('0x38')]=_0x31c055['attributes']['length']?_0x31c055[_0x42f5('0x38')]:_0xbee25[_0x42f5('0x34')];if(!_0x571bd3[_0x42f5('0x35')][_0x42f5('0x3a')]('nolimit')){_0x31c055[_0x42f5('0x22')]=qs[_0x42f5('0x22')](_0x571bd3[_0x42f5('0x35')][_0x42f5('0x22')]);_0x31c055[_0x42f5('0x21')]=qs[_0x42f5('0x21')](_0x571bd3[_0x42f5('0x35')][_0x42f5('0x21')]);}_0x31c055[_0x42f5('0x3b')]=qs[_0x42f5('0x3c')](_0x571bd3[_0x42f5('0x35')]['sort']);_0x31c055[_0x42f5('0x3d')]=qs[_0x42f5('0x36')](_[_0x42f5('0x3e')](_0x571bd3[_0x42f5('0x35')],_0xbee25['filters']),_0x2a0763);if(_0x571bd3[_0x42f5('0x35')][_0x42f5('0x3f')]){_0x31c055['where']=_[_0x42f5('0x40')](_0x31c055[_0x42f5('0x3d')],{'$or':_[_0x42f5('0x2f')](_0x2a0763,function(_0x9520a0){if(_0x9520a0[_0x42f5('0x32')]!==_0x42f5('0x41')){var _0xf0107e={};_0xf0107e[_0x9520a0[_0x42f5('0x2c')]]={'$like':'%'+_0x571bd3['query'][_0x42f5('0x3f')]+'%'};return _0xf0107e;}})});}_0x31c055=_[_0x42f5('0x40')]({},_0x31c055,_0x571bd3['options']);var _0x59b313={'where':_0x31c055[_0x42f5('0x3d')]};return db[_0x42f5('0x30')][_0x42f5('0x42')](_0x59b313)['then'](function(_0x16604c){_0x5b5d66[_0x42f5('0x42')]=_0x16604c;if(_0x571bd3[_0x42f5('0x35')][_0x42f5('0x43')]){_0x31c055[_0x42f5('0x44')]=[{'all':!![]}];}return db[_0x42f5('0x30')][_0x42f5('0x45')](_0x31c055);})['then'](function(_0x2727d1){_0x5b5d66['rows']=_0x2727d1;return _0x5b5d66;})[_0x42f5('0x29')](respondWithFilteredResult(_0x57b1ce,_0x31c055))[_0x42f5('0x46')](handleError(_0x57b1ce,null));};exports[_0x42f5('0x47')]=function(_0x4d8161,_0x352e62){var _0x354f7c={'raw':!![],'where':{'id':_0x4d8161[_0x42f5('0x48')]['id']}},_0x547c14={};_0x547c14[_0x42f5('0x34')]=_[_0x42f5('0x49')](db['ChatInternalMessage'][_0x42f5('0x31')]);_0x547c14[_0x42f5('0x35')]=_[_0x42f5('0x49')](_0x4d8161[_0x42f5('0x35')]);_0x547c14[_0x42f5('0x36')]=_[_0x42f5('0x37')](_0x547c14['model'],_0x547c14[_0x42f5('0x35')]);_0x354f7c[_0x42f5('0x38')]=_[_0x42f5('0x37')](_0x547c14[_0x42f5('0x34')],qs['fields'](_0x4d8161[_0x42f5('0x35')][_0x42f5('0x39')]));_0x354f7c['attributes']=_0x354f7c[_0x42f5('0x38')]['length']?_0x354f7c[_0x42f5('0x38')]:_0x547c14[_0x42f5('0x34')];if(_0x4d8161['query'][_0x42f5('0x43')]){_0x354f7c[_0x42f5('0x44')]=[{'all':!![]}];}_0x354f7c=_[_0x42f5('0x40')]({},_0x354f7c,_0x4d8161[_0x42f5('0x4a')]);return db[_0x42f5('0x30')][_0x42f5('0x4b')](_0x354f7c)['then'](handleEntityNotFound(_0x352e62,null))['then'](respondWithResult(_0x352e62,null))[_0x42f5('0x46')](handleError(_0x352e62,null));};exports['create']=function(_0x8d035c,_0x25e3a8){return db[_0x42f5('0x30')][_0x42f5('0x4c')](_0x8d035c[_0x42f5('0x4d')],{})['then'](respondWithResult(_0x25e3a8,0xc9))[_0x42f5('0x46')](handleError(_0x25e3a8,null));};exports[_0x42f5('0x27')]=function(_0x4e388f,_0x5be7fd){if(_0x4e388f[_0x42f5('0x4d')]['id']){delete _0x4e388f['body']['id'];}return db[_0x42f5('0x30')][_0x42f5('0x4b')]({'where':{'id':_0x4e388f[_0x42f5('0x48')]['id']}})['then'](handleEntityNotFound(_0x5be7fd,null))[_0x42f5('0x29')](saveUpdates(_0x4e388f[_0x42f5('0x4d')],null))['then'](respondWithResult(_0x5be7fd,null))[_0x42f5('0x46')](handleError(_0x5be7fd,null));};exports[_0x42f5('0x28')]=function(_0x172044,_0x2d5664){return db[_0x42f5('0x30')][_0x42f5('0x4b')]({'where':{'id':_0x172044[_0x42f5('0x48')]['id']}})[_0x42f5('0x29')](handleEntityNotFound(_0x2d5664,null))['then'](removeEntity(_0x2d5664,null))['catch'](handleError(_0x2d5664,null));};exports[_0x42f5('0x4e')]=function(_0x411526,_0x2874f4){return db['ChatInternalMessage']['describe']()['then'](respondWithResult(_0x2874f4,null))[_0x42f5('0x46')](handleError(_0x2874f4,null));};function wrapUser(_0x143fcb){return function(_0x25ea77){var _0x55b92a=_0x143fcb[_0x42f5('0x4f')]({'plain':!![]});_0x55b92a[_0x42f5('0x50')]=[];if(_0x25ea77){_0x55b92a[_0x42f5('0x51')]=_0x25ea77[_0x42f5('0x52')];_0x55b92a[_0x42f5('0x53')]=_0x25ea77;}else{_0x55b92a[_0x42f5('0x51')]=moment(0x0)['format'](_0x42f5('0x54'));_0x55b92a['lastMessage']={};}return _0x55b92a;};}exports[_0x42f5('0x55')]=function(_0x47bba6,_0x2c1542,_0x1acfca){var _0x1562c7=[];return db[_0x42f5('0x56')][_0x42f5('0x45')]({'where':{'role':[_0x42f5('0x57'),_0x42f5('0x58'),'user']},'attributes':['id',_0x42f5('0x59'),_0x42f5('0x2c'),_0x42f5('0x5a'),_0x42f5('0x5b'),_0x42f5('0x5c'),_0x42f5('0x5d'),_0x42f5('0x5e'),_0x42f5('0x5f'),_0x42f5('0x60')],'order':qs[_0x42f5('0x3c')](_0x42f5('0x61')),'include':[{'model':db[_0x42f5('0x62')],'as':_0x42f5('0x63'),'attributes':['id',_0x42f5('0x2c'),_0x42f5('0x32')],'through':{'attributes':[]}}]})[_0x42f5('0x29')](function(_0x2f5ee1){if(_0x2f5ee1){var _0x4ab09a=_0x47bba6[_0x42f5('0x64')][_0x42f5('0x4f')]({'plain':!![]});if(!_0x4ab09a)throw new Error(_0x42f5('0x65'));if(_0x4ab09a[_0x42f5('0x5a')]===_0x42f5('0x64')){return db[_0x42f5('0x66')][_0x42f5('0x4b')]({'where':{'name':_0x42f5('0x67'),'userProfileId':_0x4ab09a[_0x42f5('0x68')]},'raw':!![]})[_0x42f5('0x29')](function(_0x18e6b4){if(_0x18e6b4){if(_0x18e6b4[_0x42f5('0x69')]===0x0){return db[_0x42f5('0x6a')][_0x42f5('0x45')]({'where':{'sectionId':_0x18e6b4['id']},'raw':!![]})[_0x42f5('0x29')](function(_0x4eac96){var _0x40f2f6=[];if(_[_0x42f5('0x6b')](_0x4eac96)){_0x40f2f6=_[_0x42f5('0x3f')](_0x2f5ee1,function(_0x537bad){if(_0x537bad[_0x42f5('0x5a')]!=='agent'){return _0x537bad;}});return _0x40f2f6;}else{for(var _0x1975dd=0x0;_0x1975dd<_0x2f5ee1[_0x42f5('0x6c')];_0x1975dd++){var _0x1a7970=_0x2f5ee1[_0x1975dd];if(_0x1a7970['role']==='agent'){var _0x4753c2=_[_0x42f5('0x4b')](_0x4eac96,function(_0x14aec7){return _0x14aec7[_0x42f5('0x6d')]===_0x1a7970['id'];});if(_0x4753c2)_0x40f2f6['push'](_0x1a7970);}else{_0x40f2f6['push'](_0x1a7970);}}return _0x40f2f6;}});}else{return _0x2f5ee1;}}else{var _0x5eb00e=_[_0x42f5('0x3f')](_0x2f5ee1,function(_0x5256d0){if(_0x5256d0[_0x42f5('0x5a')]!==_0x42f5('0x57')){return _0x5256d0;}});return _0x5eb00e;}});}else{return _0x2f5ee1;}}})['then'](function(_0x3bb734){var _0x363fb7=[];if(_0x3bb734){_0x1562c7=_0x3bb734;for(var _0x2ba29c=0x0;_0x2ba29c<_0x3bb734['length'];_0x2ba29c+=0x1){_0x1562c7[_0x2ba29c]['messages']=[];_0x363fb7['push'](db['ChatInternalMessage'][_0x42f5('0x4b')]({'where':{'FromId':[_0x47bba6[_0x42f5('0x64')]['id'],_0x3bb734[_0x2ba29c]['id']],'ToId':[_0x47bba6[_0x42f5('0x64')]['id'],_0x3bb734[_0x2ba29c]['id']],'ChatGroupId':null},'attributes':['id',_0x42f5('0x52'),_0x42f5('0x6e'),'ToId',_0x42f5('0x6f'),_0x42f5('0x4d')],'order':qs['sort']('-createdAt'),'limit':0x1,'offset':0x0,'raw':!![]})[_0x42f5('0x29')](wrapUser(_0x3bb734[_0x2ba29c])));}return BPromise[_0x42f5('0x70')](_0x363fb7);}return[];})[_0x42f5('0x29')](function(_0x10cf1f){return{'rows':_0x10cf1f,'count':_0x10cf1f[_0x42f5('0x6c')]};})[_0x42f5('0x29')](respondWithResult(_0x2c1542,null))[_0x42f5('0x46')](handleError(_0x2c1542,null));};
\ No newline at end of file