Built motion from commit d9028345.|2.5.43
[motion2.git] / server / api / chatGroup / chatGroup.controller.js
index d77707a..0942142 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x05f5=['update','then','destroy','status','error','stack','name','index','map','ChatGroup','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','find','create','body','params','describe','ChatInternalMessage','toInteger','addMembers','omit','ids','getMembers','findOne','User','addMessage','ChatGroupId','$gte','format','YYYY-MM-DD\x20HH:mm:ss','getMessages','request-promise','moment','bluebird','util','path','fs-extra','lodash','crypto','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatGroup.socket','sendStatus','end','json','offset','undefined','limit','count','set','Content-Range','reject','save'];(function(_0x4235b3,_0x4295b9){var _0x5a6cc9=function(_0x3cd80d){while(--_0x3cd80d){_0x4235b3['push'](_0x4235b3['shift']());}};_0x5a6cc9(++_0x4295b9);}(_0x05f5,0xef));var _0x505f=function(_0x8be9fb,_0x2f90d9){_0x8be9fb=_0x8be9fb-0x0;var _0x3b41ac=_0x05f5[_0x8be9fb];return _0x3b41ac;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x505f('0x0'));var moment=require(_0x505f('0x1'));var BPromise=require(_0x505f('0x2'));var Mustache=require('mustache');var util=require(_0x505f('0x3'));var path=require(_0x505f('0x4'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x505f('0x5'));var _=require(_0x505f('0x6'));var squel=require('squel');var crypto=require(_0x505f('0x7'));var jsforce=require('jsforce');var deskjs=require(_0x505f('0x8'));var toCsv=require(_0x505f('0x9'));var querystring=require('querystring');var Papa=require(_0x505f('0xa'));var Redis=require(_0x505f('0xb'));var authService=require(_0x505f('0xc'));var qs=require(_0x505f('0xd'));var as=require(_0x505f('0xe'));var hardwareService=require(_0x505f('0xf'));var logger=require(_0x505f('0x10'))('api');var utils=require(_0x505f('0x11'));var config=require(_0x505f('0x12'));var licenseUtil=require(_0x505f('0x13'));var db=require(_0x505f('0x14'))['db'];config[_0x505f('0x15')]=_[_0x505f('0x16')](config[_0x505f('0x15')],{'host':_0x505f('0x17'),'port':0x18eb});var socket=require(_0x505f('0x18'))(new Redis(config[_0x505f('0x15')]));require(_0x505f('0x19'))['register'](socket);function respondWithStatusCode(_0x120aec,_0x146ae1){_0x146ae1=_0x146ae1||0xcc;return function(_0x1c73d1){if(_0x1c73d1){return _0x120aec[_0x505f('0x1a')](_0x146ae1);}return _0x120aec['status'](_0x146ae1)[_0x505f('0x1b')]();};}function respondWithResult(_0x224880,_0x1cf1df){_0x1cf1df=_0x1cf1df||0xc8;return function(_0x27bd0d){if(_0x27bd0d){return _0x224880['status'](_0x1cf1df)[_0x505f('0x1c')](_0x27bd0d);}};}function respondWithFilteredResult(_0x51788f,_0x4310ff){return function(_0x4f0fbb){if(_0x4f0fbb){var _0x3a60da=typeof _0x4310ff[_0x505f('0x1d')]===_0x505f('0x1e')&&typeof _0x4310ff[_0x505f('0x1f')]===_0x505f('0x1e');var _0xf30b09=_0x4f0fbb[_0x505f('0x20')];var _0x2b5ff1=_0x3a60da?0x0:_0x4310ff['offset'];var _0x40ab6c=_0x3a60da?_0x4f0fbb[_0x505f('0x20')]:_0x4310ff[_0x505f('0x1d')]+_0x4310ff[_0x505f('0x1f')];var _0x1dbb7d;if(_0x40ab6c>=_0xf30b09){_0x40ab6c=_0xf30b09;_0x1dbb7d=0xc8;}else{_0x1dbb7d=0xce;}_0x51788f['status'](_0x1dbb7d);return _0x51788f[_0x505f('0x21')](_0x505f('0x22'),_0x2b5ff1+'-'+_0x40ab6c+'/'+_0xf30b09)[_0x505f('0x1c')](_0x4f0fbb);}return null;};}function patchUpdates(_0x49890d){return function(_0x8eba52){try{jsonpatch['apply'](_0x8eba52,_0x49890d,!![]);}catch(_0x429115){return BPromise[_0x505f('0x23')](_0x429115);}return _0x8eba52[_0x505f('0x24')]();};}function saveUpdates(_0x554b8a,_0x47a099){return function(_0x427cf6){if(_0x427cf6){return _0x427cf6[_0x505f('0x25')](_0x554b8a)[_0x505f('0x26')](function(_0x1d1f32){return _0x1d1f32;});}return null;};}function removeEntity(_0x36553f,_0x1bb627){return function(_0x422c5d){if(_0x422c5d){return _0x422c5d[_0x505f('0x27')]()[_0x505f('0x26')](function(){_0x36553f[_0x505f('0x28')](0xcc)[_0x505f('0x1b')]();});}};}function handleEntityNotFound(_0x47f26a,_0x1bcfe4){return function(_0xbe8fea){if(!_0xbe8fea){_0x47f26a[_0x505f('0x1a')](0x194);}return _0xbe8fea;};}function handleError(_0x39cbbe,_0x2b49c1){_0x2b49c1=_0x2b49c1||0x1f4;return function(_0x4486cb){logger[_0x505f('0x29')](_0x4486cb[_0x505f('0x2a')]);if(_0x4486cb['name']){delete _0x4486cb[_0x505f('0x2b')];}_0x39cbbe[_0x505f('0x28')](_0x2b49c1)['send'](_0x4486cb);};}exports[_0x505f('0x2c')]=function(_0xf4a081,_0x3975f7){var _0xe7ad9={},_0x250d25={},_0x57d4d7={'count':0x0,'rows':[]};var _0x2bc6a1=_[_0x505f('0x2d')](db[_0x505f('0x2e')][_0x505f('0x2f')],function(_0xe2a68d){return{'name':_0xe2a68d[_0x505f('0x30')],'type':_0xe2a68d[_0x505f('0x31')]['key']};});_0x250d25[_0x505f('0x32')]=_[_0x505f('0x2d')](_0x2bc6a1,_0x505f('0x2b'));_0x250d25[_0x505f('0x33')]=_[_0x505f('0x34')](_0xf4a081[_0x505f('0x33')]);_0x250d25[_0x505f('0x35')]=_[_0x505f('0x36')](_0x250d25[_0x505f('0x32')],_0x250d25['query']);_0xe7ad9['attributes']=_[_0x505f('0x36')](_0x250d25[_0x505f('0x32')],qs[_0x505f('0x37')](_0xf4a081[_0x505f('0x33')][_0x505f('0x37')]));_0xe7ad9['attributes']=_0xe7ad9[_0x505f('0x38')][_0x505f('0x39')]?_0xe7ad9[_0x505f('0x38')]:_0x250d25['model'];if(!_0xf4a081['query'][_0x505f('0x3a')](_0x505f('0x3b'))){_0xe7ad9[_0x505f('0x1f')]=qs[_0x505f('0x1f')](_0xf4a081[_0x505f('0x33')][_0x505f('0x1f')]);_0xe7ad9[_0x505f('0x1d')]=qs[_0x505f('0x1d')](_0xf4a081[_0x505f('0x33')]['offset']);}_0xe7ad9['order']=qs[_0x505f('0x3c')](_0xf4a081['query'][_0x505f('0x3c')]);_0xe7ad9[_0x505f('0x3d')]=qs['filters'](_[_0x505f('0x3e')](_0xf4a081['query'],_0x250d25[_0x505f('0x35')]),_0x2bc6a1);if(_0xf4a081[_0x505f('0x33')][_0x505f('0x3f')]){_0xe7ad9[_0x505f('0x3d')]=_[_0x505f('0x40')](_0xe7ad9[_0x505f('0x3d')],{'$or':_[_0x505f('0x2d')](_0x2bc6a1,function(_0x5a96fb){if(_0x5a96fb[_0x505f('0x31')]!==_0x505f('0x41')){var _0x42aece={};_0x42aece[_0x5a96fb[_0x505f('0x2b')]]={'$like':'%'+_0xf4a081[_0x505f('0x33')]['filter']+'%'};return _0x42aece;}})});}_0xe7ad9=_[_0x505f('0x40')]({},_0xe7ad9,_0xf4a081[_0x505f('0x42')]);var _0x430471={'where':_0xe7ad9[_0x505f('0x3d')]};return db[_0x505f('0x2e')][_0x505f('0x20')](_0x430471)[_0x505f('0x26')](function(_0x52877b){_0x57d4d7[_0x505f('0x20')]=_0x52877b;if(_0xf4a081[_0x505f('0x33')][_0x505f('0x43')]){_0xe7ad9[_0x505f('0x44')]=[{'all':!![]}];}return db['ChatGroup'][_0x505f('0x45')](_0xe7ad9);})['then'](function(_0x83925c){_0x57d4d7[_0x505f('0x46')]=_0x83925c;return _0x57d4d7;})[_0x505f('0x26')](respondWithFilteredResult(_0x3975f7,_0xe7ad9))[_0x505f('0x47')](handleError(_0x3975f7,null));};exports[_0x505f('0x48')]=function(_0x35cd3d,_0x22d1e2){var _0x5778e9={'raw':!![],'where':{'id':_0x35cd3d['params']['id']}},_0x58247d={};_0x58247d['model']=_[_0x505f('0x34')](db[_0x505f('0x2e')][_0x505f('0x2f')]);_0x58247d[_0x505f('0x33')]=_[_0x505f('0x34')](_0x35cd3d[_0x505f('0x33')]);_0x58247d[_0x505f('0x35')]=_['intersection'](_0x58247d[_0x505f('0x32')],_0x58247d[_0x505f('0x33')]);_0x5778e9[_0x505f('0x38')]=_['intersection'](_0x58247d['model'],qs[_0x505f('0x37')](_0x35cd3d[_0x505f('0x33')]['fields']));_0x5778e9[_0x505f('0x38')]=_0x5778e9[_0x505f('0x38')][_0x505f('0x39')]?_0x5778e9[_0x505f('0x38')]:_0x58247d[_0x505f('0x32')];if(_0x35cd3d[_0x505f('0x33')]['includeAll']){_0x5778e9[_0x505f('0x44')]=[{'all':!![]}];}_0x5778e9=_[_0x505f('0x40')]({},_0x5778e9,_0x35cd3d[_0x505f('0x42')]);return db['ChatGroup'][_0x505f('0x49')](_0x5778e9)[_0x505f('0x26')](handleEntityNotFound(_0x22d1e2,null))[_0x505f('0x26')](respondWithResult(_0x22d1e2,null))[_0x505f('0x47')](handleError(_0x22d1e2,null));};exports[_0x505f('0x4a')]=function(_0x1d7de7,_0x5af503){return db[_0x505f('0x2e')][_0x505f('0x4a')](_0x1d7de7[_0x505f('0x4b')],{})[_0x505f('0x26')](respondWithResult(_0x5af503,0xc9))[_0x505f('0x47')](handleError(_0x5af503,null));};exports[_0x505f('0x25')]=function(_0x25d113,_0x66646f){if(_0x25d113[_0x505f('0x4b')]['id']){delete _0x25d113[_0x505f('0x4b')]['id'];}return db[_0x505f('0x2e')]['find']({'where':{'id':_0x25d113[_0x505f('0x4c')]['id']}})[_0x505f('0x26')](handleEntityNotFound(_0x66646f,null))[_0x505f('0x26')](saveUpdates(_0x25d113[_0x505f('0x4b')],null))[_0x505f('0x26')](respondWithResult(_0x66646f,null))[_0x505f('0x47')](handleError(_0x66646f,null));};exports[_0x505f('0x27')]=function(_0xb07408,_0x501061){return db[_0x505f('0x2e')][_0x505f('0x49')]({'where':{'id':_0xb07408[_0x505f('0x4c')]['id']}})['then'](handleEntityNotFound(_0x501061,null))[_0x505f('0x26')](removeEntity(_0x501061,null))[_0x505f('0x47')](handleError(_0x501061,null));};exports[_0x505f('0x4d')]=function(_0x39af19,_0x1d7743){return db[_0x505f('0x2e')][_0x505f('0x4d')]()[_0x505f('0x26')](respondWithResult(_0x1d7743,null))['catch'](handleError(_0x1d7743,null));};exports['getUnread']=function(_0x452848,_0x194ced,_0x56ae4a){return db[_0x505f('0x4e')]['count']({'where':{'ChatGroupId':_0x452848[_0x505f('0x4c')]['id'],'ToId':_0x452848['user']['id'],'read':![]}})[_0x505f('0x26')](function(_0x57b051){return{'id':_[_0x505f('0x4f')](_0x452848['params']['id']),'count':_0x57b051};})['then'](respondWithResult(_0x194ced,null))[_0x505f('0x47')](handleError(_0x194ced,null));};exports[_0x505f('0x50')]=function(_0x530e43,_0x45241f,_0x5de6d2){return db[_0x505f('0x2e')][_0x505f('0x49')]({'where':{'id':_0x530e43[_0x505f('0x4c')]['id']}})[_0x505f('0x26')](handleEntityNotFound(_0x45241f,null))['then'](function(_0x3cec53){if(_0x3cec53){return _0x3cec53[_0x505f('0x50')](_0x530e43['body']['ids'],_[_0x505f('0x51')](_0x530e43[_0x505f('0x4b')],[_0x505f('0x52'),'id'])||{});}})[_0x505f('0x26')](respondWithResult(_0x45241f,null))[_0x505f('0x47')](handleError(_0x45241f,null));};exports[_0x505f('0x53')]=function(_0x40b288,_0x5c7c96,_0x5835b1){var _0x302e49={};var _0xeb2712={};var _0x6a5467;var _0x4e70c1;return db[_0x505f('0x2e')][_0x505f('0x54')]({'where':{'id':_0x40b288['params']['id']}})[_0x505f('0x26')](handleEntityNotFound(_0x5c7c96,null))[_0x505f('0x26')](function(_0x116231){if(_0x116231){_0x6a5467=_0x116231;_0xeb2712['model']=_[_0x505f('0x34')](db[_0x505f('0x55')]['rawAttributes']);_0xeb2712[_0x505f('0x33')]=_['keys'](_0x40b288[_0x505f('0x33')]);_0xeb2712[_0x505f('0x35')]=_[_0x505f('0x36')](_0xeb2712[_0x505f('0x32')],_0xeb2712['query']);_0x302e49['attributes']=_[_0x505f('0x36')](_0xeb2712[_0x505f('0x32')],qs[_0x505f('0x37')](_0x40b288[_0x505f('0x33')][_0x505f('0x37')]));_0x302e49['attributes']=_0x302e49[_0x505f('0x38')][_0x505f('0x39')]?_0x302e49['attributes']:_0xeb2712['model'];_0x302e49['order']=qs[_0x505f('0x3c')](_0x40b288[_0x505f('0x33')]['sort']);_0x302e49[_0x505f('0x3d')]=qs[_0x505f('0x35')](_[_0x505f('0x3e')](_0x40b288[_0x505f('0x33')],_0xeb2712[_0x505f('0x35')]));if(_0x40b288[_0x505f('0x33')][_0x505f('0x3f')]){_0x302e49[_0x505f('0x3d')]=_[_0x505f('0x40')](_0x302e49[_0x505f('0x3d')],{'$or':_[_0x505f('0x2d')](_0x302e49[_0x505f('0x38')],function(_0x321783){var _0x18b4cf={};_0x18b4cf[_0x321783]={'$like':'%'+_0x40b288[_0x505f('0x33')][_0x505f('0x3f')]+'%'};return _0x18b4cf;})});}_0x302e49=_[_0x505f('0x40')]({},_0x302e49,_0x40b288[_0x505f('0x42')]);return _0x6a5467[_0x505f('0x53')](_0x302e49);}})[_0x505f('0x26')](function(_0x1e5210){if(_0x1e5210){_0x4e70c1=_0x1e5210[_0x505f('0x39')];if(!_0x40b288[_0x505f('0x33')][_0x505f('0x3a')](_0x505f('0x3b'))){_0x302e49['limit']=qs[_0x505f('0x1f')](_0x40b288[_0x505f('0x33')][_0x505f('0x1f')]);_0x302e49[_0x505f('0x1d')]=qs['offset'](_0x40b288[_0x505f('0x33')][_0x505f('0x1d')]);}return _0x6a5467[_0x505f('0x53')](_0x302e49);}})[_0x505f('0x26')](function(_0x579b61){if(_0x579b61){return _0x579b61?{'count':_0x4e70c1,'rows':_0x579b61}:null;}})[_0x505f('0x26')](respondWithResult(_0x5c7c96,null))[_0x505f('0x47')](handleError(_0x5c7c96,null));};exports['removeMembers']=function(_0x35b752,_0x3b2491,_0x35418d){return db['ChatGroup'][_0x505f('0x49')]({'where':{'id':_0x35b752['params']['id']}})[_0x505f('0x26')](handleEntityNotFound(_0x3b2491,null))[_0x505f('0x26')](function(_0x41d8b6){if(_0x41d8b6){return _0x41d8b6['removeMembers'](_0x35b752[_0x505f('0x33')][_0x505f('0x52')]);}})[_0x505f('0x26')](respondWithStatusCode(_0x3b2491,null))[_0x505f('0x47')](handleError(_0x3b2491,null));};exports[_0x505f('0x56')]=function(_0x57693a,_0x24b96e,_0x366d0c){if(_0x57693a['body']['id']){delete _0x57693a['body']['id'];}return db[_0x505f('0x2e')][_0x505f('0x49')]({'where':{'id':_0x57693a[_0x505f('0x4c')]['id']}})[_0x505f('0x26')](handleEntityNotFound(_0x24b96e,null))[_0x505f('0x26')](function(_0x5aacac){if(_0x5aacac){_0x57693a[_0x505f('0x4b')][_0x505f('0x57')]=_0x5aacac['id'];return db[_0x505f('0x4e')][_0x505f('0x4a')](_0x57693a[_0x505f('0x4b')]);}})['then'](respondWithResult(_0x24b96e,null))[_0x505f('0x47')](handleError(_0x24b96e,null));};exports['getMessages']=function(_0x31d722,_0x34691d,_0x32b891){var _0x12c4e4={};var _0x3d1c17={};var _0x5a678e;var _0x40e51f;return db[_0x505f('0x2e')]['findOne']({'where':{'id':_0x31d722[_0x505f('0x4c')]['id']}})[_0x505f('0x26')](handleEntityNotFound(_0x34691d,null))[_0x505f('0x26')](function(_0x4e22e2){if(_0x4e22e2){_0x5a678e=_0x4e22e2;_0x3d1c17[_0x505f('0x32')]=_['keys'](db[_0x505f('0x4e')][_0x505f('0x2f')]);_0x3d1c17['query']=_[_0x505f('0x34')](_0x31d722[_0x505f('0x33')]);_0x3d1c17[_0x505f('0x35')]=_['intersection'](_0x3d1c17['model'],_0x3d1c17[_0x505f('0x33')]);_0x12c4e4['attributes']=_['intersection'](_0x3d1c17[_0x505f('0x32')],qs[_0x505f('0x37')](_0x31d722[_0x505f('0x33')][_0x505f('0x37')]));_0x12c4e4[_0x505f('0x38')]=_0x12c4e4['attributes']['length']?_0x12c4e4[_0x505f('0x38')]:_0x3d1c17['model'];_0x12c4e4['order']=qs[_0x505f('0x3c')](_0x31d722[_0x505f('0x33')][_0x505f('0x3c')]);_0x12c4e4['where']=qs[_0x505f('0x35')](_['pick'](_0x31d722[_0x505f('0x33')],_0x3d1c17[_0x505f('0x35')]));if(_0x31d722['query'][_0x505f('0x3f')]){_0x12c4e4[_0x505f('0x3d')]=_['merge'](_0x12c4e4[_0x505f('0x3d')],{'$or':_[_0x505f('0x2d')](_0x12c4e4[_0x505f('0x38')],function(_0x3f1c7b){var _0x510546={};_0x510546[_0x3f1c7b]={'$like':'%'+_0x31d722[_0x505f('0x33')][_0x505f('0x3f')]+'%'};return _0x510546;})});}if(_0x31d722[_0x505f('0x33')][_0x505f('0x58')]){var _0x132b4d=_0x31d722[_0x505f('0x33')][_0x505f('0x58')]['split'](',');var _0x5d95f3={};_0x5d95f3[_0x132b4d[0x0]]={'$gte':moment(_0x132b4d[0x1])[_0x505f('0x59')](_0x505f('0x5a'))};_0x12c4e4['where']=_[_0x505f('0x40')](_0x12c4e4[_0x505f('0x3d')],_0x5d95f3);}_0x12c4e4=_[_0x505f('0x40')]({},_0x12c4e4,_0x31d722[_0x505f('0x42')]);return _0x5a678e[_0x505f('0x5b')](_0x12c4e4);}})[_0x505f('0x26')](function(_0x401f68){if(_0x401f68){_0x40e51f=_0x401f68[_0x505f('0x39')];if(!_0x31d722[_0x505f('0x33')]['hasOwnProperty'](_0x505f('0x3b'))){_0x12c4e4[_0x505f('0x1f')]=qs[_0x505f('0x1f')](_0x31d722['query'][_0x505f('0x1f')]);_0x12c4e4['offset']=qs[_0x505f('0x1d')](_0x31d722[_0x505f('0x33')]['offset']);}return _0x5a678e[_0x505f('0x5b')](_0x12c4e4);}})['then'](function(_0x1dbc48){if(_0x1dbc48){return _0x1dbc48?{'count':_0x40e51f,'rows':_0x1dbc48}:null;}})[_0x505f('0x26')](respondWithResult(_0x34691d,null))[_0x505f('0x47')](handleError(_0x34691d,null));};
\ No newline at end of file
+var _0x845f=['getMessages','$gte','split','format','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','./chatGroup.socket','register','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','then','destroy','stack','name','send','index','map','ChatGroup','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','merge','options','includeAll','findAll','rows','catch','show','params','include','find','create','update','body','describe','getUnread','user','toInteger','addMembers','ids','getMembers','findOne','User','order','hasOwnProperty','removeMembers','addMessage','ChatInternalMessage'];(function(_0x1ac595,_0x5d2081){var _0x455fff=function(_0x3043ee){while(--_0x3043ee){_0x1ac595['push'](_0x1ac595['shift']());}};_0x455fff(++_0x5d2081);}(_0x845f,0x124));var _0xf845=function(_0x5d5bcb,_0x25e2ea){_0x5d5bcb=_0x5d5bcb-0x0;var _0x4ea5eb=_0x845f[_0x5d5bcb];return _0x4ea5eb;};'use strict';var emlformat=require(_0xf845('0x0'));var rimraf=require(_0xf845('0x1'));var zipdir=require(_0xf845('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf845('0x3'));var moment=require(_0xf845('0x4'));var BPromise=require(_0xf845('0x5'));var Mustache=require(_0xf845('0x6'));var util=require(_0xf845('0x7'));var path=require('path');var sox=require(_0xf845('0x8'));var csv=require(_0xf845('0x9'));var ejs=require(_0xf845('0xa'));var fs=require('fs');var fs_extra=require(_0xf845('0xb'));var _=require(_0xf845('0xc'));var squel=require(_0xf845('0xd'));var crypto=require(_0xf845('0xe'));var jsforce=require(_0xf845('0xf'));var deskjs=require(_0xf845('0x10'));var toCsv=require('to-csv');var querystring=require(_0xf845('0x11'));var Papa=require(_0xf845('0x12'));var Redis=require('ioredis');var authService=require(_0xf845('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf845('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0xf845('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf845('0x16'));var db=require(_0xf845('0x17'))['db'];config['redis']=_[_0xf845('0x18')](config[_0xf845('0x19')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf845('0x19')]));require(_0xf845('0x1a'))[_0xf845('0x1b')](socket);function respondWithStatusCode(_0x3e4dee,_0x57fd43){_0x57fd43=_0x57fd43||0xcc;return function(_0x3d0137){if(_0x3d0137){return _0x3e4dee[_0xf845('0x1c')](_0x57fd43);}return _0x3e4dee[_0xf845('0x1d')](_0x57fd43)[_0xf845('0x1e')]();};}function respondWithResult(_0x39cdd7,_0x559b39){_0x559b39=_0x559b39||0xc8;return function(_0x662638){if(_0x662638){return _0x39cdd7[_0xf845('0x1d')](_0x559b39)['json'](_0x662638);}};}function respondWithFilteredResult(_0x50fe4b,_0x3a79f8){return function(_0x1d0a8a){if(_0x1d0a8a){var _0x269a45=typeof _0x3a79f8[_0xf845('0x1f')]===_0xf845('0x20')&&typeof _0x3a79f8[_0xf845('0x21')]===_0xf845('0x20');var _0x8b8994=_0x1d0a8a[_0xf845('0x22')];var _0x50e54b=_0x269a45?0x0:_0x3a79f8[_0xf845('0x1f')];var _0x215297=_0x269a45?_0x1d0a8a[_0xf845('0x22')]:_0x3a79f8[_0xf845('0x1f')]+_0x3a79f8[_0xf845('0x21')];var _0x90f094;if(_0x215297>=_0x8b8994){_0x215297=_0x8b8994;_0x90f094=0xc8;}else{_0x90f094=0xce;}_0x50fe4b[_0xf845('0x1d')](_0x90f094);return _0x50fe4b[_0xf845('0x23')](_0xf845('0x24'),_0x50e54b+'-'+_0x215297+'/'+_0x8b8994)[_0xf845('0x25')](_0x1d0a8a);}return null;};}function patchUpdates(_0x4fd2bf){return function(_0x5538e2){try{jsonpatch[_0xf845('0x26')](_0x5538e2,_0x4fd2bf,!![]);}catch(_0x227dc5){return BPromise[_0xf845('0x27')](_0x227dc5);}return _0x5538e2[_0xf845('0x28')]();};}function saveUpdates(_0x41cf7e,_0x487636){return function(_0x5dc4cf){if(_0x5dc4cf){return _0x5dc4cf['update'](_0x41cf7e)[_0xf845('0x29')](function(_0x5ac6af){return _0x5ac6af;});}return null;};}function removeEntity(_0x1346b3,_0xa5b728){return function(_0xc3c06f){if(_0xc3c06f){return _0xc3c06f[_0xf845('0x2a')]()[_0xf845('0x29')](function(){_0x1346b3[_0xf845('0x1d')](0xcc)[_0xf845('0x1e')]();});}};}function handleEntityNotFound(_0x1a82d7,_0x310041){return function(_0x19e997){if(!_0x19e997){_0x1a82d7['sendStatus'](0x194);}return _0x19e997;};}function handleError(_0x7936b1,_0x4458df){_0x4458df=_0x4458df||0x1f4;return function(_0x1b43bf){logger['error'](_0x1b43bf[_0xf845('0x2b')]);if(_0x1b43bf[_0xf845('0x2c')]){delete _0x1b43bf[_0xf845('0x2c')];}_0x7936b1[_0xf845('0x1d')](_0x4458df)[_0xf845('0x2d')](_0x1b43bf);};}exports[_0xf845('0x2e')]=function(_0x361720,_0x3b1a64){var _0x1e8dfa={},_0xc804f8={},_0xb51467={'count':0x0,'rows':[]};var _0x50f7a3=_[_0xf845('0x2f')](db[_0xf845('0x30')][_0xf845('0x31')],function(_0x3f449c){return{'name':_0x3f449c[_0xf845('0x32')],'type':_0x3f449c[_0xf845('0x33')]['key']};});_0xc804f8[_0xf845('0x34')]=_['map'](_0x50f7a3,_0xf845('0x2c'));_0xc804f8[_0xf845('0x35')]=_[_0xf845('0x36')](_0x361720['query']);_0xc804f8[_0xf845('0x37')]=_[_0xf845('0x38')](_0xc804f8[_0xf845('0x34')],_0xc804f8[_0xf845('0x35')]);_0x1e8dfa[_0xf845('0x39')]=_[_0xf845('0x38')](_0xc804f8[_0xf845('0x34')],qs[_0xf845('0x3a')](_0x361720[_0xf845('0x35')][_0xf845('0x3a')]));_0x1e8dfa[_0xf845('0x39')]=_0x1e8dfa[_0xf845('0x39')][_0xf845('0x3b')]?_0x1e8dfa[_0xf845('0x39')]:_0xc804f8[_0xf845('0x34')];if(!_0x361720[_0xf845('0x35')]['hasOwnProperty'](_0xf845('0x3c'))){_0x1e8dfa[_0xf845('0x21')]=qs[_0xf845('0x21')](_0x361720[_0xf845('0x35')][_0xf845('0x21')]);_0x1e8dfa[_0xf845('0x1f')]=qs[_0xf845('0x1f')](_0x361720[_0xf845('0x35')][_0xf845('0x1f')]);}_0x1e8dfa['order']=qs[_0xf845('0x3d')](_0x361720[_0xf845('0x35')][_0xf845('0x3d')]);_0x1e8dfa[_0xf845('0x3e')]=qs['filters'](_[_0xf845('0x3f')](_0x361720[_0xf845('0x35')],_0xc804f8['filters']),_0x50f7a3);if(_0x361720[_0xf845('0x35')][_0xf845('0x40')]){_0x1e8dfa[_0xf845('0x3e')]=_[_0xf845('0x41')](_0x1e8dfa[_0xf845('0x3e')],{'$or':_[_0xf845('0x2f')](_0x50f7a3,function(_0x1332bb){if(_0x1332bb[_0xf845('0x33')]!=='VIRTUAL'){var _0x484069={};_0x484069[_0x1332bb[_0xf845('0x2c')]]={'$like':'%'+_0x361720[_0xf845('0x35')][_0xf845('0x40')]+'%'};return _0x484069;}})});}_0x1e8dfa=_['merge']({},_0x1e8dfa,_0x361720[_0xf845('0x42')]);var _0x301469={'where':_0x1e8dfa['where']};return db[_0xf845('0x30')][_0xf845('0x22')](_0x301469)[_0xf845('0x29')](function(_0x595c89){_0xb51467[_0xf845('0x22')]=_0x595c89;if(_0x361720[_0xf845('0x35')][_0xf845('0x43')]){_0x1e8dfa['include']=[{'all':!![]}];}return db[_0xf845('0x30')][_0xf845('0x44')](_0x1e8dfa);})[_0xf845('0x29')](function(_0x310e91){_0xb51467[_0xf845('0x45')]=_0x310e91;return _0xb51467;})[_0xf845('0x29')](respondWithFilteredResult(_0x3b1a64,_0x1e8dfa))[_0xf845('0x46')](handleError(_0x3b1a64,null));};exports[_0xf845('0x47')]=function(_0x7f2c34,_0x563a5d){var _0x3cf36c={'raw':!![],'where':{'id':_0x7f2c34[_0xf845('0x48')]['id']}},_0x46d1d1={};_0x46d1d1[_0xf845('0x34')]=_[_0xf845('0x36')](db[_0xf845('0x30')][_0xf845('0x31')]);_0x46d1d1['query']=_['keys'](_0x7f2c34[_0xf845('0x35')]);_0x46d1d1[_0xf845('0x37')]=_[_0xf845('0x38')](_0x46d1d1['model'],_0x46d1d1[_0xf845('0x35')]);_0x3cf36c[_0xf845('0x39')]=_[_0xf845('0x38')](_0x46d1d1[_0xf845('0x34')],qs['fields'](_0x7f2c34[_0xf845('0x35')][_0xf845('0x3a')]));_0x3cf36c[_0xf845('0x39')]=_0x3cf36c[_0xf845('0x39')]['length']?_0x3cf36c[_0xf845('0x39')]:_0x46d1d1[_0xf845('0x34')];if(_0x7f2c34['query'][_0xf845('0x43')]){_0x3cf36c[_0xf845('0x49')]=[{'all':!![]}];}_0x3cf36c=_[_0xf845('0x41')]({},_0x3cf36c,_0x7f2c34[_0xf845('0x42')]);return db['ChatGroup'][_0xf845('0x4a')](_0x3cf36c)[_0xf845('0x29')](handleEntityNotFound(_0x563a5d,null))[_0xf845('0x29')](respondWithResult(_0x563a5d,null))[_0xf845('0x46')](handleError(_0x563a5d,null));};exports['create']=function(_0x274a8a,_0x5fe4cf){return db[_0xf845('0x30')][_0xf845('0x4b')](_0x274a8a['body'],{})[_0xf845('0x29')](respondWithResult(_0x5fe4cf,0xc9))[_0xf845('0x46')](handleError(_0x5fe4cf,null));};exports[_0xf845('0x4c')]=function(_0x585821,_0x12ea74){if(_0x585821['body']['id']){delete _0x585821['body']['id'];}return db[_0xf845('0x30')][_0xf845('0x4a')]({'where':{'id':_0x585821['params']['id']}})['then'](handleEntityNotFound(_0x12ea74,null))['then'](saveUpdates(_0x585821[_0xf845('0x4d')],null))[_0xf845('0x29')](respondWithResult(_0x12ea74,null))['catch'](handleError(_0x12ea74,null));};exports[_0xf845('0x2a')]=function(_0x3ab6a7,_0xa2f870){return db['ChatGroup'][_0xf845('0x4a')]({'where':{'id':_0x3ab6a7[_0xf845('0x48')]['id']}})['then'](handleEntityNotFound(_0xa2f870,null))[_0xf845('0x29')](removeEntity(_0xa2f870,null))[_0xf845('0x46')](handleError(_0xa2f870,null));};exports['describe']=function(_0x75613a,_0xce9b1e){return db['ChatGroup'][_0xf845('0x4e')]()[_0xf845('0x29')](respondWithResult(_0xce9b1e,null))[_0xf845('0x46')](handleError(_0xce9b1e,null));};exports[_0xf845('0x4f')]=function(_0x352ea0,_0x4724ba,_0x369a6b){return db['ChatInternalMessage'][_0xf845('0x22')]({'where':{'ChatGroupId':_0x352ea0[_0xf845('0x48')]['id'],'ToId':_0x352ea0[_0xf845('0x50')]['id'],'read':![]}})['then'](function(_0xd52f7e){return{'id':_[_0xf845('0x51')](_0x352ea0[_0xf845('0x48')]['id']),'count':_0xd52f7e};})[_0xf845('0x29')](respondWithResult(_0x4724ba,null))[_0xf845('0x46')](handleError(_0x4724ba,null));};exports[_0xf845('0x52')]=function(_0xd09f03,_0xe75c7f,_0x5f5613){return db[_0xf845('0x30')]['find']({'where':{'id':_0xd09f03[_0xf845('0x48')]['id']}})['then'](handleEntityNotFound(_0xe75c7f,null))[_0xf845('0x29')](function(_0x413640){if(_0x413640){return _0x413640[_0xf845('0x52')](_0xd09f03[_0xf845('0x4d')]['ids'],_['omit'](_0xd09f03[_0xf845('0x4d')],[_0xf845('0x53'),'id'])||{});}})['then'](respondWithResult(_0xe75c7f,null))[_0xf845('0x46')](handleError(_0xe75c7f,null));};exports[_0xf845('0x54')]=function(_0xf0340e,_0xa73cfb,_0x3d1d49){var _0x136e5c={};var _0x1420b5={};var _0x358285;var _0x2e2d66;return db['ChatGroup'][_0xf845('0x55')]({'where':{'id':_0xf0340e[_0xf845('0x48')]['id']}})['then'](handleEntityNotFound(_0xa73cfb,null))[_0xf845('0x29')](function(_0x2a4aed){if(_0x2a4aed){_0x358285=_0x2a4aed;_0x1420b5['model']=_[_0xf845('0x36')](db[_0xf845('0x56')]['rawAttributes']);_0x1420b5[_0xf845('0x35')]=_['keys'](_0xf0340e['query']);_0x1420b5[_0xf845('0x37')]=_[_0xf845('0x38')](_0x1420b5[_0xf845('0x34')],_0x1420b5['query']);_0x136e5c['attributes']=_[_0xf845('0x38')](_0x1420b5[_0xf845('0x34')],qs[_0xf845('0x3a')](_0xf0340e[_0xf845('0x35')]['fields']));_0x136e5c[_0xf845('0x39')]=_0x136e5c[_0xf845('0x39')][_0xf845('0x3b')]?_0x136e5c[_0xf845('0x39')]:_0x1420b5[_0xf845('0x34')];_0x136e5c[_0xf845('0x57')]=qs[_0xf845('0x3d')](_0xf0340e[_0xf845('0x35')][_0xf845('0x3d')]);_0x136e5c[_0xf845('0x3e')]=qs[_0xf845('0x37')](_[_0xf845('0x3f')](_0xf0340e['query'],_0x1420b5[_0xf845('0x37')]));if(_0xf0340e[_0xf845('0x35')][_0xf845('0x40')]){_0x136e5c[_0xf845('0x3e')]=_[_0xf845('0x41')](_0x136e5c['where'],{'$or':_[_0xf845('0x2f')](_0x136e5c['attributes'],function(_0x8f5069){var _0x257c8a={};_0x257c8a[_0x8f5069]={'$like':'%'+_0xf0340e['query'][_0xf845('0x40')]+'%'};return _0x257c8a;})});}_0x136e5c=_[_0xf845('0x41')]({},_0x136e5c,_0xf0340e[_0xf845('0x42')]);return _0x358285['getMembers'](_0x136e5c);}})[_0xf845('0x29')](function(_0xc9336a){if(_0xc9336a){_0x2e2d66=_0xc9336a[_0xf845('0x3b')];if(!_0xf0340e['query'][_0xf845('0x58')]('nolimit')){_0x136e5c[_0xf845('0x21')]=qs[_0xf845('0x21')](_0xf0340e[_0xf845('0x35')][_0xf845('0x21')]);_0x136e5c[_0xf845('0x1f')]=qs[_0xf845('0x1f')](_0xf0340e[_0xf845('0x35')][_0xf845('0x1f')]);}return _0x358285[_0xf845('0x54')](_0x136e5c);}})[_0xf845('0x29')](function(_0x34f5b9){if(_0x34f5b9){return _0x34f5b9?{'count':_0x2e2d66,'rows':_0x34f5b9}:null;}})[_0xf845('0x29')](respondWithResult(_0xa73cfb,null))[_0xf845('0x46')](handleError(_0xa73cfb,null));};exports[_0xf845('0x59')]=function(_0x5a5195,_0x39cdac,_0x184321){return db[_0xf845('0x30')]['find']({'where':{'id':_0x5a5195[_0xf845('0x48')]['id']}})[_0xf845('0x29')](handleEntityNotFound(_0x39cdac,null))[_0xf845('0x29')](function(_0x432b0f){if(_0x432b0f){return _0x432b0f[_0xf845('0x59')](_0x5a5195[_0xf845('0x35')][_0xf845('0x53')]);}})['then'](respondWithStatusCode(_0x39cdac,null))['catch'](handleError(_0x39cdac,null));};exports[_0xf845('0x5a')]=function(_0x27aa41,_0x5683a9,_0x563a7f){if(_0x27aa41[_0xf845('0x4d')]['id']){delete _0x27aa41['body']['id'];}return db[_0xf845('0x30')]['find']({'where':{'id':_0x27aa41[_0xf845('0x48')]['id']}})[_0xf845('0x29')](handleEntityNotFound(_0x5683a9,null))['then'](function(_0x139842){if(_0x139842){_0x27aa41['body']['ChatGroupId']=_0x139842['id'];return db[_0xf845('0x5b')]['create'](_0x27aa41['body']);}})[_0xf845('0x29')](respondWithResult(_0x5683a9,null))[_0xf845('0x46')](handleError(_0x5683a9,null));};exports[_0xf845('0x5c')]=function(_0x46e179,_0x555132,_0x4271fe){var _0x1f9c37={};var _0x35b146={};var _0x585720;var _0x3d7d61;return db[_0xf845('0x30')]['findOne']({'where':{'id':_0x46e179[_0xf845('0x48')]['id']}})[_0xf845('0x29')](handleEntityNotFound(_0x555132,null))['then'](function(_0x1bcdd0){if(_0x1bcdd0){_0x585720=_0x1bcdd0;_0x35b146[_0xf845('0x34')]=_['keys'](db['ChatInternalMessage'][_0xf845('0x31')]);_0x35b146[_0xf845('0x35')]=_[_0xf845('0x36')](_0x46e179[_0xf845('0x35')]);_0x35b146[_0xf845('0x37')]=_[_0xf845('0x38')](_0x35b146[_0xf845('0x34')],_0x35b146['query']);_0x1f9c37[_0xf845('0x39')]=_[_0xf845('0x38')](_0x35b146[_0xf845('0x34')],qs[_0xf845('0x3a')](_0x46e179['query'][_0xf845('0x3a')]));_0x1f9c37[_0xf845('0x39')]=_0x1f9c37[_0xf845('0x39')][_0xf845('0x3b')]?_0x1f9c37[_0xf845('0x39')]:_0x35b146[_0xf845('0x34')];_0x1f9c37[_0xf845('0x57')]=qs['sort'](_0x46e179[_0xf845('0x35')][_0xf845('0x3d')]);_0x1f9c37[_0xf845('0x3e')]=qs[_0xf845('0x37')](_[_0xf845('0x3f')](_0x46e179['query'],_0x35b146['filters']));if(_0x46e179[_0xf845('0x35')][_0xf845('0x40')]){_0x1f9c37[_0xf845('0x3e')]=_[_0xf845('0x41')](_0x1f9c37[_0xf845('0x3e')],{'$or':_['map'](_0x1f9c37[_0xf845('0x39')],function(_0x1cd838){var _0x31a9bc={};_0x31a9bc[_0x1cd838]={'$like':'%'+_0x46e179[_0xf845('0x35')][_0xf845('0x40')]+'%'};return _0x31a9bc;})});}if(_0x46e179['query'][_0xf845('0x5d')]){var _0x34d12f=_0x46e179[_0xf845('0x35')]['$gte'][_0xf845('0x5e')](',');var _0x31efac={};_0x31efac[_0x34d12f[0x0]]={'$gte':moment(_0x34d12f[0x1])[_0xf845('0x5f')]('YYYY-MM-DD\x20HH:mm:ss')};_0x1f9c37[_0xf845('0x3e')]=_[_0xf845('0x41')](_0x1f9c37[_0xf845('0x3e')],_0x31efac);}_0x1f9c37=_[_0xf845('0x41')]({},_0x1f9c37,_0x46e179[_0xf845('0x42')]);return _0x585720[_0xf845('0x5c')](_0x1f9c37);}})['then'](function(_0x5cdbd3){if(_0x5cdbd3){_0x3d7d61=_0x5cdbd3['length'];if(!_0x46e179[_0xf845('0x35')][_0xf845('0x58')](_0xf845('0x3c'))){_0x1f9c37[_0xf845('0x21')]=qs[_0xf845('0x21')](_0x46e179[_0xf845('0x35')][_0xf845('0x21')]);_0x1f9c37['offset']=qs['offset'](_0x46e179['query'][_0xf845('0x1f')]);}return _0x585720[_0xf845('0x5c')](_0x1f9c37);}})[_0xf845('0x29')](function(_0xacfcb3){if(_0xacfcb3){return _0xacfcb3?{'count':_0x3d7d61,'rows':_0xacfcb3}:null;}})[_0xf845('0x29')](respondWithResult(_0x555132,null))[_0xf845('0x46')](handleError(_0x555132,null));};
\ No newline at end of file