Built motion from commit (unavailable).|2.5.15
[motion2.git] / server / api / mailApplication / mailApplication.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 _0xf590=['../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','update','then','destroy','name','send','show','params','model','keys','rawAttributes','filters','attributes','intersection','fields','query','include','options','MailApplication','find','body','catch','html-pdf','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment'];(function(_0x4c2364,_0x13aeb){var _0x213753=function(_0x370738){while(--_0x370738){_0x4c2364['push'](_0x4c2364['shift']());}};_0x213753(++_0x13aeb);}(_0xf590,0x171));var _0x0f59=function(_0x5992b4,_0x414e4d){_0x5992b4=_0x5992b4-0x0;var _0x3df19c=_0xf590[_0x5992b4];return _0x3df19c;};'use strict';var pdf=require(_0x0f59('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x0f59('0x1'));var rp=require(_0x0f59('0x2'));var moment=require('moment');var BPromise=require(_0x0f59('0x3'));var Mustache=require(_0x0f59('0x4'));var util=require('util');var path=require(_0x0f59('0x5'));var sox=require(_0x0f59('0x6'));var csv=require(_0x0f59('0x7'));var ejs=require(_0x0f59('0x8'));var fs=require('fs');var _=require(_0x0f59('0x9'));var squel=require(_0x0f59('0xa'));var crypto=require(_0x0f59('0xb'));var jsforce=require(_0x0f59('0xc'));var deskjs=require(_0x0f59('0xd'));var toCsv=require(_0x0f59('0x7'));var querystring=require('querystring');var Papa=require(_0x0f59('0xe'));var Redis=require(_0x0f59('0xf'));var authService=require(_0x0f59('0x10'));var qs=require(_0x0f59('0x11'));var as=require(_0x0f59('0x12'));var hardwareService=require(_0x0f59('0x13'));var logger=require(_0x0f59('0x14'))(_0x0f59('0x15'));var utils=require('../../config/utils');var config=require(_0x0f59('0x16'));var licenseUtil=require(_0x0f59('0x17'));var db=require(_0x0f59('0x18'))['db'];function respondWithStatusCode(_0x858707,_0x536c26){_0x536c26=_0x536c26||0xcc;return function(_0x586cfb){if(_0x586cfb){return _0x858707[_0x0f59('0x19')](_0x536c26);}return _0x858707[_0x0f59('0x1a')](_0x536c26)[_0x0f59('0x1b')]();};}function respondWithResult(_0x2e021e,_0x35e8af){_0x35e8af=_0x35e8af||0xc8;return function(_0x66c220){if(_0x66c220){return _0x2e021e[_0x0f59('0x1a')](_0x35e8af)['json'](_0x66c220);}};}function respondWithFilteredResult(_0x2096e8,_0x419e7e){return function(_0x24ed79){if(_0x24ed79){var _0x1b7adb=_0x24ed79[_0x0f59('0x1c')],_0xde9cd9=_0x419e7e[_0x0f59('0x1d')],_0x153271=_0x419e7e[_0x0f59('0x1d')]+_0x419e7e[_0x0f59('0x1e')],_0x2cfd90;if(_0x153271>=_0x1b7adb){_0x153271=_0x1b7adb;_0x2cfd90=0xc8;}else{_0x2cfd90=0xce;}_0x2096e8[_0x0f59('0x1a')](_0x2cfd90);return _0x2096e8[_0x0f59('0x1f')](_0x0f59('0x20'),_0xde9cd9+'-'+_0x153271+'/'+_0x1b7adb)[_0x0f59('0x21')](_0x24ed79);}return null;};}function patchUpdates(_0x1c1291){return function(_0x352220){try{jsonpatch[_0x0f59('0x22')](_0x352220,_0x1c1291,!![]);}catch(_0x2d33b9){return BPromise['reject'](_0x2d33b9);}return _0x352220['save']();};}function saveUpdates(_0x558627,_0x3db04f){return function(_0x20cc7b){if(_0x20cc7b){return _0x20cc7b[_0x0f59('0x23')](_0x558627)[_0x0f59('0x24')](function(_0x80d320){return _0x80d320;});}return null;};}function removeEntity(_0x669bde,_0x1dcca5){return function(_0x3bc9c4){if(_0x3bc9c4){return _0x3bc9c4[_0x0f59('0x25')]()[_0x0f59('0x24')](function(){_0x669bde[_0x0f59('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x44a3ec,_0x25780e){return function(_0x573d73){if(!_0x573d73){_0x44a3ec[_0x0f59('0x19')](0x194);}return _0x573d73;};}function handleError(_0x46cf5d,_0x17b270){_0x17b270=_0x17b270||0x1f4;return function(_0x53b9cb){logger['error'](_0x53b9cb['stack']);if(_0x53b9cb[_0x0f59('0x26')]){delete _0x53b9cb['name'];}_0x46cf5d[_0x0f59('0x1a')](_0x17b270)[_0x0f59('0x27')](_0x53b9cb);};}exports[_0x0f59('0x28')]=function(_0x23e35f,_0x26c6e8){var _0x3ff64d={'raw':!![],'where':{'id':_0x23e35f[_0x0f59('0x29')]['id']}},_0x54b3ed={};_0x54b3ed[_0x0f59('0x2a')]=_[_0x0f59('0x2b')](db['MailApplication'][_0x0f59('0x2c')]);_0x54b3ed['query']=_[_0x0f59('0x2b')](_0x23e35f['query']);_0x54b3ed[_0x0f59('0x2d')]=_['intersection'](_0x54b3ed[_0x0f59('0x2a')],_0x54b3ed['query']);_0x3ff64d[_0x0f59('0x2e')]=_[_0x0f59('0x2f')](_0x54b3ed[_0x0f59('0x2a')],qs[_0x0f59('0x30')](_0x23e35f['query'][_0x0f59('0x30')]));_0x3ff64d[_0x0f59('0x2e')]=_0x3ff64d[_0x0f59('0x2e')]['length']?_0x3ff64d[_0x0f59('0x2e')]:_0x54b3ed[_0x0f59('0x2a')];if(_0x23e35f[_0x0f59('0x31')]['includeAll']){_0x3ff64d[_0x0f59('0x32')]=[{'all':!![]}];}_0x3ff64d=_['merge']({},_0x3ff64d,_0x23e35f[_0x0f59('0x33')]);return db[_0x0f59('0x34')][_0x0f59('0x35')](_0x3ff64d)[_0x0f59('0x24')](handleEntityNotFound(_0x26c6e8,null))[_0x0f59('0x24')](respondWithResult(_0x26c6e8,null))['catch'](handleError(_0x26c6e8,null));};exports[_0x0f59('0x23')]=function(_0x3817b7,_0x43ad02){if(_0x3817b7[_0x0f59('0x36')]['id']){delete _0x3817b7['body']['id'];}return db[_0x0f59('0x34')][_0x0f59('0x35')]({'where':{'id':_0x3817b7[_0x0f59('0x29')]['id']}})['then'](handleEntityNotFound(_0x43ad02,null))[_0x0f59('0x24')](saveUpdates(_0x3817b7[_0x0f59('0x36')],null))[_0x0f59('0x24')](respondWithResult(_0x43ad02,null))[_0x0f59('0x37')](handleError(_0x43ad02,null));};exports[_0x0f59('0x25')]=function(_0x414b76,_0xf56497){return db[_0x0f59('0x34')][_0x0f59('0x35')]({'where':{'id':_0x414b76[_0x0f59('0x29')]['id']}})['then'](handleEntityNotFound(_0xf56497,null))[_0x0f59('0x24')](removeEntity(_0xf56497,null))['catch'](handleError(_0xf56497,null));};