Built motion from commit (unavailable).|2.5.12
[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 _0xccc0=['find','catch','body','html-pdf','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','reject','update','destroy','then','error','stack','name','send','show','model','MailApplication','rawAttributes','query','keys','filters','intersection','attributes','fields','length','includeAll','merge','options'];(function(_0x391c55,_0x168617){var _0xa434e0=function(_0x51fa5c){while(--_0x51fa5c){_0x391c55['push'](_0x391c55['shift']());}};_0xa434e0(++_0x168617);}(_0xccc0,0x1b3));var _0x0ccc=function(_0x2276fb,_0x3e0eae){_0x2276fb=_0x2276fb-0x0;var _0x56b835=_0xccc0[_0x2276fb];return _0x56b835;};'use strict';var pdf=require(_0x0ccc('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x0ccc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x0ccc('0x2'));var rp=require(_0x0ccc('0x3'));var moment=require('moment');var BPromise=require(_0x0ccc('0x4'));var Mustache=require(_0x0ccc('0x5'));var util=require(_0x0ccc('0x6'));var path=require(_0x0ccc('0x7'));var sox=require(_0x0ccc('0x8'));var csv=require('to-csv');var ejs=require(_0x0ccc('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x0ccc('0xa'));var deskjs=require(_0x0ccc('0xb'));var toCsv=require(_0x0ccc('0xc'));var querystring=require(_0x0ccc('0xd'));var Papa=require(_0x0ccc('0xe'));var Redis=require(_0x0ccc('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x0ccc('0x10'));var hardwareService=require(_0x0ccc('0x11'));var logger=require('../../config/logger')(_0x0ccc('0x12'));var utils=require(_0x0ccc('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x0ccc('0x14'))['db'];function respondWithStatusCode(_0x305949,_0x3b5b84){_0x3b5b84=_0x3b5b84||0xcc;return function(_0x546842){if(_0x546842){return _0x305949[_0x0ccc('0x15')](_0x3b5b84);}return _0x305949[_0x0ccc('0x16')](_0x3b5b84)[_0x0ccc('0x17')]();};}function respondWithResult(_0x5066da,_0x381e74){_0x381e74=_0x381e74||0xc8;return function(_0x433ebe){if(_0x433ebe){return _0x5066da['status'](_0x381e74)[_0x0ccc('0x18')](_0x433ebe);}};}function respondWithFilteredResult(_0x1cb4bd,_0x5f40fd){return function(_0x379b5e){if(_0x379b5e){var _0x3ab144=_0x379b5e[_0x0ccc('0x19')],_0x3049d7=_0x5f40fd['offset'],_0x343ddc=_0x5f40fd[_0x0ccc('0x1a')]+_0x5f40fd['limit'],_0x2d6b29;if(_0x343ddc>=_0x3ab144){_0x343ddc=_0x3ab144;_0x2d6b29=0xc8;}else{_0x2d6b29=0xce;}_0x1cb4bd['status'](_0x2d6b29);return _0x1cb4bd[_0x0ccc('0x1b')](_0x0ccc('0x1c'),_0x3049d7+'-'+_0x343ddc+'/'+_0x3ab144)[_0x0ccc('0x18')](_0x379b5e);}return null;};}function patchUpdates(_0x266f1d){return function(_0x330443){try{jsonpatch['apply'](_0x330443,_0x266f1d,!![]);}catch(_0x25603a){return BPromise[_0x0ccc('0x1d')](_0x25603a);}return _0x330443['save']();};}function saveUpdates(_0x575725,_0x329882){return function(_0x500296){if(_0x500296){return _0x500296[_0x0ccc('0x1e')](_0x575725)['then'](function(_0x26f72b){return _0x26f72b;});}return null;};}function removeEntity(_0x5b1f01,_0x193748){return function(_0x5de31a){if(_0x5de31a){return _0x5de31a[_0x0ccc('0x1f')]()[_0x0ccc('0x20')](function(){_0x5b1f01[_0x0ccc('0x16')](0xcc)[_0x0ccc('0x17')]();});}};}function handleEntityNotFound(_0x293437,_0x7adc0e){return function(_0x4023ce){if(!_0x4023ce){_0x293437['sendStatus'](0x194);}return _0x4023ce;};}function handleError(_0x26ecc1,_0x108432){_0x108432=_0x108432||0x1f4;return function(_0x2ed325){logger[_0x0ccc('0x21')](_0x2ed325[_0x0ccc('0x22')]);if(_0x2ed325[_0x0ccc('0x23')]){delete _0x2ed325[_0x0ccc('0x23')];}_0x26ecc1[_0x0ccc('0x16')](_0x108432)[_0x0ccc('0x24')](_0x2ed325);};}exports[_0x0ccc('0x25')]=function(_0x5542d7,_0x1e893c){var _0x215b59={'raw':!![],'where':{'id':_0x5542d7['params']['id']}},_0x4cf1a3={};_0x4cf1a3[_0x0ccc('0x26')]=_['keys'](db[_0x0ccc('0x27')][_0x0ccc('0x28')]);_0x4cf1a3[_0x0ccc('0x29')]=_[_0x0ccc('0x2a')](_0x5542d7[_0x0ccc('0x29')]);_0x4cf1a3[_0x0ccc('0x2b')]=_[_0x0ccc('0x2c')](_0x4cf1a3[_0x0ccc('0x26')],_0x4cf1a3[_0x0ccc('0x29')]);_0x215b59[_0x0ccc('0x2d')]=_[_0x0ccc('0x2c')](_0x4cf1a3[_0x0ccc('0x26')],qs[_0x0ccc('0x2e')](_0x5542d7['query'][_0x0ccc('0x2e')]));_0x215b59[_0x0ccc('0x2d')]=_0x215b59['attributes'][_0x0ccc('0x2f')]?_0x215b59['attributes']:_0x4cf1a3[_0x0ccc('0x26')];if(_0x5542d7[_0x0ccc('0x29')][_0x0ccc('0x30')]){_0x215b59['include']=[{'all':!![]}];}_0x215b59=_[_0x0ccc('0x31')]({},_0x215b59,_0x5542d7[_0x0ccc('0x32')]);return db[_0x0ccc('0x27')][_0x0ccc('0x33')](_0x215b59)['then'](handleEntityNotFound(_0x1e893c,null))[_0x0ccc('0x20')](respondWithResult(_0x1e893c,null))[_0x0ccc('0x34')](handleError(_0x1e893c,null));};exports[_0x0ccc('0x1e')]=function(_0x46d62a,_0xda13e5){if(_0x46d62a[_0x0ccc('0x35')]['id']){delete _0x46d62a[_0x0ccc('0x35')]['id'];}return db[_0x0ccc('0x27')][_0x0ccc('0x33')]({'where':{'id':_0x46d62a['params']['id']}})['then'](handleEntityNotFound(_0xda13e5,null))[_0x0ccc('0x20')](saveUpdates(_0x46d62a['body'],null))[_0x0ccc('0x20')](respondWithResult(_0xda13e5,null))[_0x0ccc('0x34')](handleError(_0xda13e5,null));};exports[_0x0ccc('0x1f')]=function(_0x5e6917,_0x465155){return db[_0x0ccc('0x27')][_0x0ccc('0x33')]({'where':{'id':_0x5e6917['params']['id']}})['then'](handleEntityNotFound(_0x465155,null))[_0x0ccc('0x20')](removeEntity(_0x465155,null))[_0x0ccc('0x34')](handleError(_0x465155,null));};