Built motion from commit (unavailable).|2.5.18
[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 _0x840e=['../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','limit','apply','reject','save','update','then','destroy','end','stack','name','send','show','params','keys','rawAttributes','query','intersection','model','attributes','fields','length','includeAll','include','merge','options','MailApplication','find','catch','body','html-pdf','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api'];(function(_0x3784a8,_0x3730ce){var _0x2a602d=function(_0x433798){while(--_0x433798){_0x3784a8['push'](_0x3784a8['shift']());}};_0x2a602d(++_0x3730ce);}(_0x840e,0x194));var _0xe840=function(_0x44b0af,_0xdb6975){_0x44b0af=_0x44b0af-0x0;var _0xafaa74=_0x840e[_0x44b0af];return _0xafaa74;};'use strict';var pdf=require(_0xe840('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xe840('0x1'));var zipdir=require(_0xe840('0x2'));var jsonpatch=require(_0xe840('0x3'));var rp=require('request-promise');var moment=require(_0xe840('0x4'));var BPromise=require(_0xe840('0x5'));var Mustache=require(_0xe840('0x6'));var util=require(_0xe840('0x7'));var path=require('path');var sox=require(_0xe840('0x8'));var csv=require(_0xe840('0x9'));var ejs=require(_0xe840('0xa'));var fs=require('fs');var _=require(_0xe840('0xb'));var squel=require('squel');var crypto=require(_0xe840('0xc'));var jsforce=require(_0xe840('0xd'));var deskjs=require(_0xe840('0xe'));var toCsv=require(_0xe840('0x9'));var querystring=require(_0xe840('0xf'));var Papa=require(_0xe840('0x10'));var Redis=require(_0xe840('0x11'));var authService=require(_0xe840('0x12'));var qs=require(_0xe840('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xe840('0x14'));var logger=require(_0xe840('0x15'))(_0xe840('0x16'));var utils=require(_0xe840('0x17'));var config=require(_0xe840('0x18'));var licenseUtil=require(_0xe840('0x19'));var db=require(_0xe840('0x1a'))['db'];function respondWithStatusCode(_0x599e17,_0x253140){_0x253140=_0x253140||0xcc;return function(_0x9a4465){if(_0x9a4465){return _0x599e17[_0xe840('0x1b')](_0x253140);}return _0x599e17[_0xe840('0x1c')](_0x253140)['end']();};}function respondWithResult(_0x44fbfc,_0x18b833){_0x18b833=_0x18b833||0xc8;return function(_0x583487){if(_0x583487){return _0x44fbfc[_0xe840('0x1c')](_0x18b833)[_0xe840('0x1d')](_0x583487);}};}function respondWithFilteredResult(_0x5d2551,_0x2e391d){return function(_0x2a1765){if(_0x2a1765){var _0x24672b=_0x2a1765[_0xe840('0x1e')],_0x510e30=_0x2e391d[_0xe840('0x1f')],_0x15c660=_0x2e391d['offset']+_0x2e391d[_0xe840('0x20')],_0x1295a4;if(_0x15c660>=_0x24672b){_0x15c660=_0x24672b;_0x1295a4=0xc8;}else{_0x1295a4=0xce;}_0x5d2551['status'](_0x1295a4);return _0x5d2551['set']('Content-Range',_0x510e30+'-'+_0x15c660+'/'+_0x24672b)['json'](_0x2a1765);}return null;};}function patchUpdates(_0x5157e9){return function(_0x10e7d8){try{jsonpatch[_0xe840('0x21')](_0x10e7d8,_0x5157e9,!![]);}catch(_0x3169a0){return BPromise[_0xe840('0x22')](_0x3169a0);}return _0x10e7d8[_0xe840('0x23')]();};}function saveUpdates(_0x268ec2,_0x3fc9e8){return function(_0x596cba){if(_0x596cba){return _0x596cba[_0xe840('0x24')](_0x268ec2)[_0xe840('0x25')](function(_0x5c4313){return _0x5c4313;});}return null;};}function removeEntity(_0x142171,_0x160612){return function(_0x584002){if(_0x584002){return _0x584002[_0xe840('0x26')]()[_0xe840('0x25')](function(){_0x142171['status'](0xcc)[_0xe840('0x27')]();});}};}function handleEntityNotFound(_0x3cfc8f,_0x5695c1){return function(_0x5a968f){if(!_0x5a968f){_0x3cfc8f[_0xe840('0x1b')](0x194);}return _0x5a968f;};}function handleError(_0xeecb87,_0x5218f1){_0x5218f1=_0x5218f1||0x1f4;return function(_0x3e82d6){logger['error'](_0x3e82d6[_0xe840('0x28')]);if(_0x3e82d6[_0xe840('0x29')]){delete _0x3e82d6[_0xe840('0x29')];}_0xeecb87['status'](_0x5218f1)[_0xe840('0x2a')](_0x3e82d6);};}exports[_0xe840('0x2b')]=function(_0x3fb886,_0x134553){var _0x1c4cdd={'raw':!![],'where':{'id':_0x3fb886[_0xe840('0x2c')]['id']}},_0x51fd2f={};_0x51fd2f['model']=_[_0xe840('0x2d')](db['MailApplication'][_0xe840('0x2e')]);_0x51fd2f[_0xe840('0x2f')]=_[_0xe840('0x2d')](_0x3fb886['query']);_0x51fd2f['filters']=_[_0xe840('0x30')](_0x51fd2f[_0xe840('0x31')],_0x51fd2f[_0xe840('0x2f')]);_0x1c4cdd[_0xe840('0x32')]=_[_0xe840('0x30')](_0x51fd2f[_0xe840('0x31')],qs['fields'](_0x3fb886[_0xe840('0x2f')][_0xe840('0x33')]));_0x1c4cdd[_0xe840('0x32')]=_0x1c4cdd['attributes'][_0xe840('0x34')]?_0x1c4cdd['attributes']:_0x51fd2f['model'];if(_0x3fb886[_0xe840('0x2f')][_0xe840('0x35')]){_0x1c4cdd[_0xe840('0x36')]=[{'all':!![]}];}_0x1c4cdd=_[_0xe840('0x37')]({},_0x1c4cdd,_0x3fb886[_0xe840('0x38')]);return db[_0xe840('0x39')][_0xe840('0x3a')](_0x1c4cdd)['then'](handleEntityNotFound(_0x134553,null))[_0xe840('0x25')](respondWithResult(_0x134553,null))[_0xe840('0x3b')](handleError(_0x134553,null));};exports[_0xe840('0x24')]=function(_0x265f10,_0x50e8ae){if(_0x265f10['body']['id']){delete _0x265f10[_0xe840('0x3c')]['id'];}return db[_0xe840('0x39')][_0xe840('0x3a')]({'where':{'id':_0x265f10[_0xe840('0x2c')]['id']}})[_0xe840('0x25')](handleEntityNotFound(_0x50e8ae,null))['then'](saveUpdates(_0x265f10[_0xe840('0x3c')],null))['then'](respondWithResult(_0x50e8ae,null))[_0xe840('0x3b')](handleError(_0x50e8ae,null));};exports[_0xe840('0x26')]=function(_0x2407d7,_0x3f574f){return db[_0xe840('0x39')][_0xe840('0x3a')]({'where':{'id':_0x2407d7[_0xe840('0x2c')]['id']}})[_0xe840('0x25')](handleEntityNotFound(_0x3f574f,null))[_0xe840('0x25')](removeEntity(_0x3f574f,null))[_0xe840('0x3b')](handleError(_0x3f574f,null));};