7c6f716c04d9d17e8b0267e8b78ddca25b94e55a
[motion2.git] / server / api / UserMailInteraction / UserMailInteraction.controller.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 _0xbf4f=['fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','options','UserMailInteraction','count','includeAll','include','findAll','rows','catch','show','params','find','create','body','user','get','role','autoAssociation','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','save','update','then','destroy','UserMailInteractions','UserProfileResource','error','name','send','map','rawAttributes'];(function(_0x46f62c,_0x49eb41){var _0x46d994=function(_0x225d69){while(--_0x225d69){_0x46f62c['push'](_0x46f62c['shift']());}};_0x46d994(++_0x49eb41);}(_0xbf4f,0x1c8));var _0xfbf4=function(_0x54691e,_0x28b041){_0x54691e=_0x54691e-0x0;var _0x5520b2=_0xbf4f[_0x54691e];return _0x5520b2;};'use strict';var pdf=require(_0xfbf4('0x0'));var emlformat=require(_0xfbf4('0x1'));var rimraf=require(_0xfbf4('0x2'));var zipdir=require(_0xfbf4('0x3'));var jsonpatch=require(_0xfbf4('0x4'));var rp=require(_0xfbf4('0x5'));var moment=require(_0xfbf4('0x6'));var BPromise=require(_0xfbf4('0x7'));var Mustache=require(_0xfbf4('0x8'));var util=require(_0xfbf4('0x9'));var path=require(_0xfbf4('0xa'));var sox=require(_0xfbf4('0xb'));var csv=require(_0xfbf4('0xc'));var ejs=require(_0xfbf4('0xd'));var fs=require('fs');var _=require(_0xfbf4('0xe'));var squel=require(_0xfbf4('0xf'));var crypto=require(_0xfbf4('0x10'));var jsforce=require(_0xfbf4('0x11'));var deskjs=require('desk.js');var toCsv=require(_0xfbf4('0xc'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xfbf4('0x12'));var authService=require(_0xfbf4('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0xfbf4('0x14'));var hardwareService=require(_0xfbf4('0x15'));var logger=require(_0xfbf4('0x16'))(_0xfbf4('0x17'));var utils=require(_0xfbf4('0x18'));var config=require(_0xfbf4('0x19'));var licenseUtil=require(_0xfbf4('0x1a'));var db=require(_0xfbf4('0x1b'))['db'];function respondWithStatusCode(_0xa9a2ec,_0x39eca8){_0x39eca8=_0x39eca8||0xcc;return function(_0x112050){if(_0x112050){return _0xa9a2ec[_0xfbf4('0x1c')](_0x39eca8);}return _0xa9a2ec[_0xfbf4('0x1d')](_0x39eca8)[_0xfbf4('0x1e')]();};}function respondWithResult(_0x29f1cb,_0x15c5be){_0x15c5be=_0x15c5be||0xc8;return function(_0x1b2810){if(_0x1b2810){return _0x29f1cb[_0xfbf4('0x1d')](_0x15c5be)[_0xfbf4('0x1f')](_0x1b2810);}};}function respondWithFilteredResult(_0x4db88f,_0x48e0fc){return function(_0x4614c9){if(_0x4614c9){var _0x5f47a5=_0x4614c9['count'],_0x140954=_0x48e0fc[_0xfbf4('0x20')],_0x37276a=_0x48e0fc[_0xfbf4('0x20')]+_0x48e0fc[_0xfbf4('0x21')],_0x1e6cdf;if(_0x37276a>=_0x5f47a5){_0x37276a=_0x5f47a5;_0x1e6cdf=0xc8;}else{_0x1e6cdf=0xce;}_0x4db88f['status'](_0x1e6cdf);return _0x4db88f[_0xfbf4('0x22')](_0xfbf4('0x23'),_0x140954+'-'+_0x37276a+'/'+_0x5f47a5)[_0xfbf4('0x1f')](_0x4614c9);}return null;};}function patchUpdates(_0x1c0232){return function(_0x239bd5){try{jsonpatch[_0xfbf4('0x24')](_0x239bd5,_0x1c0232,!![]);}catch(_0x5131bb){return BPromise['reject'](_0x5131bb);}return _0x239bd5[_0xfbf4('0x25')]();};}function saveUpdates(_0x323ed0,_0x101a5c){return function(_0x2a43d8){if(_0x2a43d8){return _0x2a43d8[_0xfbf4('0x26')](_0x323ed0)[_0xfbf4('0x27')](function(_0x35d9a6){return _0x35d9a6;});}return null;};}function removeEntity(_0x1b43f0,_0x549acd){return function(_0x46bfdf){if(_0x46bfdf){return _0x46bfdf[_0xfbf4('0x28')]()['then'](function(){var _0x527716=_0x46bfdf['get']({'plain':!![]});var _0x3c408c=_0xfbf4('0x29');return db[_0xfbf4('0x2a')][_0xfbf4('0x28')]({'where':{'type':_0x3c408c,'resourceId':_0x527716['id']}})['then'](function(){return _0x46bfdf;});})[_0xfbf4('0x27')](function(){_0x1b43f0[_0xfbf4('0x1d')](0xcc)[_0xfbf4('0x1e')]();});}};}function handleEntityNotFound(_0x29bab1,_0x474514){return function(_0x46b1fd){if(!_0x46b1fd){_0x29bab1['sendStatus'](0x194);}return _0x46b1fd;};}function handleError(_0x24ce13,_0xb9cc73){_0xb9cc73=_0xb9cc73||0x1f4;return function(_0xe6a2df){logger[_0xfbf4('0x2b')](_0xe6a2df['stack']);if(_0xe6a2df[_0xfbf4('0x2c')]){delete _0xe6a2df[_0xfbf4('0x2c')];}_0x24ce13[_0xfbf4('0x1d')](_0xb9cc73)[_0xfbf4('0x2d')](_0xe6a2df);};}exports['index']=function(_0x2c192a,_0xa05ae7){var _0x2db60d={},_0x45fd96={},_0x3b2b6a={'count':0x0,'rows':[]};var _0x56e867=_[_0xfbf4('0x2e')](db['UserMailInteraction'][_0xfbf4('0x2f')],function(_0x1b2631){return{'name':_0x1b2631[_0xfbf4('0x30')],'type':_0x1b2631[_0xfbf4('0x31')][_0xfbf4('0x32')]};});_0x45fd96[_0xfbf4('0x33')]=_[_0xfbf4('0x2e')](_0x56e867,_0xfbf4('0x2c'));_0x45fd96[_0xfbf4('0x34')]=_[_0xfbf4('0x35')](_0x2c192a[_0xfbf4('0x34')]);_0x45fd96['filters']=_[_0xfbf4('0x36')](_0x45fd96['model'],_0x45fd96[_0xfbf4('0x34')]);_0x2db60d[_0xfbf4('0x37')]=_[_0xfbf4('0x36')](_0x45fd96[_0xfbf4('0x33')],qs[_0xfbf4('0x38')](_0x2c192a[_0xfbf4('0x34')][_0xfbf4('0x38')]));_0x2db60d[_0xfbf4('0x37')]=_0x2db60d[_0xfbf4('0x37')][_0xfbf4('0x39')]?_0x2db60d[_0xfbf4('0x37')]:_0x45fd96[_0xfbf4('0x33')];if(!_0x2c192a[_0xfbf4('0x34')][_0xfbf4('0x3a')](_0xfbf4('0x3b'))){_0x2db60d[_0xfbf4('0x21')]=qs['limit'](_0x2c192a[_0xfbf4('0x34')]['limit']);_0x2db60d[_0xfbf4('0x20')]=qs[_0xfbf4('0x20')](_0x2c192a[_0xfbf4('0x34')][_0xfbf4('0x20')]);}_0x2db60d[_0xfbf4('0x3c')]=qs['sort'](_0x2c192a[_0xfbf4('0x34')][_0xfbf4('0x3d')]);_0x2db60d[_0xfbf4('0x3e')]=qs[_0xfbf4('0x3f')](_[_0xfbf4('0x40')](_0x2c192a['query'],_0x45fd96[_0xfbf4('0x3f')]),_0x56e867);if(_0x2c192a[_0xfbf4('0x34')][_0xfbf4('0x41')]){_0x2db60d[_0xfbf4('0x3e')]=_[_0xfbf4('0x42')](_0x2db60d[_0xfbf4('0x3e')],{'$or':_[_0xfbf4('0x2e')](_0x56e867,function(_0x52a966){if(_0x52a966[_0xfbf4('0x31')]!=='VIRTUAL'){var _0x477460={};_0x477460[_0x52a966[_0xfbf4('0x2c')]]={'$like':'%'+_0x2c192a['query'][_0xfbf4('0x41')]+'%'};return _0x477460;}})});}_0x2db60d=_['merge']({},_0x2db60d,_0x2c192a[_0xfbf4('0x43')]);var _0x1a20bb={'where':_0x2db60d[_0xfbf4('0x3e')]};return db[_0xfbf4('0x44')][_0xfbf4('0x45')](_0x1a20bb)[_0xfbf4('0x27')](function(_0xf698d2){_0x3b2b6a[_0xfbf4('0x45')]=_0xf698d2;if(_0x2c192a[_0xfbf4('0x34')][_0xfbf4('0x46')]){_0x2db60d[_0xfbf4('0x47')]=[{'all':!![]}];}return db[_0xfbf4('0x44')][_0xfbf4('0x48')](_0x2db60d);})[_0xfbf4('0x27')](function(_0x28f877){_0x3b2b6a[_0xfbf4('0x49')]=_0x28f877;return _0x3b2b6a;})[_0xfbf4('0x27')](respondWithFilteredResult(_0xa05ae7,_0x2db60d))[_0xfbf4('0x4a')](handleError(_0xa05ae7,null));};exports[_0xfbf4('0x4b')]=function(_0x124b8b,_0x3126ba){var _0x102166={'raw':!![],'where':{'id':_0x124b8b[_0xfbf4('0x4c')]['id']}},_0x4624d6={};_0x4624d6[_0xfbf4('0x33')]=_[_0xfbf4('0x35')](db[_0xfbf4('0x44')][_0xfbf4('0x2f')]);_0x4624d6[_0xfbf4('0x34')]=_[_0xfbf4('0x35')](_0x124b8b['query']);_0x4624d6[_0xfbf4('0x3f')]=_[_0xfbf4('0x36')](_0x4624d6[_0xfbf4('0x33')],_0x4624d6[_0xfbf4('0x34')]);_0x102166[_0xfbf4('0x37')]=_[_0xfbf4('0x36')](_0x4624d6[_0xfbf4('0x33')],qs[_0xfbf4('0x38')](_0x124b8b['query']['fields']));_0x102166[_0xfbf4('0x37')]=_0x102166[_0xfbf4('0x37')][_0xfbf4('0x39')]?_0x102166[_0xfbf4('0x37')]:_0x4624d6['model'];if(_0x124b8b['query'][_0xfbf4('0x46')]){_0x102166[_0xfbf4('0x47')]=[{'all':!![]}];}_0x102166=_['merge']({},_0x102166,_0x124b8b[_0xfbf4('0x43')]);return db[_0xfbf4('0x44')][_0xfbf4('0x4d')](_0x102166)[_0xfbf4('0x27')](handleEntityNotFound(_0x3126ba,null))[_0xfbf4('0x27')](respondWithResult(_0x3126ba,null))[_0xfbf4('0x4a')](handleError(_0x3126ba,null));};exports[_0xfbf4('0x4e')]=function(_0x241282,_0x10ece0){return db[_0xfbf4('0x44')][_0xfbf4('0x4e')](_0x241282[_0xfbf4('0x4f')],{})[_0xfbf4('0x27')](function(_0x3cc65f){var _0x2954dd=_0x241282[_0xfbf4('0x50')][_0xfbf4('0x51')]({'plain':!![]});if(!_0x2954dd)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2954dd[_0xfbf4('0x52')]===_0xfbf4('0x50')){var _0x11d875=_0x3cc65f[_0xfbf4('0x51')]({'plain':!![]});var _0x1b0601='UserMailInteractions';return db['UserProfileSection'][_0xfbf4('0x4d')]({'where':{'name':_0x1b0601,'userProfileId':_0x2954dd['userProfileId']},'raw':!![]})[_0xfbf4('0x27')](function(_0x107bbe){if(_0x107bbe&&_0x107bbe[_0xfbf4('0x53')]===0x0){return db[_0xfbf4('0x2a')]['create']({'name':_0x11d875[_0xfbf4('0x2c')],'resourceId':_0x11d875['id'],'type':_0x107bbe['name'],'sectionId':_0x107bbe['id']},{})[_0xfbf4('0x27')](function(){return _0x3cc65f;});}else{return _0x3cc65f;}})[_0xfbf4('0x4a')](function(_0x5e46c2){logger[_0xfbf4('0x2b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x5e46c2);throw _0x5e46c2;});}return _0x3cc65f;})[_0xfbf4('0x27')](respondWithResult(_0x10ece0,0xc9))[_0xfbf4('0x4a')](handleError(_0x10ece0,null));};exports[_0xfbf4('0x26')]=function(_0x21b4f8,_0x46f055){if(_0x21b4f8[_0xfbf4('0x4f')]['id']){delete _0x21b4f8['body']['id'];}return db[_0xfbf4('0x44')][_0xfbf4('0x4d')]({'where':{'id':_0x21b4f8[_0xfbf4('0x4c')]['id']}})[_0xfbf4('0x27')](handleEntityNotFound(_0x46f055,null))[_0xfbf4('0x27')](saveUpdates(_0x21b4f8[_0xfbf4('0x4f')],null))[_0xfbf4('0x27')](respondWithResult(_0x46f055,null))['catch'](handleError(_0x46f055,null));};exports[_0xfbf4('0x28')]=function(_0x32f03c,_0x261643){return db[_0xfbf4('0x44')][_0xfbf4('0x4d')]({'where':{'id':_0x32f03c[_0xfbf4('0x4c')]['id']}})[_0xfbf4('0x27')](handleEntityNotFound(_0x261643,null))['then'](removeEntity(_0x261643,null))['catch'](handleError(_0x261643,null));};