c590f81a4ecc924ae6468958c3f92a534f911336
[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 _0x9a29=['merge','type','filter','includeAll','include','findAll','rows','show','params','keys','intersection','options','find','catch','create','body','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','undefined','count','offset','limit','set','Content-Range','reject','save','update','then','error','name','MailServerOut','rawAttributes','model','map','query','filters','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where'];(function(_0x639086,_0x6556a2){var _0x49aabc=function(_0x4829ab){while(--_0x4829ab){_0x639086['push'](_0x639086['shift']());}};_0x49aabc(++_0x6556a2);}(_0x9a29,0x1ba));var _0x99a2=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x9a29[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0x99a2('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x99a2('0x1'));var jsonpatch=require(_0x99a2('0x2'));var rp=require(_0x99a2('0x3'));var moment=require(_0x99a2('0x4'));var BPromise=require(_0x99a2('0x5'));var Mustache=require(_0x99a2('0x6'));var util=require(_0x99a2('0x7'));var path=require(_0x99a2('0x8'));var sox=require(_0x99a2('0x9'));var csv=require('to-csv');var ejs=require(_0x99a2('0xa'));var fs=require('fs');var fs_extra=require(_0x99a2('0xb'));var _=require(_0x99a2('0xc'));var squel=require(_0x99a2('0xd'));var crypto=require(_0x99a2('0xe'));var jsforce=require(_0x99a2('0xf'));var deskjs=require(_0x99a2('0x10'));var toCsv=require(_0x99a2('0x11'));var querystring=require('querystring');var Papa=require(_0x99a2('0x12'));var Redis=require(_0x99a2('0x13'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x99a2('0x14'));var hardwareService=require(_0x99a2('0x15'));var logger=require('../../config/logger')(_0x99a2('0x16'));var utils=require(_0x99a2('0x17'));var config=require(_0x99a2('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x99a2('0x19'))['db'];function respondWithStatusCode(_0x46e1a7,_0x48c5b7){_0x48c5b7=_0x48c5b7||0xcc;return function(_0x2dbf41){if(_0x2dbf41){return _0x46e1a7[_0x99a2('0x1a')](_0x48c5b7);}return _0x46e1a7[_0x99a2('0x1b')](_0x48c5b7)['end']();};}function respondWithResult(_0x26a162,_0x243d96){_0x243d96=_0x243d96||0xc8;return function(_0x74c532){if(_0x74c532){return _0x26a162[_0x99a2('0x1b')](_0x243d96)[_0x99a2('0x1c')](_0x74c532);}};}function respondWithFilteredResult(_0x5a26ca,_0x5b79d2){return function(_0x13c5cb){if(_0x13c5cb){var _0xe23742=typeof _0x5b79d2['offset']===_0x99a2('0x1d')&&typeof _0x5b79d2['limit']===_0x99a2('0x1d');var _0x18d391=_0x13c5cb['count'];var _0x57b65d=_0xe23742?0x0:_0x5b79d2['offset'];var _0x1b540a=_0xe23742?_0x13c5cb[_0x99a2('0x1e')]:_0x5b79d2[_0x99a2('0x1f')]+_0x5b79d2[_0x99a2('0x20')];var _0x439e12;if(_0x1b540a>=_0x18d391){_0x1b540a=_0x18d391;_0x439e12=0xc8;}else{_0x439e12=0xce;}_0x5a26ca[_0x99a2('0x1b')](_0x439e12);return _0x5a26ca[_0x99a2('0x21')](_0x99a2('0x22'),_0x57b65d+'-'+_0x1b540a+'/'+_0x18d391)[_0x99a2('0x1c')](_0x13c5cb);}return null;};}function patchUpdates(_0xf23988){return function(_0x576e92){try{jsonpatch['apply'](_0x576e92,_0xf23988,!![]);}catch(_0x28e58d){return BPromise[_0x99a2('0x23')](_0x28e58d);}return _0x576e92[_0x99a2('0x24')]();};}function saveUpdates(_0x1238fd,_0x5e1724){return function(_0x117a66){if(_0x117a66){return _0x117a66[_0x99a2('0x25')](_0x1238fd)['then'](function(_0x52a86e){return _0x52a86e;});}return null;};}function removeEntity(_0x1bdc19,_0xcfb433){return function(_0x123703){if(_0x123703){return _0x123703['destroy']()[_0x99a2('0x26')](function(){_0x1bdc19[_0x99a2('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5f9b49,_0x2f1699){return function(_0x2721c9){if(!_0x2721c9){_0x5f9b49['sendStatus'](0x194);}return _0x2721c9;};}function handleError(_0x5c1848,_0xda5793){_0xda5793=_0xda5793||0x1f4;return function(_0x51473d){logger[_0x99a2('0x27')](_0x51473d['stack']);if(_0x51473d[_0x99a2('0x28')]){delete _0x51473d[_0x99a2('0x28')];}_0x5c1848[_0x99a2('0x1b')](_0xda5793)['send'](_0x51473d);};}exports['index']=function(_0x5f0b84,_0x3f4b62){var _0x1bdff6={},_0x35cb62={},_0x692fc9={'count':0x0,'rows':[]};var _0x1a4e24=_['map'](db[_0x99a2('0x29')][_0x99a2('0x2a')],function(_0xe9497b){return{'name':_0xe9497b['fieldName'],'type':_0xe9497b['type']['key']};});_0x35cb62[_0x99a2('0x2b')]=_[_0x99a2('0x2c')](_0x1a4e24,'name');_0x35cb62[_0x99a2('0x2d')]=_['keys'](_0x5f0b84[_0x99a2('0x2d')]);_0x35cb62[_0x99a2('0x2e')]=_['intersection'](_0x35cb62[_0x99a2('0x2b')],_0x35cb62[_0x99a2('0x2d')]);_0x1bdff6[_0x99a2('0x2f')]=_['intersection'](_0x35cb62[_0x99a2('0x2b')],qs[_0x99a2('0x30')](_0x5f0b84['query']['fields']));_0x1bdff6[_0x99a2('0x2f')]=_0x1bdff6[_0x99a2('0x2f')][_0x99a2('0x31')]?_0x1bdff6[_0x99a2('0x2f')]:_0x35cb62['model'];if(!_0x5f0b84[_0x99a2('0x2d')][_0x99a2('0x32')](_0x99a2('0x33'))){_0x1bdff6[_0x99a2('0x20')]=qs[_0x99a2('0x20')](_0x5f0b84[_0x99a2('0x2d')]['limit']);_0x1bdff6['offset']=qs[_0x99a2('0x1f')](_0x5f0b84[_0x99a2('0x2d')][_0x99a2('0x1f')]);}_0x1bdff6[_0x99a2('0x34')]=qs[_0x99a2('0x35')](_0x5f0b84[_0x99a2('0x2d')][_0x99a2('0x35')]);_0x1bdff6[_0x99a2('0x36')]=qs['filters'](_['pick'](_0x5f0b84['query'],_0x35cb62[_0x99a2('0x2e')]),_0x1a4e24);if(_0x5f0b84['query']['filter']){_0x1bdff6[_0x99a2('0x36')]=_[_0x99a2('0x37')](_0x1bdff6[_0x99a2('0x36')],{'$or':_[_0x99a2('0x2c')](_0x1a4e24,function(_0x5c0a40){if(_0x5c0a40[_0x99a2('0x38')]!=='VIRTUAL'){var _0x1905de={};_0x1905de[_0x5c0a40[_0x99a2('0x28')]]={'$like':'%'+_0x5f0b84['query'][_0x99a2('0x39')]+'%'};return _0x1905de;}})});}_0x1bdff6=_[_0x99a2('0x37')]({},_0x1bdff6,_0x5f0b84['options']);var _0x4ee6fc={'where':_0x1bdff6[_0x99a2('0x36')]};return db[_0x99a2('0x29')][_0x99a2('0x1e')](_0x4ee6fc)[_0x99a2('0x26')](function(_0x2781b5){_0x692fc9[_0x99a2('0x1e')]=_0x2781b5;if(_0x5f0b84[_0x99a2('0x2d')][_0x99a2('0x3a')]){_0x1bdff6[_0x99a2('0x3b')]=[{'all':!![]}];}return db['MailServerOut'][_0x99a2('0x3c')](_0x1bdff6);})['then'](function(_0x1113c4){_0x692fc9[_0x99a2('0x3d')]=_0x1113c4;return _0x692fc9;})[_0x99a2('0x26')](respondWithFilteredResult(_0x3f4b62,_0x1bdff6))['catch'](handleError(_0x3f4b62,null));};exports[_0x99a2('0x3e')]=function(_0x58512a,_0x90d6de){var _0x505bd9={'raw':!![],'where':{'id':_0x58512a[_0x99a2('0x3f')]['id']}},_0x396a5f={};_0x396a5f[_0x99a2('0x2b')]=_[_0x99a2('0x40')](db['MailServerOut']['rawAttributes']);_0x396a5f[_0x99a2('0x2d')]=_[_0x99a2('0x40')](_0x58512a[_0x99a2('0x2d')]);_0x396a5f[_0x99a2('0x2e')]=_['intersection'](_0x396a5f[_0x99a2('0x2b')],_0x396a5f[_0x99a2('0x2d')]);_0x505bd9[_0x99a2('0x2f')]=_[_0x99a2('0x41')](_0x396a5f[_0x99a2('0x2b')],qs[_0x99a2('0x30')](_0x58512a[_0x99a2('0x2d')][_0x99a2('0x30')]));_0x505bd9[_0x99a2('0x2f')]=_0x505bd9[_0x99a2('0x2f')][_0x99a2('0x31')]?_0x505bd9[_0x99a2('0x2f')]:_0x396a5f[_0x99a2('0x2b')];if(_0x58512a[_0x99a2('0x2d')]['includeAll']){_0x505bd9[_0x99a2('0x3b')]=[{'all':!![]}];}_0x505bd9=_[_0x99a2('0x37')]({},_0x505bd9,_0x58512a[_0x99a2('0x42')]);return db[_0x99a2('0x29')][_0x99a2('0x43')](_0x505bd9)['then'](handleEntityNotFound(_0x90d6de,null))[_0x99a2('0x26')](respondWithResult(_0x90d6de,null))[_0x99a2('0x44')](handleError(_0x90d6de,null));};exports[_0x99a2('0x45')]=function(_0x1a975b,_0x220b2f){return db[_0x99a2('0x29')][_0x99a2('0x45')](_0x1a975b[_0x99a2('0x46')],{})[_0x99a2('0x26')](respondWithResult(_0x220b2f,0xc9))['catch'](handleError(_0x220b2f,null));};exports['update']=function(_0x157590,_0x37849b){if(_0x157590[_0x99a2('0x46')]['id']){delete _0x157590[_0x99a2('0x46')]['id'];}return db[_0x99a2('0x29')][_0x99a2('0x43')]({'where':{'id':_0x157590['params']['id']}})[_0x99a2('0x26')](handleEntityNotFound(_0x37849b,null))[_0x99a2('0x26')](saveUpdates(_0x157590['body'],null))[_0x99a2('0x26')](respondWithResult(_0x37849b,null))[_0x99a2('0x44')](handleError(_0x37849b,null));};exports['destroy']=function(_0x12854,_0x3faeac){return db['MailServerOut'][_0x99a2('0x43')]({'where':{'id':_0x12854[_0x99a2('0x3f')]['id']}})['then'](handleEntityNotFound(_0x3faeac,null))[_0x99a2('0x26')](removeEntity(_0x3faeac,null))[_0x99a2('0x44')](handleError(_0x3faeac,null));};