Built motion from commit 47436d59.|2.6.7
[motion2.git] / server / api / mailSubstatus / mailSubstatus.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 _0xbc06=['undefined','count','set','Content-Range','json','reject','update','then','error','stack','name','send','index','map','MailSubstatus','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','nolimit','order','sort','where','merge','options','include','findAll','rows','catch','params','keys','length','includeAll','find','create','body','destroy','describe','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','limit'];(function(_0x4973c6,_0x3bd2b3){var _0x115f12=function(_0x5ee537){while(--_0x5ee537){_0x4973c6['push'](_0x4973c6['shift']());}};_0x115f12(++_0x3bd2b3);}(_0xbc06,0x77));var _0x6bc0=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xbc06[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x6bc0('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x6bc0('0x1'));var rp=require(_0x6bc0('0x2'));var moment=require(_0x6bc0('0x3'));var BPromise=require(_0x6bc0('0x4'));var Mustache=require(_0x6bc0('0x5'));var util=require(_0x6bc0('0x6'));var path=require('path');var sox=require(_0x6bc0('0x7'));var csv=require('to-csv');var ejs=require(_0x6bc0('0x8'));var fs=require('fs');var fs_extra=require(_0x6bc0('0x9'));var _=require(_0x6bc0('0xa'));var squel=require(_0x6bc0('0xb'));var crypto=require(_0x6bc0('0xc'));var jsforce=require(_0x6bc0('0xd'));var deskjs=require(_0x6bc0('0xe'));var toCsv=require('to-csv');var querystring=require(_0x6bc0('0xf'));var Papa=require(_0x6bc0('0x10'));var Redis=require(_0x6bc0('0x11'));var authService=require(_0x6bc0('0x12'));var qs=require(_0x6bc0('0x13'));var as=require(_0x6bc0('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x6bc0('0x15'))(_0x6bc0('0x16'));var utils=require('../../config/utils');var config=require(_0x6bc0('0x17'));var licenseUtil=require(_0x6bc0('0x18'));var db=require(_0x6bc0('0x19'))['db'];function respondWithStatusCode(_0x14168c,_0x5176e2){_0x5176e2=_0x5176e2||0xcc;return function(_0x232cd6){if(_0x232cd6){return _0x14168c[_0x6bc0('0x1a')](_0x5176e2);}return _0x14168c[_0x6bc0('0x1b')](_0x5176e2)[_0x6bc0('0x1c')]();};}function respondWithResult(_0xed2c4a,_0x41d4cb){_0x41d4cb=_0x41d4cb||0xc8;return function(_0x2b60dc){if(_0x2b60dc){return _0xed2c4a[_0x6bc0('0x1b')](_0x41d4cb)['json'](_0x2b60dc);}};}function respondWithFilteredResult(_0x3dbfeb,_0x372298){return function(_0x2f9c2b){if(_0x2f9c2b){var _0x3cda11=typeof _0x372298[_0x6bc0('0x1d')]==='undefined'&&typeof _0x372298[_0x6bc0('0x1e')]===_0x6bc0('0x1f');var _0x2fd776=_0x2f9c2b[_0x6bc0('0x20')];var _0x2da7a3=_0x3cda11?0x0:_0x372298['offset'];var _0x3c4386=_0x3cda11?_0x2f9c2b['count']:_0x372298['offset']+_0x372298[_0x6bc0('0x1e')];var _0x11635b;if(_0x3c4386>=_0x2fd776){_0x3c4386=_0x2fd776;_0x11635b=0xc8;}else{_0x11635b=0xce;}_0x3dbfeb[_0x6bc0('0x1b')](_0x11635b);return _0x3dbfeb[_0x6bc0('0x21')](_0x6bc0('0x22'),_0x2da7a3+'-'+_0x3c4386+'/'+_0x2fd776)[_0x6bc0('0x23')](_0x2f9c2b);}return null;};}function patchUpdates(_0x5cab8e){return function(_0x3a8b3f){try{jsonpatch['apply'](_0x3a8b3f,_0x5cab8e,!![]);}catch(_0x1b5262){return BPromise[_0x6bc0('0x24')](_0x1b5262);}return _0x3a8b3f['save']();};}function saveUpdates(_0x27d55b,_0x18bed5){return function(_0x3315b4){if(_0x3315b4){return _0x3315b4[_0x6bc0('0x25')](_0x27d55b)[_0x6bc0('0x26')](function(_0x1f911b){return _0x1f911b;});}return null;};}function removeEntity(_0x3504ff,_0x47623f){return function(_0x32db42){if(_0x32db42){return _0x32db42['destroy']()['then'](function(){_0x3504ff[_0x6bc0('0x1b')](0xcc)[_0x6bc0('0x1c')]();});}};}function handleEntityNotFound(_0x9a2485,_0x1cfcc3){return function(_0x3fdfa9){if(!_0x3fdfa9){_0x9a2485['sendStatus'](0x194);}return _0x3fdfa9;};}function handleError(_0x5467cc,_0xae382c){_0xae382c=_0xae382c||0x1f4;return function(_0x2904ce){logger[_0x6bc0('0x27')](_0x2904ce[_0x6bc0('0x28')]);if(_0x2904ce[_0x6bc0('0x29')]){delete _0x2904ce[_0x6bc0('0x29')];}_0x5467cc['status'](_0xae382c)[_0x6bc0('0x2a')](_0x2904ce);};}exports[_0x6bc0('0x2b')]=function(_0x214ce6,_0x27300d){var _0x26a6f6={},_0x5676cc={},_0x4a7daa={'count':0x0,'rows':[]};var _0x39eefa=_[_0x6bc0('0x2c')](db[_0x6bc0('0x2d')][_0x6bc0('0x2e')],function(_0x64ae32){return{'name':_0x64ae32[_0x6bc0('0x2f')],'type':_0x64ae32[_0x6bc0('0x30')][_0x6bc0('0x31')]};});_0x5676cc[_0x6bc0('0x32')]=_[_0x6bc0('0x2c')](_0x39eefa,_0x6bc0('0x29'));_0x5676cc[_0x6bc0('0x33')]=_['keys'](_0x214ce6['query']);_0x5676cc[_0x6bc0('0x34')]=_[_0x6bc0('0x35')](_0x5676cc[_0x6bc0('0x32')],_0x5676cc['query']);_0x26a6f6[_0x6bc0('0x36')]=_[_0x6bc0('0x35')](_0x5676cc['model'],qs[_0x6bc0('0x37')](_0x214ce6['query'][_0x6bc0('0x37')]));_0x26a6f6[_0x6bc0('0x36')]=_0x26a6f6[_0x6bc0('0x36')]['length']?_0x26a6f6['attributes']:_0x5676cc[_0x6bc0('0x32')];if(!_0x214ce6[_0x6bc0('0x33')]['hasOwnProperty'](_0x6bc0('0x38'))){_0x26a6f6[_0x6bc0('0x1e')]=qs[_0x6bc0('0x1e')](_0x214ce6[_0x6bc0('0x33')][_0x6bc0('0x1e')]);_0x26a6f6[_0x6bc0('0x1d')]=qs[_0x6bc0('0x1d')](_0x214ce6['query'][_0x6bc0('0x1d')]);}_0x26a6f6[_0x6bc0('0x39')]=qs[_0x6bc0('0x3a')](_0x214ce6['query'][_0x6bc0('0x3a')]);_0x26a6f6[_0x6bc0('0x3b')]=qs[_0x6bc0('0x34')](_['pick'](_0x214ce6[_0x6bc0('0x33')],_0x5676cc[_0x6bc0('0x34')]),_0x39eefa);if(_0x214ce6['query']['filter']){_0x26a6f6[_0x6bc0('0x3b')]=_[_0x6bc0('0x3c')](_0x26a6f6[_0x6bc0('0x3b')],{'$or':_[_0x6bc0('0x2c')](_0x39eefa,function(_0x1202aa){if(_0x1202aa[_0x6bc0('0x30')]!=='VIRTUAL'){var _0x4c147c={};_0x4c147c[_0x1202aa[_0x6bc0('0x29')]]={'$like':'%'+_0x214ce6[_0x6bc0('0x33')]['filter']+'%'};return _0x4c147c;}})});}_0x26a6f6=_['merge']({},_0x26a6f6,_0x214ce6[_0x6bc0('0x3d')]);var _0x508290={'where':_0x26a6f6[_0x6bc0('0x3b')]};return db['MailSubstatus'][_0x6bc0('0x20')](_0x508290)[_0x6bc0('0x26')](function(_0x5ed363){_0x4a7daa[_0x6bc0('0x20')]=_0x5ed363;if(_0x214ce6[_0x6bc0('0x33')]['includeAll']){_0x26a6f6[_0x6bc0('0x3e')]=[{'all':!![]}];}return db[_0x6bc0('0x2d')][_0x6bc0('0x3f')](_0x26a6f6);})['then'](function(_0x516cdc){_0x4a7daa[_0x6bc0('0x40')]=_0x516cdc;return _0x4a7daa;})[_0x6bc0('0x26')](respondWithFilteredResult(_0x27300d,_0x26a6f6))[_0x6bc0('0x41')](handleError(_0x27300d,null));};exports['show']=function(_0x4f38a8,_0xb33e01){var _0x491a94={'raw':!![],'where':{'id':_0x4f38a8[_0x6bc0('0x42')]['id']}},_0x1ae91b={};_0x1ae91b[_0x6bc0('0x32')]=_[_0x6bc0('0x43')](db[_0x6bc0('0x2d')][_0x6bc0('0x2e')]);_0x1ae91b[_0x6bc0('0x33')]=_[_0x6bc0('0x43')](_0x4f38a8[_0x6bc0('0x33')]);_0x1ae91b['filters']=_['intersection'](_0x1ae91b[_0x6bc0('0x32')],_0x1ae91b[_0x6bc0('0x33')]);_0x491a94[_0x6bc0('0x36')]=_[_0x6bc0('0x35')](_0x1ae91b['model'],qs[_0x6bc0('0x37')](_0x4f38a8['query'][_0x6bc0('0x37')]));_0x491a94[_0x6bc0('0x36')]=_0x491a94[_0x6bc0('0x36')][_0x6bc0('0x44')]?_0x491a94['attributes']:_0x1ae91b[_0x6bc0('0x32')];if(_0x4f38a8['query'][_0x6bc0('0x45')]){_0x491a94[_0x6bc0('0x3e')]=[{'all':!![]}];}_0x491a94=_[_0x6bc0('0x3c')]({},_0x491a94,_0x4f38a8[_0x6bc0('0x3d')]);return db[_0x6bc0('0x2d')][_0x6bc0('0x46')](_0x491a94)['then'](handleEntityNotFound(_0xb33e01,null))[_0x6bc0('0x26')](respondWithResult(_0xb33e01,null))['catch'](handleError(_0xb33e01,null));};exports[_0x6bc0('0x47')]=function(_0x41fc06,_0x4ae7fe){return db[_0x6bc0('0x2d')][_0x6bc0('0x47')](_0x41fc06[_0x6bc0('0x48')],{})[_0x6bc0('0x26')](respondWithResult(_0x4ae7fe,0xc9))['catch'](handleError(_0x4ae7fe,null));};exports['update']=function(_0x2470f9,_0x113fbd){if(_0x2470f9['body']['id']){delete _0x2470f9['body']['id'];}return db[_0x6bc0('0x2d')][_0x6bc0('0x46')]({'where':{'id':_0x2470f9[_0x6bc0('0x42')]['id']}})['then'](handleEntityNotFound(_0x113fbd,null))[_0x6bc0('0x26')](saveUpdates(_0x2470f9[_0x6bc0('0x48')],null))[_0x6bc0('0x26')](respondWithResult(_0x113fbd,null))[_0x6bc0('0x41')](handleError(_0x113fbd,null));};exports[_0x6bc0('0x49')]=function(_0x24ec88,_0xe65c90){return db[_0x6bc0('0x2d')][_0x6bc0('0x46')]({'where':{'id':_0x24ec88['params']['id']}})['then'](handleEntityNotFound(_0xe65c90,null))['then'](removeEntity(_0xe65c90,null))[_0x6bc0('0x41')](handleError(_0xe65c90,null));};exports[_0x6bc0('0x4a')]=function(_0x14a472,_0x37aec7){return db[_0x6bc0('0x2d')]['describe']()[_0x6bc0('0x26')](respondWithResult(_0x37aec7,null))['catch'](handleError(_0x37aec7,null));};