Built motion from commit (unavailable).|2.0.76
[motion2.git] / server / api / mailServerOut / mailServerOut.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 _0xc17f=['set','Content-Range','reject','save','update','then','destroy','error','stack','name','send','rawAttributes','model','query','dateEnd','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','add','day','dateStart','merge','filter','map','options','includeAll','MailServerOut','findAll','show','params','include','catch','create','body','find','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/parsers/qs','../../config/logger','api','../../mysqldb','sendStatus','status','end','json','count','offset','limit'];(function(_0x19bb0b,_0x257218){var _0x27f38c=function(_0x1eb9ef){while(--_0x1eb9ef){_0x19bb0b['push'](_0x19bb0b['shift']());}};_0x27f38c(++_0x257218);}(_0xc17f,0xb8));var _0xfc17=function(_0x280fdd,_0x258d03){_0x280fdd=_0x280fdd-0x0;var _0x1af49a=_0xc17f[_0x280fdd];return _0x1af49a;};'use strict';var pdf=require(_0xfc17('0x0'));var emlformat=require(_0xfc17('0x1'));var rimraf=require(_0xfc17('0x2'));var zipdir=require(_0xfc17('0x3'));var jsonpatch=require(_0xfc17('0x4'));var rp=require(_0xfc17('0x5'));var moment=require('moment');var BPromise=require(_0xfc17('0x6'));var Mustache=require(_0xfc17('0x7'));var util=require(_0xfc17('0x8'));var path=require(_0xfc17('0x9'));var sox=require('sox');var csv=require(_0xfc17('0xa'));var ejs=require(_0xfc17('0xb'));var fs=require('fs');var _=require(_0xfc17('0xc'));var squel=require(_0xfc17('0xd'));var crypto=require(_0xfc17('0xe'));var jsforce=require(_0xfc17('0xf'));var deskjs=require(_0xfc17('0x10'));var toCsv=require(_0xfc17('0xa'));var querystring=require('querystring');var Papa=require(_0xfc17('0x11'));var qs=require(_0xfc17('0x12'));var logger=require(_0xfc17('0x13'))(_0xfc17('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0xfc17('0x15'))['db'];function respondWithStatusCode(_0x22cbef,_0x2924e9){_0x2924e9=_0x2924e9||0xcc;return function(_0x431f67){if(_0x431f67){return _0x22cbef[_0xfc17('0x16')](_0x2924e9);}return _0x22cbef[_0xfc17('0x17')](_0x2924e9)[_0xfc17('0x18')]();};}function respondWithResult(_0x133c4c,_0x115411){_0x115411=_0x115411||0xc8;return function(_0x1f0c64){if(_0x1f0c64){return _0x133c4c['status'](_0x115411)[_0xfc17('0x19')](_0x1f0c64);}};}function respondWithFilteredResult(_0x137d6d,_0x29c8e9){return function(_0x47e84a){if(_0x47e84a){var _0x16e49b=_0x47e84a[_0xfc17('0x1a')],_0x349779=_0x29c8e9[_0xfc17('0x1b')],_0x3a81f7=_0x29c8e9[_0xfc17('0x1b')]+_0x29c8e9[_0xfc17('0x1c')],_0x25d5fe;if(_0x3a81f7>=_0x16e49b){_0x3a81f7=_0x16e49b;_0x25d5fe=0xc8;}else{_0x25d5fe=0xce;}_0x137d6d[_0xfc17('0x17')](_0x25d5fe);return _0x137d6d[_0xfc17('0x1d')](_0xfc17('0x1e'),_0x349779+'-'+_0x3a81f7+'/'+_0x16e49b)[_0xfc17('0x19')](_0x47e84a);}return null;};}function patchUpdates(_0x2bbb0e){return function(_0x5b2c7c){try{jsonpatch['apply'](_0x5b2c7c,_0x2bbb0e,!![]);}catch(_0x2aa3a2){return BPromise[_0xfc17('0x1f')](_0x2aa3a2);}return _0x5b2c7c[_0xfc17('0x20')]();};}function saveUpdates(_0x109c84,_0x5b23e8){return function(_0x12ec9b){if(_0x12ec9b){return _0x12ec9b[_0xfc17('0x21')](_0x109c84)[_0xfc17('0x22')](function(_0x48edb4){return _0x48edb4;});}return null;};}function removeEntity(_0x2614de,_0x1010af){return function(_0xd4031d){if(_0xd4031d){return _0xd4031d[_0xfc17('0x23')]()[_0xfc17('0x22')](function(){_0x2614de[_0xfc17('0x17')](0xcc)[_0xfc17('0x18')]();});}};}function handleEntityNotFound(_0x4593d0,_0x3f91a5){return function(_0x410d77){if(!_0x410d77){_0x4593d0['sendStatus'](0x194);}return _0x410d77;};}function handleError(_0x37c847,_0x2285df){_0x2285df=_0x2285df||0x1f4;return function(_0x10a81f){logger[_0xfc17('0x24')](_0x10a81f[_0xfc17('0x25')]);if(_0x10a81f[_0xfc17('0x26')]){delete _0x10a81f['name'];}_0x37c847[_0xfc17('0x17')](_0x2285df)[_0xfc17('0x27')](_0x10a81f);};}exports['index']=function(_0x358f48,_0x2f1ebc){var _0x4b1038={},_0x4e4cf5={},_0xd0144c={'count':0x0,'rows':[]};var _0x24338b=db['MailServerOut'][_0xfc17('0x28')];_0x4e4cf5[_0xfc17('0x29')]=_['keys'](_0x24338b);var _0x38fdea={'dateStart':_0x358f48[_0xfc17('0x2a')]['dateStart'],'dateEnd':_0x358f48[_0xfc17('0x2a')][_0xfc17('0x2b')]};delete _0x358f48['query']['dateStart'];delete _0x358f48[_0xfc17('0x2a')][_0xfc17('0x2b')];_0x4e4cf5[_0xfc17('0x2a')]=_[_0xfc17('0x2c')](_0x358f48[_0xfc17('0x2a')]);_0x4e4cf5[_0xfc17('0x2d')]=_[_0xfc17('0x2e')](_0x4e4cf5[_0xfc17('0x29')],_0x4e4cf5[_0xfc17('0x2a')]);_0x4b1038['attributes']=_[_0xfc17('0x2e')](_0x4e4cf5[_0xfc17('0x29')],qs[_0xfc17('0x2f')](_0x358f48['query'][_0xfc17('0x2f')]));_0x4b1038['attributes']=_0x4b1038[_0xfc17('0x30')][_0xfc17('0x31')]?_0x4b1038[_0xfc17('0x30')]:_0x4e4cf5[_0xfc17('0x29')];if(!_0x358f48['query'][_0xfc17('0x32')](_0xfc17('0x33'))){_0x4b1038['limit']=qs['limit'](_0x358f48['query'][_0xfc17('0x1c')]);_0x4b1038[_0xfc17('0x1b')]=qs[_0xfc17('0x1b')](_0x358f48[_0xfc17('0x2a')][_0xfc17('0x1b')]);}_0x4b1038['order']=qs[_0xfc17('0x34')](_0x358f48[_0xfc17('0x2a')]['sort']);_0x4b1038[_0xfc17('0x35')]=qs[_0xfc17('0x2d')](_['pick'](_0x358f48['query'],_0x4e4cf5[_0xfc17('0x2d')]));if(_0x38fdea['dateStart']){if(_0x38fdea[_0xfc17('0x2b')]){_0x38fdea['dateEnd']=moment(_0x38fdea['dateEnd'])[_0xfc17('0x36')](0x1,_0xfc17('0x37'));}else{_0x38fdea[_0xfc17('0x2b')]=moment(_0x38fdea[_0xfc17('0x38')])[_0xfc17('0x36')](0x1,_0xfc17('0x37'));}_[_0xfc17('0x39')](_0x4b1038['where'],{'createdAt':{'$gte':_0x38fdea[_0xfc17('0x38')],'$lte':_0x38fdea[_0xfc17('0x2b')]}});}if(_0x358f48[_0xfc17('0x2a')][_0xfc17('0x3a')]){_0x4b1038['where']=_['merge'](_0x4b1038[_0xfc17('0x35')],{'$or':_[_0xfc17('0x3b')](_0x4b1038[_0xfc17('0x30')],function(_0x1c2da4){var _0x4fc531={};_0x4fc531[_0x1c2da4]={'$like':'%'+_0x358f48['query'][_0xfc17('0x3a')]+'%'};return _0x4fc531;})});}_0x4b1038=_['merge']({},_0x4b1038,_0x358f48[_0xfc17('0x3c')]);var _0x5aee83={'where':_0x4b1038[_0xfc17('0x35')]};return db['MailServerOut'][_0xfc17('0x1a')](_0x5aee83)[_0xfc17('0x22')](function(_0x29a557){_0xd0144c[_0xfc17('0x1a')]=_0x29a557;if(_0x358f48[_0xfc17('0x2a')][_0xfc17('0x3d')]){_0x4b1038['include']=[{'all':!![]}];}return db[_0xfc17('0x3e')][_0xfc17('0x3f')](_0x4b1038);})[_0xfc17('0x22')](function(_0x131f8d){_0xd0144c['rows']=_0x131f8d;return _0xd0144c;})[_0xfc17('0x22')](respondWithFilteredResult(_0x2f1ebc,_0x4b1038))['catch'](handleError(_0x2f1ebc,null));};exports[_0xfc17('0x40')]=function(_0x5c0671,_0x384c78){var _0x3760e9={'raw':!![],'where':{'id':_0x5c0671[_0xfc17('0x41')]['id']}},_0x47d217={};_0x47d217[_0xfc17('0x29')]=_[_0xfc17('0x2c')](db['MailServerOut'][_0xfc17('0x28')]);_0x47d217['query']=_[_0xfc17('0x2c')](_0x5c0671[_0xfc17('0x2a')]);_0x47d217[_0xfc17('0x2d')]=_[_0xfc17('0x2e')](_0x47d217['model'],_0x47d217[_0xfc17('0x2a')]);_0x3760e9[_0xfc17('0x30')]=_['intersection'](_0x47d217[_0xfc17('0x29')],qs['fields'](_0x5c0671[_0xfc17('0x2a')][_0xfc17('0x2f')]));_0x3760e9['attributes']=_0x3760e9[_0xfc17('0x30')]['length']?_0x3760e9[_0xfc17('0x30')]:_0x47d217[_0xfc17('0x29')];if(_0x5c0671[_0xfc17('0x2a')][_0xfc17('0x3d')]){_0x3760e9[_0xfc17('0x42')]=[{'all':!![]}];}_0x3760e9=_[_0xfc17('0x39')]({},_0x3760e9,_0x5c0671['options']);return db[_0xfc17('0x3e')]['find'](_0x3760e9)[_0xfc17('0x22')](handleEntityNotFound(_0x384c78,null))[_0xfc17('0x22')](respondWithResult(_0x384c78,null))[_0xfc17('0x43')](handleError(_0x384c78,null));};exports[_0xfc17('0x44')]=function(_0xba87b6,_0x381064){return db[_0xfc17('0x3e')][_0xfc17('0x44')](_0xba87b6[_0xfc17('0x45')],{})['then'](respondWithResult(_0x381064,0xc9))[_0xfc17('0x43')](handleError(_0x381064,null));};exports['update']=function(_0x53011f,_0x38b2ed){if(_0x53011f[_0xfc17('0x45')]['id']){delete _0x53011f[_0xfc17('0x45')]['id'];}return db[_0xfc17('0x3e')]['find']({'where':{'id':_0x53011f['params']['id']}})['then'](handleEntityNotFound(_0x38b2ed,null))['then'](saveUpdates(_0x53011f[_0xfc17('0x45')],null))[_0xfc17('0x22')](respondWithResult(_0x38b2ed,null))[_0xfc17('0x43')](handleError(_0x38b2ed,null));};exports['destroy']=function(_0x31261a,_0x33333e){return db[_0xfc17('0x3e')][_0xfc17('0x46')]({'where':{'id':_0x31261a[_0xfc17('0x41')]['id']}})['then'](handleEntityNotFound(_0x33333e,null))['then'](removeEntity(_0x33333e,null))['catch'](handleError(_0x33333e,null));};