Built motion from commit (unavailable).|2.5.11
[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 _0x26f9=['map','MailServerOut','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','length','nolimit','offset','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','params','fields','create','body','find','zip-dir','fast-json-patch','mustache','util','path','sox','to-csv','ejs','squel','crypto','jsforce','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','sendStatus','status','end','count','limit','set','apply','reject','update','then','stack','name','send','index'];(function(_0x60ef35,_0x4a66e5){var _0x4cc5c9=function(_0x45d553){while(--_0x45d553){_0x60ef35['push'](_0x60ef35['shift']());}};_0x4cc5c9(++_0x4a66e5);}(_0x26f9,0x166));var _0x926f=function(_0x3c2666,_0x15fd23){_0x3c2666=_0x3c2666-0x0;var _0x10c814=_0x26f9[_0x3c2666];return _0x10c814;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x926f('0x0'));var jsonpatch=require(_0x926f('0x1'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x926f('0x2'));var util=require(_0x926f('0x3'));var path=require(_0x926f('0x4'));var sox=require(_0x926f('0x5'));var csv=require(_0x926f('0x6'));var ejs=require(_0x926f('0x7'));var fs=require('fs');var _=require('lodash');var squel=require(_0x926f('0x8'));var crypto=require(_0x926f('0x9'));var jsforce=require(_0x926f('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x926f('0xb'));var Redis=require('ioredis');var authService=require(_0x926f('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0x926f('0xd'));var hardwareService=require(_0x926f('0xe'));var logger=require(_0x926f('0xf'))(_0x926f('0x10'));var utils=require(_0x926f('0x11'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1d5f91,_0x1586fa){_0x1586fa=_0x1586fa||0xcc;return function(_0x2cec3f){if(_0x2cec3f){return _0x1d5f91[_0x926f('0x12')](_0x1586fa);}return _0x1d5f91[_0x926f('0x13')](_0x1586fa)[_0x926f('0x14')]();};}function respondWithResult(_0x31b803,_0x3cc1f8){_0x3cc1f8=_0x3cc1f8||0xc8;return function(_0x5c5a9d){if(_0x5c5a9d){return _0x31b803[_0x926f('0x13')](_0x3cc1f8)['json'](_0x5c5a9d);}};}function respondWithFilteredResult(_0x118a29,_0x4c5b06){return function(_0x2d4d35){if(_0x2d4d35){var _0x401d2b=_0x2d4d35[_0x926f('0x15')],_0x82b274=_0x4c5b06['offset'],_0x1343c4=_0x4c5b06['offset']+_0x4c5b06[_0x926f('0x16')],_0x26de02;if(_0x1343c4>=_0x401d2b){_0x1343c4=_0x401d2b;_0x26de02=0xc8;}else{_0x26de02=0xce;}_0x118a29['status'](_0x26de02);return _0x118a29[_0x926f('0x17')]('Content-Range',_0x82b274+'-'+_0x1343c4+'/'+_0x401d2b)['json'](_0x2d4d35);}return null;};}function patchUpdates(_0xe4461a){return function(_0x290072){try{jsonpatch[_0x926f('0x18')](_0x290072,_0xe4461a,!![]);}catch(_0x3aec4e){return BPromise[_0x926f('0x19')](_0x3aec4e);}return _0x290072['save']();};}function saveUpdates(_0x22c370,_0x116999){return function(_0x2f224b){if(_0x2f224b){return _0x2f224b[_0x926f('0x1a')](_0x22c370)[_0x926f('0x1b')](function(_0x23b0a8){return _0x23b0a8;});}return null;};}function removeEntity(_0x9e7b97,_0x5d3659){return function(_0x2f73c5){if(_0x2f73c5){return _0x2f73c5['destroy']()[_0x926f('0x1b')](function(){_0x9e7b97['status'](0xcc)[_0x926f('0x14')]();});}};}function handleEntityNotFound(_0x153e3a,_0x2f4fb5){return function(_0x1a1b71){if(!_0x1a1b71){_0x153e3a[_0x926f('0x12')](0x194);}return _0x1a1b71;};}function handleError(_0x5b81c4,_0x43cebc){_0x43cebc=_0x43cebc||0x1f4;return function(_0x4c8eb3){logger['error'](_0x4c8eb3[_0x926f('0x1c')]);if(_0x4c8eb3[_0x926f('0x1d')]){delete _0x4c8eb3[_0x926f('0x1d')];}_0x5b81c4['status'](_0x43cebc)[_0x926f('0x1e')](_0x4c8eb3);};}exports[_0x926f('0x1f')]=function(_0x16f9a6,_0x9e1781){var _0x2edc60={},_0x594eae={},_0x3edd1d={'count':0x0,'rows':[]};var _0x520d98=_[_0x926f('0x20')](db[_0x926f('0x21')][_0x926f('0x22')],function(_0x3fd9f0){return{'name':_0x3fd9f0[_0x926f('0x23')],'type':_0x3fd9f0[_0x926f('0x24')][_0x926f('0x25')]};});_0x594eae[_0x926f('0x26')]=_[_0x926f('0x20')](_0x520d98,_0x926f('0x1d'));_0x594eae[_0x926f('0x27')]=_[_0x926f('0x28')](_0x16f9a6[_0x926f('0x27')]);_0x594eae[_0x926f('0x29')]=_['intersection'](_0x594eae[_0x926f('0x26')],_0x594eae[_0x926f('0x27')]);_0x2edc60['attributes']=_[_0x926f('0x2a')](_0x594eae[_0x926f('0x26')],qs['fields'](_0x16f9a6[_0x926f('0x27')]['fields']));_0x2edc60[_0x926f('0x2b')]=_0x2edc60['attributes'][_0x926f('0x2c')]?_0x2edc60[_0x926f('0x2b')]:_0x594eae['model'];if(!_0x16f9a6[_0x926f('0x27')]['hasOwnProperty'](_0x926f('0x2d'))){_0x2edc60['limit']=qs[_0x926f('0x16')](_0x16f9a6['query'][_0x926f('0x16')]);_0x2edc60[_0x926f('0x2e')]=qs[_0x926f('0x2e')](_0x16f9a6[_0x926f('0x27')]['offset']);}_0x2edc60[_0x926f('0x2f')]=qs[_0x926f('0x30')](_0x16f9a6[_0x926f('0x27')][_0x926f('0x30')]);_0x2edc60[_0x926f('0x31')]=qs[_0x926f('0x29')](_[_0x926f('0x32')](_0x16f9a6[_0x926f('0x27')],_0x594eae[_0x926f('0x29')]),_0x520d98);if(_0x16f9a6[_0x926f('0x27')][_0x926f('0x33')]){_0x2edc60[_0x926f('0x31')]=_['merge'](_0x2edc60[_0x926f('0x31')],{'$or':_[_0x926f('0x20')](_0x520d98,function(_0x2210c2){if(_0x2210c2['type']!==_0x926f('0x34')){var _0x2fcdba={};_0x2fcdba[_0x2210c2[_0x926f('0x1d')]]={'$like':'%'+_0x16f9a6[_0x926f('0x27')][_0x926f('0x33')]+'%'};return _0x2fcdba;}})});}_0x2edc60=_[_0x926f('0x35')]({},_0x2edc60,_0x16f9a6[_0x926f('0x36')]);var _0x18f5ca={'where':_0x2edc60[_0x926f('0x31')]};return db['MailServerOut'][_0x926f('0x15')](_0x18f5ca)['then'](function(_0x2b5839){_0x3edd1d[_0x926f('0x15')]=_0x2b5839;if(_0x16f9a6[_0x926f('0x27')][_0x926f('0x37')]){_0x2edc60[_0x926f('0x38')]=[{'all':!![]}];}return db[_0x926f('0x21')][_0x926f('0x39')](_0x2edc60);})[_0x926f('0x1b')](function(_0x54356b){_0x3edd1d[_0x926f('0x3a')]=_0x54356b;return _0x3edd1d;})[_0x926f('0x1b')](respondWithFilteredResult(_0x9e1781,_0x2edc60))[_0x926f('0x3b')](handleError(_0x9e1781,null));};exports['show']=function(_0x535fda,_0x3dc61a){var _0x238502={'raw':!![],'where':{'id':_0x535fda[_0x926f('0x3c')]['id']}},_0xf7380d={};_0xf7380d[_0x926f('0x26')]=_[_0x926f('0x28')](db[_0x926f('0x21')][_0x926f('0x22')]);_0xf7380d[_0x926f('0x27')]=_[_0x926f('0x28')](_0x535fda['query']);_0xf7380d[_0x926f('0x29')]=_[_0x926f('0x2a')](_0xf7380d[_0x926f('0x26')],_0xf7380d[_0x926f('0x27')]);_0x238502[_0x926f('0x2b')]=_[_0x926f('0x2a')](_0xf7380d[_0x926f('0x26')],qs[_0x926f('0x3d')](_0x535fda[_0x926f('0x27')][_0x926f('0x3d')]));_0x238502[_0x926f('0x2b')]=_0x238502[_0x926f('0x2b')]['length']?_0x238502[_0x926f('0x2b')]:_0xf7380d[_0x926f('0x26')];if(_0x535fda[_0x926f('0x27')][_0x926f('0x37')]){_0x238502[_0x926f('0x38')]=[{'all':!![]}];}_0x238502=_[_0x926f('0x35')]({},_0x238502,_0x535fda[_0x926f('0x36')]);return db['MailServerOut']['find'](_0x238502)[_0x926f('0x1b')](handleEntityNotFound(_0x3dc61a,null))['then'](respondWithResult(_0x3dc61a,null))[_0x926f('0x3b')](handleError(_0x3dc61a,null));};exports[_0x926f('0x3e')]=function(_0x4f5c26,_0x1cb9dc){return db[_0x926f('0x21')][_0x926f('0x3e')](_0x4f5c26[_0x926f('0x3f')],{})[_0x926f('0x1b')](respondWithResult(_0x1cb9dc,0xc9))['catch'](handleError(_0x1cb9dc,null));};exports[_0x926f('0x1a')]=function(_0x436472,_0x19ef11){if(_0x436472[_0x926f('0x3f')]['id']){delete _0x436472[_0x926f('0x3f')]['id'];}return db[_0x926f('0x21')][_0x926f('0x40')]({'where':{'id':_0x436472[_0x926f('0x3c')]['id']}})[_0x926f('0x1b')](handleEntityNotFound(_0x19ef11,null))[_0x926f('0x1b')](saveUpdates(_0x436472[_0x926f('0x3f')],null))[_0x926f('0x1b')](respondWithResult(_0x19ef11,null))['catch'](handleError(_0x19ef11,null));};exports['destroy']=function(_0x4adcd3,_0x13d668){return db[_0x926f('0x21')][_0x926f('0x40')]({'where':{'id':_0x4adcd3['params']['id']}})[_0x926f('0x1b')](handleEntityNotFound(_0x13d668,null))[_0x926f('0x1b')](removeEntity(_0x13d668,null))[_0x926f('0x3b')](handleError(_0x13d668,null));};