Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / api / smsInteraction / smsInteraction.controller.js
index 259e956..abc7708 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x644f=['fields','length','includeAll','merge','find','body','describe','SmsMessage','addMessage','omit','ids','getMessages','findOne','hasOwnProperty','nolimit','order','sort','where','SmsInteractionId','filter','$gte','split','format','include','findAll','rows','addTags','setTags','Tag','emit','removeTags','download','unix','toString','join','server','tmp','transcript-%d-%s.zip','push','User','CmContact','Contact','firstName','lastName','Messages','createdAt','direction','read','SmsAccount','Account','Owner','fullname','get','mkdirSync','Sms','N.A.','closed','closedAt','YYYY-MM-DD\x20HH:mm:ss','out','System','secret','renderFile','root','downloadInteraction.ejs','transcript-','.pdf','createPdfFromHTML','log','err','unlinkSync','sendStatus','rimraf','zip-dir','util','path','ejs','lodash','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','defaults','redis','socket.io-emitter','register','status','end','offset','undefined','limit','count','Content-Range','json','update','destroy','then','error','name','send','index','map','SmsInteraction','rawAttributes','fieldName','type','key','getOptions','sms','query','catch','show','params','keys','filters','intersection','model','attributes'];(function(_0x17141f,_0x4d7c4b){var _0x3ee900=function(_0x5ec0f4){while(--_0x5ec0f4){_0x17141f['push'](_0x17141f['shift']());}};_0x3ee900(++_0x4d7c4b);}(_0x644f,0xc2));var _0xf644=function(_0x260f28,_0x4e9b30){_0x260f28=_0x260f28-0x0;var _0x3aefcc=_0x644f[_0x260f28];return _0x3aefcc;};'use strict';var rimraf=require(_0xf644('0x0'));var zipdir=require(_0xf644('0x1'));var moment=require('moment');var BPromise=require('bluebird');var util=require(_0xf644('0x2'));var path=require(_0xf644('0x3'));var ejs=require(_0xf644('0x4'));var fs=require('fs');var _=require(_0xf644('0x5'));var Redis=require(_0xf644('0x6'));var interaction=require(_0xf644('0x7'));var qs=require(_0xf644('0x8'));var pdf=require(_0xf644('0x9'));var logger=require(_0xf644('0xa'))(_0xf644('0xb'));var config=require(_0xf644('0xc'));var db=require(_0xf644('0xd'))['db'];config['redis']=_[_0xf644('0xe')](config[_0xf644('0xf')],{'host':'localhost','port':0x18eb});var socket=require(_0xf644('0x10'))(new Redis(config['redis']));require('./smsInteraction.socket')[_0xf644('0x11')](socket);function respondWithStatusCode(_0x4a490d,_0x2c7bd0){_0x2c7bd0=_0x2c7bd0||0xcc;return function(_0x865312){if(_0x865312){return _0x4a490d['sendStatus'](_0x2c7bd0);}return _0x4a490d[_0xf644('0x12')](_0x2c7bd0)[_0xf644('0x13')]();};}function respondWithResult(_0x1ef872,_0x5911d3){_0x5911d3=_0x5911d3||0xc8;return function(_0x296647){if(_0x296647){return _0x1ef872[_0xf644('0x12')](_0x5911d3)['json'](_0x296647);}};}function respondWithFilteredResult(_0x3678c9,_0xaa5d1c){return function(_0x4ed4d6){if(_0x4ed4d6){var _0x400906=typeof _0xaa5d1c[_0xf644('0x14')]===_0xf644('0x15')&&typeof _0xaa5d1c[_0xf644('0x16')]==='undefined';var _0x155fd9=_0x4ed4d6[_0xf644('0x17')];var _0x52f74a=_0x400906?0x0:_0xaa5d1c['offset'];var _0x4c197b=_0x400906?_0x4ed4d6['count']:_0xaa5d1c[_0xf644('0x14')]+_0xaa5d1c[_0xf644('0x16')];var _0x34dec2;if(_0x4c197b>=_0x155fd9){_0x4c197b=_0x155fd9;_0x34dec2=0xc8;}else{_0x34dec2=0xce;}_0x3678c9[_0xf644('0x12')](_0x34dec2);return _0x3678c9['set'](_0xf644('0x18'),_0x52f74a+'-'+_0x4c197b+'/'+_0x155fd9)[_0xf644('0x19')](_0x4ed4d6);}return null;};}function saveUpdates(_0x4650b5){return function(_0x44fc39){if(_0x44fc39){return _0x44fc39[_0xf644('0x1a')](_0x4650b5)['then'](function(_0x4beeb0){return _0x4beeb0;});}return null;};}function removeEntity(_0x37c32d){return function(_0x305515){if(_0x305515){return _0x305515[_0xf644('0x1b')]()[_0xf644('0x1c')](function(){_0x37c32d[_0xf644('0x12')](0xcc)[_0xf644('0x13')]();});}};}function handleEntityNotFound(_0x67e595){return function(_0x20c0fb){if(!_0x20c0fb){_0x67e595['sendStatus'](0x194);}return _0x20c0fb;};}function handleError(_0x14af1b,_0x1c36b4){_0x1c36b4=_0x1c36b4||0x1f4;return function(_0x2180c6){logger[_0xf644('0x1d')](_0x2180c6['stack']);if(_0x2180c6[_0xf644('0x1e')]){delete _0x2180c6[_0xf644('0x1e')];}_0x14af1b[_0xf644('0x12')](_0x1c36b4)[_0xf644('0x1f')](_0x2180c6);};}exports[_0xf644('0x20')]=function(_0x3173c1,_0xae30c0){var _0x4cb86c={};var _0x4b6369=_[_0xf644('0x21')](db[_0xf644('0x22')][_0xf644('0x23')],function(_0x383987){return{'name':_0x383987[_0xf644('0x24')],'type':_0x383987[_0xf644('0x25')][_0xf644('0x26')]};});_0x4cb86c=qs[_0xf644('0x27')](_0x4b6369,_0x3173c1);return interaction['findAll'](_0xf644('0x28'),_0x3173c1[_0xf644('0x29')],_0x3173c1['user'],_0x4cb86c,_0x4b6369)['then'](respondWithFilteredResult(_0xae30c0,_0x4cb86c))[_0xf644('0x2a')](handleError(_0xae30c0,null));};exports[_0xf644('0x2b')]=function(_0x16c745,_0x3881e3){var _0x2bcb20={'raw':![],'where':{'id':_0x16c745[_0xf644('0x2c')]['id']}},_0x1ef501={};_0x1ef501['model']=_[_0xf644('0x2d')](db[_0xf644('0x22')]['rawAttributes']);_0x1ef501['query']=_[_0xf644('0x2d')](_0x16c745[_0xf644('0x29')]);_0x1ef501[_0xf644('0x2e')]=_[_0xf644('0x2f')](_0x1ef501[_0xf644('0x30')],_0x1ef501[_0xf644('0x29')]);_0x2bcb20[_0xf644('0x31')]=_[_0xf644('0x2f')](_0x1ef501[_0xf644('0x30')],qs[_0xf644('0x32')](_0x16c745['query']['fields']));_0x2bcb20[_0xf644('0x31')]=_0x2bcb20[_0xf644('0x31')][_0xf644('0x33')]?_0x2bcb20[_0xf644('0x31')]:_0x1ef501[_0xf644('0x30')];if(_0x16c745[_0xf644('0x29')][_0xf644('0x34')]){_0x2bcb20['include']=[{'all':!![]}];}_0x2bcb20=_[_0xf644('0x35')]({},_0x2bcb20,_0x16c745['options']);return db['SmsInteraction'][_0xf644('0x36')](_0x2bcb20)[_0xf644('0x1c')](handleEntityNotFound(_0x3881e3,null))[_0xf644('0x1c')](respondWithResult(_0x3881e3,null))['catch'](handleError(_0x3881e3,null));};exports['create']=function(_0x3aa198,_0xd5790a){return db[_0xf644('0x22')]['create'](_0x3aa198[_0xf644('0x37')],{})[_0xf644('0x1c')](respondWithResult(_0xd5790a,0xc9))['catch'](handleError(_0xd5790a,null));};exports[_0xf644('0x1a')]=function(_0x67cbfc,_0x27fbc7){if(_0x67cbfc[_0xf644('0x37')]['id']){delete _0x67cbfc[_0xf644('0x37')]['id'];}return db[_0xf644('0x22')]['find']({'where':{'id':_0x67cbfc[_0xf644('0x2c')]['id']}})['then'](handleEntityNotFound(_0x27fbc7,null))[_0xf644('0x1c')](saveUpdates(_0x67cbfc[_0xf644('0x37')],null))[_0xf644('0x1c')](respondWithResult(_0x27fbc7,null))[_0xf644('0x2a')](handleError(_0x27fbc7,null));};exports[_0xf644('0x1b')]=function(_0x60bec,_0x52e738){return db[_0xf644('0x22')][_0xf644('0x36')]({'where':{'id':_0x60bec[_0xf644('0x2c')]['id']}})['then'](handleEntityNotFound(_0x52e738,null))['then'](removeEntity(_0x52e738,null))[_0xf644('0x2a')](handleError(_0x52e738,null));};exports[_0xf644('0x38')]=function(_0x11d879,_0x14efb3){return db['SmsInteraction'][_0xf644('0x38')]()['then'](respondWithResult(_0x14efb3,null))[_0xf644('0x2a')](handleError(_0x14efb3,null));};exports['addMessage']=function(_0x2d9f52,_0x3475cf){return db[_0xf644('0x39')][_0xf644('0x36')]({'where':{'id':_0x2d9f52['params']['id']}})[_0xf644('0x1c')](handleEntityNotFound(_0x3475cf,null))[_0xf644('0x1c')](function(_0x565e83){if(_0x565e83){return _0x565e83[_0xf644('0x3a')](_0x2d9f52[_0xf644('0x37')]['ids'],_[_0xf644('0x3b')](_0x2d9f52['body'],[_0xf644('0x3c'),'id'])||{});}})[_0xf644('0x1c')](respondWithResult(_0x3475cf,null))[_0xf644('0x2a')](handleError(_0x3475cf,null));};exports[_0xf644('0x3d')]=function(_0x29724d,_0x594615){var _0x1062e3={'raw':![],'where':{}};var _0x395340={};var _0x1b9e4f={'count':0x0,'rows':[]};return db[_0xf644('0x22')][_0xf644('0x3e')]({'where':{'id':_0x29724d['params']['id']}})[_0xf644('0x1c')](handleEntityNotFound(_0x594615,null))[_0xf644('0x1c')](function(_0x2db98c){if(_0x2db98c){_0x395340['model']=_[_0xf644('0x2d')](db[_0xf644('0x39')][_0xf644('0x23')]);_0x395340[_0xf644('0x29')]=_['keys'](_0x29724d['query']);_0x395340[_0xf644('0x2e')]=_[_0xf644('0x2f')](_0x395340[_0xf644('0x30')],_0x395340[_0xf644('0x29')]);_0x1062e3['attributes']=_['intersection'](_0x395340[_0xf644('0x30')],qs[_0xf644('0x32')](_0x29724d[_0xf644('0x29')]['fields']));_0x1062e3[_0xf644('0x31')]=_0x1062e3[_0xf644('0x31')][_0xf644('0x33')]?_0x1062e3[_0xf644('0x31')]:_0x395340[_0xf644('0x30')];if(!_0x29724d[_0xf644('0x29')][_0xf644('0x3f')](_0xf644('0x40'))){_0x1062e3[_0xf644('0x16')]=qs['limit'](_0x29724d[_0xf644('0x29')][_0xf644('0x16')]);_0x1062e3[_0xf644('0x14')]=qs[_0xf644('0x14')](_0x29724d[_0xf644('0x29')][_0xf644('0x14')]);}_0x1062e3[_0xf644('0x41')]=qs['sort'](_0x29724d[_0xf644('0x29')][_0xf644('0x42')]);_0x1062e3['where']=qs['filters'](_['pick'](_0x29724d[_0xf644('0x29')],_0x395340['filters']));_0x1062e3[_0xf644('0x43')][_0xf644('0x44')]=_0x2db98c['id'];if(_0x29724d['query'][_0xf644('0x45')]){_0x1062e3[_0xf644('0x43')]=_[_0xf644('0x35')](_0x1062e3[_0xf644('0x43')],{'$or':_[_0xf644('0x21')](_0x1062e3[_0xf644('0x31')],function(_0x40910c){var _0x3d0915={};_0x3d0915[_0x40910c]={'$like':'%'+_0x29724d['query'][_0xf644('0x45')]+'%'};return _0x3d0915;})});}if(_0x29724d[_0xf644('0x29')][_0xf644('0x46')]){var _0x53701d=_0x29724d[_0xf644('0x29')][_0xf644('0x46')][_0xf644('0x47')](',');var _0x58a3b8={};_0x58a3b8[_0x53701d[0x0]]={'$gte':moment(_0x53701d[0x1])[_0xf644('0x48')]('YYYY-MM-DD\x20HH:mm:ss')};_0x1062e3[_0xf644('0x43')]=_['merge'](_0x1062e3[_0xf644('0x43')],_0x58a3b8);}_0x1062e3=_[_0xf644('0x35')]({},_0x1062e3,_0x29724d['options']);return db[_0xf644('0x39')][_0xf644('0x17')]({'where':_0x1062e3[_0xf644('0x43')]})[_0xf644('0x1c')](function(_0x1d68fd){_0x1b9e4f['count']=_0x1d68fd;if(_0x29724d['query'][_0xf644('0x34')]){_0x1062e3[_0xf644('0x49')]=[{'all':!![]}];}return db[_0xf644('0x39')][_0xf644('0x4a')](_0x1062e3);})[_0xf644('0x1c')](function(_0x4763c7){_0x1b9e4f[_0xf644('0x4b')]=_0x4763c7;return _0x1b9e4f;});}})[_0xf644('0x1c')](respondWithFilteredResult(_0x594615,_0x1062e3))[_0xf644('0x2a')](handleError(_0x594615,null));};exports[_0xf644('0x4c')]=function(_0x389c40,_0xf74e1){return db[_0xf644('0x22')][_0xf644('0x36')]({'where':{'id':_0x389c40['params']['id']}})[_0xf644('0x1c')](handleEntityNotFound(_0xf74e1,null))[_0xf644('0x1c')](function(_0x2ad9a3){if(_0x2ad9a3){return _0x2ad9a3[_0xf644('0x4d')](_0x389c40[_0xf644('0x37')][_0xf644('0x3c')],_[_0xf644('0x3b')](_0x389c40[_0xf644('0x37')],[_0xf644('0x3c'),'id'])||{})['spread'](function(){return db[_0xf644('0x4e')][_0xf644('0x4a')]({'attributes':['id',_0xf644('0x1e'),'color'],'where':{'id':_0x389c40[_0xf644('0x37')][_0xf644('0x3c')]}});})['then'](function(_0x4efff5){socket[_0xf644('0x4f')]('smsInteractionTags:save',{'id':Number(_0x389c40[_0xf644('0x2c')]['id']),'tags':_0x4efff5||[]});return{'id':Number(_0x389c40[_0xf644('0x2c')]['id']),'tags':_0x4efff5||[]};});}})[_0xf644('0x1c')](respondWithResult(_0xf74e1,null))['catch'](handleError(_0xf74e1,null));};exports[_0xf644('0x50')]=function(_0xc225ae,_0x41e3d8){return db['SmsInteraction'][_0xf644('0x36')]({'where':{'id':_0xc225ae[_0xf644('0x2c')]['id']}})['then'](handleEntityNotFound(_0x41e3d8,null))[_0xf644('0x1c')](function(_0x479d21){if(_0x479d21){return _0x479d21[_0xf644('0x50')](_0xc225ae['query'][_0xf644('0x3c')]);}})['then'](respondWithStatusCode(_0x41e3d8,null))[_0xf644('0x2a')](handleError(_0x41e3d8,null));};exports[_0xf644('0x51')]=function(_0x27c13d,_0x36c5db){var _0x31e76a=moment()[_0xf644('0x52')]()[_0xf644('0x53')]();var _0xf258d8=path[_0xf644('0x54')](config['root'],_0xf644('0x55'),'files',_0xf644('0x56'));var _0x18b52b=path[_0xf644('0x54')](_0xf258d8,_0x31e76a);var _0xbd0649=util['format'](_0xf644('0x57'),_0x27c13d[_0xf644('0x2c')]['id'],_0x31e76a);var _0x2eac5e=path[_0xf644('0x54')](_0xf258d8,_0xbd0649);var _0x25ccee=[];_0x25ccee[_0xf644('0x58')]({'model':db[_0xf644('0x59')],'as':_0xf644('0x59'),'attributes':['id','fullname'],'raw':!![]});_0x25ccee[_0xf644('0x58')]({'model':db[_0xf644('0x5a')],'as':_0xf644('0x5b'),'attributes':['id',_0xf644('0x5c'),_0xf644('0x5d')],'raw':!![]});var _0x275a9e=[{'model':db[_0xf644('0x39')],'as':_0xf644('0x5e'),'attributes':['id','body',_0xf644('0x5f'),_0xf644('0x60'),'secret',_0xf644('0x61')],'include':_0x25ccee}];_0x275a9e['push']({'model':db[_0xf644('0x62')],'as':_0xf644('0x63'),'attributes':['id',_0xf644('0x1e')]});_0x275a9e['push']({'model':db['User'],'as':_0xf644('0x64'),'attributes':['id',_0xf644('0x65')]});return db[_0xf644('0x22')][_0xf644('0x36')]({'where':{'id':_0x27c13d[_0xf644('0x2c')]['id']},'include':_0x275a9e})['then'](handleEntityNotFound(_0x36c5db,null))[_0xf644('0x1c')](function(_0x4ec2b1){if(_0x4ec2b1){var _0x580871=_0x4ec2b1[_0xf644('0x66')]({'plain':!![]});fs[_0xf644('0x67')](_0x18b52b);var _0x174bfd={'channel':_0xf644('0x68'),'account':_0x580871[_0xf644('0x63')][_0xf644('0x1e')],'agent':_0x580871[_0xf644('0x64')]?_0x580871['Owner'][_0xf644('0x65')]:_0xf644('0x69'),'createdAt':moment(_0x580871[_0xf644('0x5f')])[_0xf644('0x48')]('YYYY-MM-DD\x20HH:mm:ss')['toString'](),'closedAt':_0x580871[_0xf644('0x6a')]?moment(_0x580871[_0xf644('0x6b')])[_0xf644('0x48')](_0xf644('0x6c'))[_0xf644('0x53')]():'','disposition':_0x580871['disposition'],'messages':_(_0x580871['Messages'])['filter']({'secret':![]})[_0xf644('0x21')](function(_0xfd5aad){return{'date':moment(_0xfd5aad[_0xf644('0x5f')])[_0xf644('0x48')](_0xf644('0x6c'))['toString'](),'sender':_0xfd5aad[_0xf644('0x60')]===_0xf644('0x6d')?_0xfd5aad[_0xf644('0x59')]?_0xfd5aad[_0xf644('0x59')][_0xf644('0x65')]:_0xf644('0x6e'):_0xfd5aad[_0xf644('0x5b')]['firstName']+(_0xfd5aad['Contact'][_0xf644('0x5d')]?'\x20'+_0xfd5aad['Contact'][_0xf644('0x5d')]:''),'body':_0xfd5aad[_0xf644('0x37')],'direction':_0xfd5aad[_0xf644('0x60')]===_0xf644('0x6d')?'A':'C','secret':_0xfd5aad[_0xf644('0x6f')],'read':_0xfd5aad[_0xf644('0x61')]};})['value']()};return ejs[_0xf644('0x70')](path['join'](config[_0xf644('0x71')],'server','views',_0xf644('0x72')),{'interaction':_0x174bfd})['then'](function(_0x29f9f9){var _0x2310e8=path['join'](_0x18b52b,_0xf644('0x73')+_0x580871['id']+'-'+_0x31e76a+_0xf644('0x74'));var _0x173a93={'path':_0x2310e8,'channel':_0xf644('0x68'),'interactionId':_0x580871['id']};return pdf[_0xf644('0x75')](_0x29f9f9,_0x173a93);})[_0xf644('0x1c')](function(){return new BPromise(function(_0x1a3ba2,_0x152f1e){zipdir(_0x18b52b,{'saveTo':_0x2eac5e},function(_0x50bdd7,_0x4f485f){if(_0x50bdd7)return _0x152f1e(_0x50bdd7);return _0x1a3ba2(_0x4f485f);});})['then'](function(){return new BPromise(function(_0x49f208,_0x4b3a85){rimraf(_0x18b52b,function(_0x59d2e1){if(_0x59d2e1)_0x4b3a85(_0x59d2e1);return _0x49f208();});});})[_0xf644('0x1c')](function(){return _0x36c5db['download'](_0x2eac5e,_0xbd0649,function(_0x17586f){if(_0x17586f){console[_0xf644('0x76')](_0xf644('0x77'),_0x17586f);}else{fs[_0xf644('0x78')](_0x2eac5e);}});});});}else{return _0x36c5db[_0xf644('0x79')](0xc8);}})['catch'](handleError(_0x36c5db,null));};
\ No newline at end of file
+var _0x992a=['util','path','ejs','ioredis','../../components/interaction/service','../../components/parsers/qs','../../components/export/pdf','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','./smsInteraction.socket','register','sendStatus','status','offset','undefined','count','limit','set','Content-Range','json','update','then','destroy','end','error','stack','name','index','map','SmsInteraction','rawAttributes','type','key','getOptions','findAll','sms','query','catch','show','params','keys','filters','intersection','model','attributes','fields','length','includeAll','include','find','create','body','describe','SmsMessage','addMessage','ids','omit','getMessages','findOne','hasOwnProperty','nolimit','order','sort','where','pick','SmsInteractionId','merge','filter','$gte','split','format','options','rows','addTags','setTags','emit','smsInteractionTags:save','removeTags','download','toString','join','files','tmp','transcript-%d-%s.zip','push','User','CmContact','Contact','Messages','direction','read','SmsAccount','Account','fullname','get','mkdirSync','Sms','Owner','N.A.','createdAt','YYYY-MM-DD\x20HH:mm:ss','closed','closedAt','disposition','out','System','firstName','lastName','secret','renderFile','root','views','transcript-','.pdf','unlinkSync','rimraf','zip-dir','moment','bluebird'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x992a,0x1e8));var _0xa992=function(_0x257642,_0x270a80){_0x257642=_0x257642-0x0;var _0x3d813b=_0x992a[_0x257642];return _0x3d813b;};'use strict';var rimraf=require(_0xa992('0x0'));var zipdir=require(_0xa992('0x1'));var moment=require(_0xa992('0x2'));var BPromise=require(_0xa992('0x3'));var util=require(_0xa992('0x4'));var path=require(_0xa992('0x5'));var ejs=require(_0xa992('0x6'));var fs=require('fs');var _=require('lodash');var Redis=require(_0xa992('0x7'));var interaction=require(_0xa992('0x8'));var qs=require(_0xa992('0x9'));var pdf=require(_0xa992('0xa'));var logger=require(_0xa992('0xb'))(_0xa992('0xc'));var config=require(_0xa992('0xd'));var db=require(_0xa992('0xe'))['db'];config[_0xa992('0xf')]=_[_0xa992('0x10')](config[_0xa992('0xf')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xa992('0xf')]));require(_0xa992('0x11'))[_0xa992('0x12')](socket);function respondWithStatusCode(_0x12fd22,_0x225983){_0x225983=_0x225983||0xcc;return function(_0x59dcf1){if(_0x59dcf1){return _0x12fd22[_0xa992('0x13')](_0x225983);}return _0x12fd22['status'](_0x225983)['end']();};}function respondWithResult(_0x258cc8,_0x24579f){_0x24579f=_0x24579f||0xc8;return function(_0xb346d6){if(_0xb346d6){return _0x258cc8[_0xa992('0x14')](_0x24579f)['json'](_0xb346d6);}};}function respondWithFilteredResult(_0x11a8df,_0x509c5b){return function(_0x43b0f6){if(_0x43b0f6){var _0x4a0b92=typeof _0x509c5b[_0xa992('0x15')]===_0xa992('0x16')&&typeof _0x509c5b['limit']===_0xa992('0x16');var _0x4ab3a6=_0x43b0f6[_0xa992('0x17')];var _0x252e5c=_0x4a0b92?0x0:_0x509c5b[_0xa992('0x15')];var _0x12f023=_0x4a0b92?_0x43b0f6[_0xa992('0x17')]:_0x509c5b[_0xa992('0x15')]+_0x509c5b[_0xa992('0x18')];var _0x1232f4;if(_0x12f023>=_0x4ab3a6){_0x12f023=_0x4ab3a6;_0x1232f4=0xc8;}else{_0x1232f4=0xce;}_0x11a8df[_0xa992('0x14')](_0x1232f4);return _0x11a8df[_0xa992('0x19')](_0xa992('0x1a'),_0x252e5c+'-'+_0x12f023+'/'+_0x4ab3a6)[_0xa992('0x1b')](_0x43b0f6);}return null;};}function saveUpdates(_0x300070){return function(_0x377d82){if(_0x377d82){return _0x377d82[_0xa992('0x1c')](_0x300070)[_0xa992('0x1d')](function(_0x4c88f6){return _0x4c88f6;});}return null;};}function removeEntity(_0x5c4948){return function(_0x35a1ec){if(_0x35a1ec){return _0x35a1ec[_0xa992('0x1e')]()[_0xa992('0x1d')](function(){_0x5c4948['status'](0xcc)[_0xa992('0x1f')]();});}};}function handleEntityNotFound(_0x4e2c41){return function(_0x1921fb){if(!_0x1921fb){_0x4e2c41[_0xa992('0x13')](0x194);}return _0x1921fb;};}function handleError(_0x4040d1,_0x493de2){_0x493de2=_0x493de2||0x1f4;return function(_0xb4fb29){logger[_0xa992('0x20')](_0xb4fb29[_0xa992('0x21')]);if(_0xb4fb29[_0xa992('0x22')]){delete _0xb4fb29['name'];}_0x4040d1['status'](_0x493de2)['send'](_0xb4fb29);};}exports[_0xa992('0x23')]=function(_0x2dcfe6,_0x49fcca){var _0x48c4fd={};var _0x498ab0=_[_0xa992('0x24')](db[_0xa992('0x25')][_0xa992('0x26')],function(_0x393c02){return{'name':_0x393c02['fieldName'],'type':_0x393c02[_0xa992('0x27')][_0xa992('0x28')]};});_0x48c4fd=qs[_0xa992('0x29')](_0x498ab0,_0x2dcfe6);return interaction[_0xa992('0x2a')](_0xa992('0x2b'),_0x2dcfe6[_0xa992('0x2c')],_0x2dcfe6['user'],_0x48c4fd,_0x498ab0)[_0xa992('0x1d')](respondWithFilteredResult(_0x49fcca,_0x48c4fd))[_0xa992('0x2d')](handleError(_0x49fcca,null));};exports[_0xa992('0x2e')]=function(_0x25af99,_0x34c96d){var _0x902089={'raw':![],'where':{'id':_0x25af99[_0xa992('0x2f')]['id']}},_0x68baef={};_0x68baef['model']=_[_0xa992('0x30')](db[_0xa992('0x25')][_0xa992('0x26')]);_0x68baef[_0xa992('0x2c')]=_[_0xa992('0x30')](_0x25af99['query']);_0x68baef[_0xa992('0x31')]=_[_0xa992('0x32')](_0x68baef[_0xa992('0x33')],_0x68baef['query']);_0x902089[_0xa992('0x34')]=_[_0xa992('0x32')](_0x68baef[_0xa992('0x33')],qs[_0xa992('0x35')](_0x25af99[_0xa992('0x2c')][_0xa992('0x35')]));_0x902089[_0xa992('0x34')]=_0x902089[_0xa992('0x34')][_0xa992('0x36')]?_0x902089[_0xa992('0x34')]:_0x68baef[_0xa992('0x33')];if(_0x25af99[_0xa992('0x2c')][_0xa992('0x37')]){_0x902089[_0xa992('0x38')]=[{'all':!![]}];}_0x902089=_['merge']({},_0x902089,_0x25af99['options']);return db[_0xa992('0x25')][_0xa992('0x39')](_0x902089)['then'](handleEntityNotFound(_0x34c96d,null))[_0xa992('0x1d')](respondWithResult(_0x34c96d,null))[_0xa992('0x2d')](handleError(_0x34c96d,null));};exports['create']=function(_0x3643a0,_0x3d6102){return db[_0xa992('0x25')][_0xa992('0x3a')](_0x3643a0[_0xa992('0x3b')],{})[_0xa992('0x1d')](respondWithResult(_0x3d6102,0xc9))[_0xa992('0x2d')](handleError(_0x3d6102,null));};exports['update']=function(_0x1e11c4,_0x115bb5){if(_0x1e11c4['body']['id']){delete _0x1e11c4[_0xa992('0x3b')]['id'];}return db[_0xa992('0x25')][_0xa992('0x39')]({'where':{'id':_0x1e11c4[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x115bb5,null))['then'](saveUpdates(_0x1e11c4[_0xa992('0x3b')],null))[_0xa992('0x1d')](respondWithResult(_0x115bb5,null))[_0xa992('0x2d')](handleError(_0x115bb5,null));};exports[_0xa992('0x1e')]=function(_0x4af7d9,_0xb7dbb0){return db[_0xa992('0x25')][_0xa992('0x39')]({'where':{'id':_0x4af7d9['params']['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0xb7dbb0,null))['then'](removeEntity(_0xb7dbb0,null))['catch'](handleError(_0xb7dbb0,null));};exports[_0xa992('0x3c')]=function(_0x52b363,_0x533805){return db[_0xa992('0x25')]['describe']()[_0xa992('0x1d')](respondWithResult(_0x533805,null))[_0xa992('0x2d')](handleError(_0x533805,null));};exports['addMessage']=function(_0x521e5c,_0x519bac){return db[_0xa992('0x3d')][_0xa992('0x39')]({'where':{'id':_0x521e5c[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x519bac,null))['then'](function(_0x251843){if(_0x251843){return _0x251843[_0xa992('0x3e')](_0x521e5c['body'][_0xa992('0x3f')],_[_0xa992('0x40')](_0x521e5c['body'],[_0xa992('0x3f'),'id'])||{});}})[_0xa992('0x1d')](respondWithResult(_0x519bac,null))[_0xa992('0x2d')](handleError(_0x519bac,null));};exports[_0xa992('0x41')]=function(_0x1e625e,_0x1810fe){var _0x4bfa61={'raw':![],'where':{}};var _0x181649={};var _0x22ecd1={'count':0x0,'rows':[]};return db[_0xa992('0x25')][_0xa992('0x42')]({'where':{'id':_0x1e625e[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x1810fe,null))[_0xa992('0x1d')](function(_0x40155c){if(_0x40155c){_0x181649[_0xa992('0x33')]=_[_0xa992('0x30')](db[_0xa992('0x3d')]['rawAttributes']);_0x181649[_0xa992('0x2c')]=_[_0xa992('0x30')](_0x1e625e[_0xa992('0x2c')]);_0x181649[_0xa992('0x31')]=_[_0xa992('0x32')](_0x181649[_0xa992('0x33')],_0x181649[_0xa992('0x2c')]);_0x4bfa61['attributes']=_['intersection'](_0x181649['model'],qs[_0xa992('0x35')](_0x1e625e[_0xa992('0x2c')][_0xa992('0x35')]));_0x4bfa61[_0xa992('0x34')]=_0x4bfa61[_0xa992('0x34')]['length']?_0x4bfa61[_0xa992('0x34')]:_0x181649[_0xa992('0x33')];if(!_0x1e625e['query'][_0xa992('0x43')](_0xa992('0x44'))){_0x4bfa61[_0xa992('0x18')]=qs[_0xa992('0x18')](_0x1e625e[_0xa992('0x2c')]['limit']);_0x4bfa61[_0xa992('0x15')]=qs[_0xa992('0x15')](_0x1e625e['query'][_0xa992('0x15')]);}_0x4bfa61[_0xa992('0x45')]=qs[_0xa992('0x46')](_0x1e625e[_0xa992('0x2c')][_0xa992('0x46')]);_0x4bfa61[_0xa992('0x47')]=qs[_0xa992('0x31')](_[_0xa992('0x48')](_0x1e625e[_0xa992('0x2c')],_0x181649[_0xa992('0x31')]));_0x4bfa61[_0xa992('0x47')][_0xa992('0x49')]=_0x40155c['id'];if(_0x1e625e[_0xa992('0x2c')]['filter']){_0x4bfa61[_0xa992('0x47')]=_[_0xa992('0x4a')](_0x4bfa61[_0xa992('0x47')],{'$or':_[_0xa992('0x24')](_0x4bfa61[_0xa992('0x34')],function(_0x21c07e){var _0x4e815e={};_0x4e815e[_0x21c07e]={'$like':'%'+_0x1e625e[_0xa992('0x2c')][_0xa992('0x4b')]+'%'};return _0x4e815e;})});}if(_0x1e625e['query'][_0xa992('0x4c')]){var _0x29e6f2=_0x1e625e['query'][_0xa992('0x4c')][_0xa992('0x4d')](',');var _0x3fdfab={};_0x3fdfab[_0x29e6f2[0x0]]={'$gte':moment(_0x29e6f2[0x1])[_0xa992('0x4e')]('YYYY-MM-DD\x20HH:mm:ss')};_0x4bfa61[_0xa992('0x47')]=_['merge'](_0x4bfa61[_0xa992('0x47')],_0x3fdfab);}_0x4bfa61=_[_0xa992('0x4a')]({},_0x4bfa61,_0x1e625e[_0xa992('0x4f')]);return db[_0xa992('0x3d')]['count']({'where':_0x4bfa61['where']})[_0xa992('0x1d')](function(_0x5a99bc){_0x22ecd1['count']=_0x5a99bc;if(_0x1e625e[_0xa992('0x2c')][_0xa992('0x37')]){_0x4bfa61[_0xa992('0x38')]=[{'all':!![]}];}return db[_0xa992('0x3d')][_0xa992('0x2a')](_0x4bfa61);})[_0xa992('0x1d')](function(_0x52f46f){_0x22ecd1[_0xa992('0x50')]=_0x52f46f;return _0x22ecd1;});}})[_0xa992('0x1d')](respondWithFilteredResult(_0x1810fe,_0x4bfa61))[_0xa992('0x2d')](handleError(_0x1810fe,null));};exports[_0xa992('0x51')]=function(_0x39d69f,_0x2227ab){return db['SmsInteraction']['find']({'where':{'id':_0x39d69f[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x2227ab,null))['then'](function(_0x3a7a46){if(_0x3a7a46){return _0x3a7a46[_0xa992('0x52')](_0x39d69f[_0xa992('0x3b')][_0xa992('0x3f')],_[_0xa992('0x40')](_0x39d69f[_0xa992('0x3b')],[_0xa992('0x3f'),'id'])||{})['spread'](function(){return db['Tag'][_0xa992('0x2a')]({'attributes':['id','name','color'],'where':{'id':_0x39d69f[_0xa992('0x3b')][_0xa992('0x3f')]}});})[_0xa992('0x1d')](function(_0x2294f3){socket[_0xa992('0x53')](_0xa992('0x54'),{'id':Number(_0x39d69f['params']['id']),'tags':_0x2294f3||[]});return{'id':Number(_0x39d69f[_0xa992('0x2f')]['id']),'tags':_0x2294f3||[]};});}})['then'](respondWithResult(_0x2227ab,null))[_0xa992('0x2d')](handleError(_0x2227ab,null));};exports[_0xa992('0x55')]=function(_0x5a9ed9,_0x5210bb){return db[_0xa992('0x25')][_0xa992('0x39')]({'where':{'id':_0x5a9ed9[_0xa992('0x2f')]['id']}})[_0xa992('0x1d')](handleEntityNotFound(_0x5210bb,null))[_0xa992('0x1d')](function(_0x362de5){if(_0x362de5){return _0x362de5['removeTags'](_0x5a9ed9[_0xa992('0x2c')][_0xa992('0x3f')]);}})[_0xa992('0x1d')](respondWithStatusCode(_0x5210bb,null))[_0xa992('0x2d')](handleError(_0x5210bb,null));};exports[_0xa992('0x56')]=function(_0xc7456f,_0x23d284){var _0x5c0e1f=moment()['unix']()[_0xa992('0x57')]();var _0x758b3c=path[_0xa992('0x58')](config['root'],'server',_0xa992('0x59'),_0xa992('0x5a'));var _0x43f595=path[_0xa992('0x58')](_0x758b3c,_0x5c0e1f);var _0x2bded0=util['format'](_0xa992('0x5b'),_0xc7456f[_0xa992('0x2f')]['id'],_0x5c0e1f);var _0x3e835c=path['join'](_0x758b3c,_0x2bded0);var _0x3ef622=[];_0x3ef622[_0xa992('0x5c')]({'model':db[_0xa992('0x5d')],'as':_0xa992('0x5d'),'attributes':['id','fullname'],'raw':!![]});_0x3ef622[_0xa992('0x5c')]({'model':db[_0xa992('0x5e')],'as':_0xa992('0x5f'),'attributes':['id','firstName','lastName'],'raw':!![]});var _0xf76f23=[{'model':db[_0xa992('0x3d')],'as':_0xa992('0x60'),'attributes':['id',_0xa992('0x3b'),'createdAt',_0xa992('0x61'),'secret',_0xa992('0x62')],'include':_0x3ef622}];_0xf76f23[_0xa992('0x5c')]({'model':db[_0xa992('0x63')],'as':_0xa992('0x64'),'attributes':['id',_0xa992('0x22')]});_0xf76f23['push']({'model':db[_0xa992('0x5d')],'as':'Owner','attributes':['id',_0xa992('0x65')]});return db['SmsInteraction'][_0xa992('0x39')]({'where':{'id':_0xc7456f['params']['id']},'include':_0xf76f23})[_0xa992('0x1d')](handleEntityNotFound(_0x23d284,null))['then'](function(_0x322448){if(_0x322448){var _0x586383=_0x322448[_0xa992('0x66')]({'plain':!![]});fs[_0xa992('0x67')](_0x43f595);var _0x1dd588={'channel':_0xa992('0x68'),'account':_0x586383[_0xa992('0x64')][_0xa992('0x22')],'agent':_0x586383[_0xa992('0x69')]?_0x586383[_0xa992('0x69')]['fullname']:_0xa992('0x6a'),'createdAt':moment(_0x586383[_0xa992('0x6b')])[_0xa992('0x4e')](_0xa992('0x6c'))[_0xa992('0x57')](),'closedAt':_0x586383[_0xa992('0x6d')]?moment(_0x586383[_0xa992('0x6e')])[_0xa992('0x4e')]('YYYY-MM-DD\x20HH:mm:ss')['toString']():'','disposition':_0x586383[_0xa992('0x6f')],'messages':_(_0x586383[_0xa992('0x60')])['filter']({'secret':![]})[_0xa992('0x24')](function(_0x389440){return{'date':moment(_0x389440[_0xa992('0x6b')])[_0xa992('0x4e')](_0xa992('0x6c'))['toString'](),'sender':_0x389440['direction']===_0xa992('0x70')?_0x389440[_0xa992('0x5d')]?_0x389440[_0xa992('0x5d')][_0xa992('0x65')]:_0xa992('0x71'):_0x389440[_0xa992('0x5f')][_0xa992('0x72')]+(_0x389440['Contact'][_0xa992('0x73')]?'\x20'+_0x389440[_0xa992('0x5f')]['lastName']:''),'body':_0x389440[_0xa992('0x3b')],'direction':_0x389440['direction']===_0xa992('0x70')?'A':'C','secret':_0x389440[_0xa992('0x74')],'read':_0x389440[_0xa992('0x62')]};})['value']()};return ejs[_0xa992('0x75')](path[_0xa992('0x58')](config[_0xa992('0x76')],'server',_0xa992('0x77'),'downloadInteraction.ejs'),{'interaction':_0x1dd588})[_0xa992('0x1d')](function(_0x452f01){var _0x596893=path[_0xa992('0x58')](_0x43f595,_0xa992('0x78')+_0x586383['id']+'-'+_0x5c0e1f+_0xa992('0x79'));var _0x14907f={'path':_0x596893,'channel':_0xa992('0x68'),'interactionId':_0x586383['id']};return pdf['createPdfFromHTML'](_0x452f01,_0x14907f);})['then'](function(){return new BPromise(function(_0x1a7c44,_0x19cb8){zipdir(_0x43f595,{'saveTo':_0x3e835c},function(_0x15b516,_0x59a0fc){if(_0x15b516)return _0x19cb8(_0x15b516);return _0x1a7c44(_0x59a0fc);});})['then'](function(){return new BPromise(function(_0x43a233,_0x166072){rimraf(_0x43f595,function(_0x4a0a05){if(_0x4a0a05)_0x166072(_0x4a0a05);return _0x43a233();});});})[_0xa992('0x1d')](function(){return _0x23d284['download'](_0x3e835c,_0x2bded0,function(_0x50c375){if(_0x50c375){console['log']('err',_0x50c375);}else{fs[_0xa992('0x7a')](_0x3e835c);}});});});}else{return _0x23d284[_0xa992('0x13')](0xc8);}})[_0xa992('0x2d')](handleError(_0x23d284,null));};
\ No newline at end of file