Built motion from commit (unavailable).|2.5.6
[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 _0x9f18=['stack','name','show','params','keys','MailApplication','rawAttributes','query','intersection','model','attributes','fields','includeAll','include','options','find','catch','update','body','destroy','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','to-csv','lodash','squel','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','sendStatus','status','end','json','offset','apply','reject','save','then','error'];(function(_0x5189d6,_0x557268){var _0xb04855=function(_0x49d867){while(--_0x49d867){_0x5189d6['push'](_0x5189d6['shift']());}};_0xb04855(++_0x557268);}(_0x9f18,0x1df));var _0x89f1=function(_0x18aaaf,_0x385db6){_0x18aaaf=_0x18aaaf-0x0;var _0x52d892=_0x9f18[_0x18aaaf];return _0x52d892;};'use strict';var pdf=require(_0x89f1('0x0'));var emlformat=require(_0x89f1('0x1'));var rimraf=require(_0x89f1('0x2'));var zipdir=require(_0x89f1('0x3'));var jsonpatch=require(_0x89f1('0x4'));var rp=require(_0x89f1('0x5'));var moment=require(_0x89f1('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x89f1('0x7'));var util=require('util');var path=require(_0x89f1('0x8'));var sox=require('sox');var csv=require(_0x89f1('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x89f1('0xa'));var squel=require(_0x89f1('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x89f1('0x9'));var querystring=require(_0x89f1('0xc'));var Papa=require(_0x89f1('0xd'));var Redis=require(_0x89f1('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x89f1('0xf'));var as=require(_0x89f1('0x10'));var hardwareService=require(_0x89f1('0x11'));var logger=require('../../config/logger')(_0x89f1('0x12'));var utils=require(_0x89f1('0x13'));var config=require(_0x89f1('0x14'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x37753a,_0x1eddce){_0x1eddce=_0x1eddce||0xcc;return function(_0x164c9c){if(_0x164c9c){return _0x37753a[_0x89f1('0x15')](_0x1eddce);}return _0x37753a[_0x89f1('0x16')](_0x1eddce)[_0x89f1('0x17')]();};}function respondWithResult(_0x4d203c,_0x54fc43){_0x54fc43=_0x54fc43||0xc8;return function(_0x196549){if(_0x196549){return _0x4d203c[_0x89f1('0x16')](_0x54fc43)[_0x89f1('0x18')](_0x196549);}};}function respondWithFilteredResult(_0x1dd8c9,_0x783605){return function(_0x866fa9){if(_0x866fa9){var _0x1f67e7=_0x866fa9['count'],_0x4ea229=_0x783605[_0x89f1('0x19')],_0x298c9a=_0x783605['offset']+_0x783605['limit'],_0x1acf5b;if(_0x298c9a>=_0x1f67e7){_0x298c9a=_0x1f67e7;_0x1acf5b=0xc8;}else{_0x1acf5b=0xce;}_0x1dd8c9[_0x89f1('0x16')](_0x1acf5b);return _0x1dd8c9['set']('Content-Range',_0x4ea229+'-'+_0x298c9a+'/'+_0x1f67e7)[_0x89f1('0x18')](_0x866fa9);}return null;};}function patchUpdates(_0x5a86a7){return function(_0x4a8e59){try{jsonpatch[_0x89f1('0x1a')](_0x4a8e59,_0x5a86a7,!![]);}catch(_0x4f056e){return BPromise[_0x89f1('0x1b')](_0x4f056e);}return _0x4a8e59[_0x89f1('0x1c')]();};}function saveUpdates(_0x3b5dc5,_0x51fb8d){return function(_0x2f2494){if(_0x2f2494){return _0x2f2494['update'](_0x3b5dc5)[_0x89f1('0x1d')](function(_0x583281){return _0x583281;});}return null;};}function removeEntity(_0x50c4b1,_0x29b926){return function(_0xff61a2){if(_0xff61a2){return _0xff61a2['destroy']()[_0x89f1('0x1d')](function(){_0x50c4b1[_0x89f1('0x16')](0xcc)[_0x89f1('0x17')]();});}};}function handleEntityNotFound(_0x16c653,_0x3d3054){return function(_0x3eec80){if(!_0x3eec80){_0x16c653[_0x89f1('0x15')](0x194);}return _0x3eec80;};}function handleError(_0x269798,_0x4648c2){_0x4648c2=_0x4648c2||0x1f4;return function(_0x27316a){logger[_0x89f1('0x1e')](_0x27316a[_0x89f1('0x1f')]);if(_0x27316a[_0x89f1('0x20')]){delete _0x27316a[_0x89f1('0x20')];}_0x269798[_0x89f1('0x16')](_0x4648c2)['send'](_0x27316a);};}exports[_0x89f1('0x21')]=function(_0x2e7a99,_0x2b7ded){var _0x882bbd={'raw':!![],'where':{'id':_0x2e7a99[_0x89f1('0x22')]['id']}},_0x2a6847={};_0x2a6847['model']=_[_0x89f1('0x23')](db[_0x89f1('0x24')][_0x89f1('0x25')]);_0x2a6847[_0x89f1('0x26')]=_[_0x89f1('0x23')](_0x2e7a99[_0x89f1('0x26')]);_0x2a6847['filtears']=_[_0x89f1('0x27')](_0x2a6847[_0x89f1('0x28')],_0x2a6847[_0x89f1('0x26')]);_0x882bbd[_0x89f1('0x29')]=_['intersection'](_0x2a6847[_0x89f1('0x28')],qs[_0x89f1('0x2a')](_0x2e7a99['query'][_0x89f1('0x2a')]));_0x882bbd[_0x89f1('0x29')]=_0x882bbd[_0x89f1('0x29')]['length']?_0x882bbd['attributes']:_0x2a6847[_0x89f1('0x28')];if(_0x2e7a99[_0x89f1('0x26')][_0x89f1('0x2b')]){_0x882bbd[_0x89f1('0x2c')]=[{'all':!![]}];}_0x882bbd=_['merge']({},_0x882bbd,_0x2e7a99[_0x89f1('0x2d')]);return db[_0x89f1('0x24')][_0x89f1('0x2e')](_0x882bbd)['then'](handleEntityNotFound(_0x2b7ded,null))[_0x89f1('0x1d')](respondWithResult(_0x2b7ded,null))[_0x89f1('0x2f')](handleError(_0x2b7ded,null));};exports[_0x89f1('0x30')]=function(_0x128bd1,_0x188b4d){if(_0x128bd1[_0x89f1('0x31')]['id']){delete _0x128bd1[_0x89f1('0x31')]['id'];}return db[_0x89f1('0x24')][_0x89f1('0x2e')]({'where':{'id':_0x128bd1[_0x89f1('0x22')]['id']}})[_0x89f1('0x1d')](handleEntityNotFound(_0x188b4d,null))[_0x89f1('0x1d')](saveUpdates(_0x128bd1[_0x89f1('0x31')],null))[_0x89f1('0x1d')](respondWithResult(_0x188b4d,null))[_0x89f1('0x2f')](handleError(_0x188b4d,null));};exports[_0x89f1('0x32')]=function(_0x5149e7,_0x6da494){return db['MailApplication'][_0x89f1('0x2e')]({'where':{'id':_0x5149e7[_0x89f1('0x22')]['id']}})[_0x89f1('0x1d')](handleEntityNotFound(_0x6da494,null))['then'](removeEntity(_0x6da494,null))[_0x89f1('0x2f')](handleError(_0x6da494,null));};