Built motion from commit (unavailable).|2.5.21
[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 _0xe2ea=['show','params','model','keys','MailApplication','rawAttributes','query','filters','intersection','attributes','fields','includeAll','include','options','find','catch','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','limit','set','json','apply','update','destroy','then','error','send'];(function(_0x245c1e,_0x3aa29c){var _0x56785d=function(_0x4c3b9c){while(--_0x4c3b9c){_0x245c1e['push'](_0x245c1e['shift']());}};_0x56785d(++_0x3aa29c);}(_0xe2ea,0xfd));var _0xae2e=function(_0x595b80,_0x494f64){_0x595b80=_0x595b80-0x0;var _0x4e6e31=_0xe2ea[_0x595b80];return _0x4e6e31;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xae2e('0x0'));var rimraf=require(_0xae2e('0x1'));var zipdir=require(_0xae2e('0x2'));var jsonpatch=require(_0xae2e('0x3'));var rp=require(_0xae2e('0x4'));var moment=require(_0xae2e('0x5'));var BPromise=require(_0xae2e('0x6'));var Mustache=require(_0xae2e('0x7'));var util=require(_0xae2e('0x8'));var path=require(_0xae2e('0x9'));var sox=require(_0xae2e('0xa'));var csv=require(_0xae2e('0xb'));var ejs=require(_0xae2e('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0xae2e('0xd'));var crypto=require(_0xae2e('0xe'));var jsforce=require(_0xae2e('0xf'));var deskjs=require(_0xae2e('0x10'));var toCsv=require('to-csv');var querystring=require(_0xae2e('0x11'));var Papa=require(_0xae2e('0x12'));var Redis=require(_0xae2e('0x13'));var authService=require(_0xae2e('0x14'));var qs=require(_0xae2e('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xae2e('0x16'));var logger=require(_0xae2e('0x17'))(_0xae2e('0x18'));var utils=require(_0xae2e('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0xae2e('0x1a'));var db=require(_0xae2e('0x1b'))['db'];function respondWithStatusCode(_0xd428a1,_0x4997b9){_0x4997b9=_0x4997b9||0xcc;return function(_0x30f1f5){if(_0x30f1f5){return _0xd428a1[_0xae2e('0x1c')](_0x4997b9);}return _0xd428a1[_0xae2e('0x1d')](_0x4997b9)[_0xae2e('0x1e')]();};}function respondWithResult(_0x3384f3,_0x569035){_0x569035=_0x569035||0xc8;return function(_0x5639f8){if(_0x5639f8){return _0x3384f3[_0xae2e('0x1d')](_0x569035)['json'](_0x5639f8);}};}function respondWithFilteredResult(_0x56174e,_0x287ca9){return function(_0x5f5d67){if(_0x5f5d67){var _0x59d55b=_0x5f5d67[_0xae2e('0x1f')],_0x26af7f=_0x287ca9['offset'],_0xd9654c=_0x287ca9[_0xae2e('0x20')]+_0x287ca9[_0xae2e('0x21')],_0x18e901;if(_0xd9654c>=_0x59d55b){_0xd9654c=_0x59d55b;_0x18e901=0xc8;}else{_0x18e901=0xce;}_0x56174e['status'](_0x18e901);return _0x56174e[_0xae2e('0x22')]('Content-Range',_0x26af7f+'-'+_0xd9654c+'/'+_0x59d55b)[_0xae2e('0x23')](_0x5f5d67);}return null;};}function patchUpdates(_0xc53632){return function(_0x142b86){try{jsonpatch[_0xae2e('0x24')](_0x142b86,_0xc53632,!![]);}catch(_0x180cc6){return BPromise['reject'](_0x180cc6);}return _0x142b86['save']();};}function saveUpdates(_0x27e8c2,_0x4f9d22){return function(_0x1e3f63){if(_0x1e3f63){return _0x1e3f63[_0xae2e('0x25')](_0x27e8c2)['then'](function(_0x5d50c9){return _0x5d50c9;});}return null;};}function removeEntity(_0x4e4e6a,_0x43cfb2){return function(_0x1e962d){if(_0x1e962d){return _0x1e962d[_0xae2e('0x26')]()[_0xae2e('0x27')](function(){_0x4e4e6a['status'](0xcc)[_0xae2e('0x1e')]();});}};}function handleEntityNotFound(_0x503fec,_0x272333){return function(_0x1c8a47){if(!_0x1c8a47){_0x503fec['sendStatus'](0x194);}return _0x1c8a47;};}function handleError(_0x10ba9f,_0x5f584c){_0x5f584c=_0x5f584c||0x1f4;return function(_0x537017){logger[_0xae2e('0x28')](_0x537017['stack']);if(_0x537017['name']){delete _0x537017['name'];}_0x10ba9f[_0xae2e('0x1d')](_0x5f584c)[_0xae2e('0x29')](_0x537017);};}exports[_0xae2e('0x2a')]=function(_0x25b7fb,_0x526633){var _0x303906={'raw':!![],'where':{'id':_0x25b7fb[_0xae2e('0x2b')]['id']}},_0x3b86c2={};_0x3b86c2[_0xae2e('0x2c')]=_[_0xae2e('0x2d')](db[_0xae2e('0x2e')][_0xae2e('0x2f')]);_0x3b86c2['query']=_[_0xae2e('0x2d')](_0x25b7fb[_0xae2e('0x30')]);_0x3b86c2[_0xae2e('0x31')]=_[_0xae2e('0x32')](_0x3b86c2[_0xae2e('0x2c')],_0x3b86c2[_0xae2e('0x30')]);_0x303906[_0xae2e('0x33')]=_[_0xae2e('0x32')](_0x3b86c2[_0xae2e('0x2c')],qs[_0xae2e('0x34')](_0x25b7fb[_0xae2e('0x30')]['fields']));_0x303906[_0xae2e('0x33')]=_0x303906[_0xae2e('0x33')]['length']?_0x303906[_0xae2e('0x33')]:_0x3b86c2['model'];if(_0x25b7fb[_0xae2e('0x30')][_0xae2e('0x35')]){_0x303906[_0xae2e('0x36')]=[{'all':!![]}];}_0x303906=_['merge']({},_0x303906,_0x25b7fb[_0xae2e('0x37')]);return db['MailApplication'][_0xae2e('0x38')](_0x303906)['then'](handleEntityNotFound(_0x526633,null))[_0xae2e('0x27')](respondWithResult(_0x526633,null))[_0xae2e('0x39')](handleError(_0x526633,null));};exports[_0xae2e('0x25')]=function(_0x5a3da0,_0x50137d){if(_0x5a3da0['body']['id']){delete _0x5a3da0['body']['id'];}return db[_0xae2e('0x2e')][_0xae2e('0x38')]({'where':{'id':_0x5a3da0['params']['id']}})['then'](handleEntityNotFound(_0x50137d,null))[_0xae2e('0x27')](saveUpdates(_0x5a3da0[_0xae2e('0x3a')],null))[_0xae2e('0x27')](respondWithResult(_0x50137d,null))['catch'](handleError(_0x50137d,null));};exports[_0xae2e('0x26')]=function(_0x426aca,_0x2faf9c){return db[_0xae2e('0x2e')][_0xae2e('0x38')]({'where':{'id':_0x426aca[_0xae2e('0x2b')]['id']}})[_0xae2e('0x27')](handleEntityNotFound(_0x2faf9c,null))[_0xae2e('0x27')](removeEntity(_0x2faf9c,null))[_0xae2e('0x39')](handleError(_0x2faf9c,null));};