93a878c18bac18ffd465cb788a477ccc993219ed
[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 _0x089f=['body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','set','Content-Range','apply','reject','save','update','then','destroy','end','show','params','model','keys','query','filtears','attributes','intersection','fields','merge','options','MailApplication','find','catch'];(function(_0x36c5b0,_0x5001da){var _0xf19333=function(_0x1e880a){while(--_0x1e880a){_0x36c5b0['push'](_0x36c5b0['shift']());}};_0xf19333(++_0x5001da);}(_0x089f,0x73));var _0xf089=function(_0x3689c6,_0x29eb20){_0x3689c6=_0x3689c6-0x0;var _0x4b13b6=_0x089f[_0x3689c6];return _0x4b13b6;};'use strict';var pdf=require(_0xf089('0x0'));var emlformat=require(_0xf089('0x1'));var rimraf=require(_0xf089('0x2'));var zipdir=require(_0xf089('0x3'));var jsonpatch=require(_0xf089('0x4'));var rp=require(_0xf089('0x5'));var moment=require(_0xf089('0x6'));var BPromise=require(_0xf089('0x7'));var Mustache=require(_0xf089('0x8'));var util=require(_0xf089('0x9'));var path=require(_0xf089('0xa'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf089('0xb'));var fs=require('fs');var _=require(_0xf089('0xc'));var squel=require(_0xf089('0xd'));var crypto=require(_0xf089('0xe'));var jsforce=require(_0xf089('0xf'));var deskjs=require(_0xf089('0x10'));var toCsv=require('to-csv');var querystring=require(_0xf089('0x11'));var Papa=require(_0xf089('0x12'));var Redis=require(_0xf089('0x13'));var authService=require('../../components/auth/service');var qs=require(_0xf089('0x14'));var as=require(_0xf089('0x15'));var hardwareService=require(_0xf089('0x16'));var logger=require(_0xf089('0x17'))(_0xf089('0x18'));var utils=require(_0xf089('0x19'));var config=require(_0xf089('0x1a'));var licenseUtil=require(_0xf089('0x1b'));var db=require(_0xf089('0x1c'))['db'];function respondWithStatusCode(_0x12d6f5,_0x579320){_0x579320=_0x579320||0xcc;return function(_0x210bd1){if(_0x210bd1){return _0x12d6f5[_0xf089('0x1d')](_0x579320);}return _0x12d6f5[_0xf089('0x1e')](_0x579320)['end']();};}function respondWithResult(_0x23635e,_0x42741a){_0x42741a=_0x42741a||0xc8;return function(_0x26fdff){if(_0x26fdff){return _0x23635e[_0xf089('0x1e')](_0x42741a)[_0xf089('0x1f')](_0x26fdff);}};}function respondWithFilteredResult(_0x337e6f,_0x250962){return function(_0x2462e7){if(_0x2462e7){var _0x273b12=_0x2462e7['count'],_0x10e623=_0x250962['offset'],_0x417a06=_0x250962[_0xf089('0x20')]+_0x250962['limit'],_0x349072;if(_0x417a06>=_0x273b12){_0x417a06=_0x273b12;_0x349072=0xc8;}else{_0x349072=0xce;}_0x337e6f[_0xf089('0x1e')](_0x349072);return _0x337e6f[_0xf089('0x21')](_0xf089('0x22'),_0x10e623+'-'+_0x417a06+'/'+_0x273b12)[_0xf089('0x1f')](_0x2462e7);}return null;};}function patchUpdates(_0x4ecad3){return function(_0x59ecc9){try{jsonpatch[_0xf089('0x23')](_0x59ecc9,_0x4ecad3,!![]);}catch(_0x393610){return BPromise[_0xf089('0x24')](_0x393610);}return _0x59ecc9[_0xf089('0x25')]();};}function saveUpdates(_0x2e90b5,_0x2bd054){return function(_0x90866d){if(_0x90866d){return _0x90866d[_0xf089('0x26')](_0x2e90b5)[_0xf089('0x27')](function(_0x56e9ac){return _0x56e9ac;});}return null;};}function removeEntity(_0x57620a,_0x2ed56a){return function(_0x1ec160){if(_0x1ec160){return _0x1ec160[_0xf089('0x28')]()[_0xf089('0x27')](function(){_0x57620a[_0xf089('0x1e')](0xcc)[_0xf089('0x29')]();});}};}function handleEntityNotFound(_0x20a43f,_0x525dba){return function(_0x5b40e0){if(!_0x5b40e0){_0x20a43f['sendStatus'](0x194);}return _0x5b40e0;};}function handleError(_0x2d0dd7,_0x15ebd2){_0x15ebd2=_0x15ebd2||0x1f4;return function(_0x594307){logger['error'](_0x594307['stack']);if(_0x594307['name']){delete _0x594307['name'];}_0x2d0dd7[_0xf089('0x1e')](_0x15ebd2)['send'](_0x594307);};}exports[_0xf089('0x2a')]=function(_0x14d130,_0x4fb64b){var _0x1f1f27={'raw':!![],'where':{'id':_0x14d130[_0xf089('0x2b')]['id']}},_0x5298a2={};_0x5298a2[_0xf089('0x2c')]=_[_0xf089('0x2d')](db['MailApplication']['rawAttributes']);_0x5298a2[_0xf089('0x2e')]=_[_0xf089('0x2d')](_0x14d130[_0xf089('0x2e')]);_0x5298a2[_0xf089('0x2f')]=_['intersection'](_0x5298a2['model'],_0x5298a2[_0xf089('0x2e')]);_0x1f1f27[_0xf089('0x30')]=_[_0xf089('0x31')](_0x5298a2['model'],qs[_0xf089('0x32')](_0x14d130[_0xf089('0x2e')]['fields']));_0x1f1f27[_0xf089('0x30')]=_0x1f1f27['attributes']['length']?_0x1f1f27[_0xf089('0x30')]:_0x5298a2[_0xf089('0x2c')];if(_0x14d130[_0xf089('0x2e')]['includeAll']){_0x1f1f27['include']=[{'all':!![]}];}_0x1f1f27=_[_0xf089('0x33')]({},_0x1f1f27,_0x14d130[_0xf089('0x34')]);return db[_0xf089('0x35')][_0xf089('0x36')](_0x1f1f27)[_0xf089('0x27')](handleEntityNotFound(_0x4fb64b,null))[_0xf089('0x27')](respondWithResult(_0x4fb64b,null))[_0xf089('0x37')](handleError(_0x4fb64b,null));};exports[_0xf089('0x26')]=function(_0x101635,_0x51239b){if(_0x101635[_0xf089('0x38')]['id']){delete _0x101635[_0xf089('0x38')]['id'];}return db['MailApplication']['find']({'where':{'id':_0x101635['params']['id']}})['then'](handleEntityNotFound(_0x51239b,null))[_0xf089('0x27')](saveUpdates(_0x101635['body'],null))[_0xf089('0x27')](respondWithResult(_0x51239b,null))['catch'](handleError(_0x51239b,null));};exports[_0xf089('0x28')]=function(_0x57a54f,_0x20c7e4){return db[_0xf089('0x35')][_0xf089('0x36')]({'where':{'id':_0x57a54f[_0xf089('0x2b')]['id']}})[_0xf089('0x27')](handleEntityNotFound(_0x20c7e4,null))[_0xf089('0x27')](removeEntity(_0x20c7e4,null))['catch'](handleError(_0x20c7e4,null));};