aff0fdbb4f80456ec900b4f9d77752ef294e90a0
[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 _0x7c9f=['send','index','map','MailSubstatus','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','rawAttributes','find','create','update','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','then','destroy','sendStatus','error','stack','name'];(function(_0x5ec698,_0x499134){var _0x2cdeb0=function(_0x23d034){while(--_0x23d034){_0x5ec698['push'](_0x5ec698['shift']());}};_0x2cdeb0(++_0x499134);}(_0x7c9f,0x1eb));var _0xf7c9=function(_0x174d7b,_0x50f7ab){_0x174d7b=_0x174d7b-0x0;var _0x506f7a=_0x7c9f[_0x174d7b];return _0x506f7a;};'use strict';var emlformat=require(_0xf7c9('0x0'));var rimraf=require(_0xf7c9('0x1'));var zipdir=require(_0xf7c9('0x2'));var jsonpatch=require(_0xf7c9('0x3'));var rp=require(_0xf7c9('0x4'));var moment=require(_0xf7c9('0x5'));var BPromise=require(_0xf7c9('0x6'));var Mustache=require(_0xf7c9('0x7'));var util=require(_0xf7c9('0x8'));var path=require(_0xf7c9('0x9'));var sox=require('sox');var csv=require(_0xf7c9('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf7c9('0xb'));var _=require(_0xf7c9('0xc'));var squel=require('squel');var crypto=require(_0xf7c9('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xf7c9('0xe'));var toCsv=require(_0xf7c9('0xa'));var querystring=require(_0xf7c9('0xf'));var Papa=require(_0xf7c9('0x10'));var Redis=require(_0xf7c9('0x11'));var authService=require(_0xf7c9('0x12'));var qs=require(_0xf7c9('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf7c9('0x14'));var logger=require('../../config/logger')(_0xf7c9('0x15'));var utils=require(_0xf7c9('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xf7c9('0x17'));var db=require(_0xf7c9('0x18'))['db'];function respondWithStatusCode(_0x2f696d,_0x165fcd){_0x165fcd=_0x165fcd||0xcc;return function(_0x2f6e2d){if(_0x2f6e2d){return _0x2f696d['sendStatus'](_0x165fcd);}return _0x2f696d[_0xf7c9('0x19')](_0x165fcd)[_0xf7c9('0x1a')]();};}function respondWithResult(_0x2555a4,_0x82d12b){_0x82d12b=_0x82d12b||0xc8;return function(_0x4485d3){if(_0x4485d3){return _0x2555a4[_0xf7c9('0x19')](_0x82d12b)[_0xf7c9('0x1b')](_0x4485d3);}};}function respondWithFilteredResult(_0x23d4f9,_0x1f8725){return function(_0xf8c4f3){if(_0xf8c4f3){var _0x1b818e=typeof _0x1f8725[_0xf7c9('0x1c')]===_0xf7c9('0x1d')&&typeof _0x1f8725[_0xf7c9('0x1e')]===_0xf7c9('0x1d');var _0x4aa6dc=_0xf8c4f3[_0xf7c9('0x1f')];var _0x3d93ef=_0x1b818e?0x0:_0x1f8725[_0xf7c9('0x1c')];var _0x1616d9=_0x1b818e?_0xf8c4f3['count']:_0x1f8725['offset']+_0x1f8725[_0xf7c9('0x1e')];var _0x117468;if(_0x1616d9>=_0x4aa6dc){_0x1616d9=_0x4aa6dc;_0x117468=0xc8;}else{_0x117468=0xce;}_0x23d4f9[_0xf7c9('0x19')](_0x117468);return _0x23d4f9['set'](_0xf7c9('0x20'),_0x3d93ef+'-'+_0x1616d9+'/'+_0x4aa6dc)[_0xf7c9('0x1b')](_0xf8c4f3);}return null;};}function patchUpdates(_0x11c180){return function(_0x162442){try{jsonpatch[_0xf7c9('0x21')](_0x162442,_0x11c180,!![]);}catch(_0x25aa2d){return BPromise[_0xf7c9('0x22')](_0x25aa2d);}return _0x162442['save']();};}function saveUpdates(_0x3d84d2,_0x18cd8e){return function(_0x3ff1f5){if(_0x3ff1f5){return _0x3ff1f5['update'](_0x3d84d2)[_0xf7c9('0x23')](function(_0x1ff018){return _0x1ff018;});}return null;};}function removeEntity(_0x2874a2,_0x11f7b9){return function(_0x22d7c3){if(_0x22d7c3){return _0x22d7c3[_0xf7c9('0x24')]()[_0xf7c9('0x23')](function(){_0x2874a2[_0xf7c9('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2e9c61,_0x1aa39e){return function(_0x52043d){if(!_0x52043d){_0x2e9c61[_0xf7c9('0x25')](0x194);}return _0x52043d;};}function handleError(_0xf0984a,_0x404521){_0x404521=_0x404521||0x1f4;return function(_0x1ae59d){logger[_0xf7c9('0x26')](_0x1ae59d[_0xf7c9('0x27')]);if(_0x1ae59d[_0xf7c9('0x28')]){delete _0x1ae59d[_0xf7c9('0x28')];}_0xf0984a['status'](_0x404521)[_0xf7c9('0x29')](_0x1ae59d);};}exports[_0xf7c9('0x2a')]=function(_0x29c5fc,_0x4dc983){var _0x338bbe={},_0x401a43={},_0x12dd17={'count':0x0,'rows':[]};var _0x11931c=_[_0xf7c9('0x2b')](db[_0xf7c9('0x2c')]['rawAttributes'],function(_0x8df962){return{'name':_0x8df962['fieldName'],'type':_0x8df962[_0xf7c9('0x2d')][_0xf7c9('0x2e')]};});_0x401a43[_0xf7c9('0x2f')]=_['map'](_0x11931c,_0xf7c9('0x28'));_0x401a43[_0xf7c9('0x30')]=_[_0xf7c9('0x31')](_0x29c5fc[_0xf7c9('0x30')]);_0x401a43['filters']=_[_0xf7c9('0x32')](_0x401a43['model'],_0x401a43[_0xf7c9('0x30')]);_0x338bbe['attributes']=_[_0xf7c9('0x32')](_0x401a43[_0xf7c9('0x2f')],qs[_0xf7c9('0x33')](_0x29c5fc[_0xf7c9('0x30')][_0xf7c9('0x33')]));_0x338bbe[_0xf7c9('0x34')]=_0x338bbe[_0xf7c9('0x34')][_0xf7c9('0x35')]?_0x338bbe['attributes']:_0x401a43[_0xf7c9('0x2f')];if(!_0x29c5fc[_0xf7c9('0x30')][_0xf7c9('0x36')](_0xf7c9('0x37'))){_0x338bbe[_0xf7c9('0x1e')]=qs[_0xf7c9('0x1e')](_0x29c5fc[_0xf7c9('0x30')][_0xf7c9('0x1e')]);_0x338bbe[_0xf7c9('0x1c')]=qs[_0xf7c9('0x1c')](_0x29c5fc[_0xf7c9('0x30')]['offset']);}_0x338bbe['order']=qs[_0xf7c9('0x38')](_0x29c5fc[_0xf7c9('0x30')][_0xf7c9('0x38')]);_0x338bbe[_0xf7c9('0x39')]=qs[_0xf7c9('0x3a')](_[_0xf7c9('0x3b')](_0x29c5fc[_0xf7c9('0x30')],_0x401a43['filters']),_0x11931c);if(_0x29c5fc['query'][_0xf7c9('0x3c')]){_0x338bbe[_0xf7c9('0x39')]=_[_0xf7c9('0x3d')](_0x338bbe['where'],{'$or':_[_0xf7c9('0x2b')](_0x11931c,function(_0x5af31a){if(_0x5af31a['type']!==_0xf7c9('0x3e')){var _0x4e778c={};_0x4e778c[_0x5af31a[_0xf7c9('0x28')]]={'$like':'%'+_0x29c5fc['query'][_0xf7c9('0x3c')]+'%'};return _0x4e778c;}})});}_0x338bbe=_[_0xf7c9('0x3d')]({},_0x338bbe,_0x29c5fc[_0xf7c9('0x3f')]);var _0x5510e8={'where':_0x338bbe[_0xf7c9('0x39')]};return db[_0xf7c9('0x2c')][_0xf7c9('0x1f')](_0x5510e8)[_0xf7c9('0x23')](function(_0x2a4863){_0x12dd17['count']=_0x2a4863;if(_0x29c5fc[_0xf7c9('0x30')][_0xf7c9('0x40')]){_0x338bbe[_0xf7c9('0x41')]=[{'all':!![]}];}return db['MailSubstatus'][_0xf7c9('0x42')](_0x338bbe);})[_0xf7c9('0x23')](function(_0x250475){_0x12dd17['rows']=_0x250475;return _0x12dd17;})[_0xf7c9('0x23')](respondWithFilteredResult(_0x4dc983,_0x338bbe))[_0xf7c9('0x43')](handleError(_0x4dc983,null));};exports[_0xf7c9('0x44')]=function(_0x191ea0,_0x3938f1){var _0x430411={'raw':!![],'where':{'id':_0x191ea0['params']['id']}},_0x1ac2c8={};_0x1ac2c8[_0xf7c9('0x2f')]=_['keys'](db[_0xf7c9('0x2c')][_0xf7c9('0x45')]);_0x1ac2c8['query']=_['keys'](_0x191ea0[_0xf7c9('0x30')]);_0x1ac2c8[_0xf7c9('0x3a')]=_['intersection'](_0x1ac2c8[_0xf7c9('0x2f')],_0x1ac2c8['query']);_0x430411[_0xf7c9('0x34')]=_[_0xf7c9('0x32')](_0x1ac2c8[_0xf7c9('0x2f')],qs[_0xf7c9('0x33')](_0x191ea0[_0xf7c9('0x30')][_0xf7c9('0x33')]));_0x430411[_0xf7c9('0x34')]=_0x430411[_0xf7c9('0x34')][_0xf7c9('0x35')]?_0x430411[_0xf7c9('0x34')]:_0x1ac2c8[_0xf7c9('0x2f')];if(_0x191ea0[_0xf7c9('0x30')][_0xf7c9('0x40')]){_0x430411[_0xf7c9('0x41')]=[{'all':!![]}];}_0x430411=_[_0xf7c9('0x3d')]({},_0x430411,_0x191ea0['options']);return db['MailSubstatus'][_0xf7c9('0x46')](_0x430411)[_0xf7c9('0x23')](handleEntityNotFound(_0x3938f1,null))[_0xf7c9('0x23')](respondWithResult(_0x3938f1,null))[_0xf7c9('0x43')](handleError(_0x3938f1,null));};exports[_0xf7c9('0x47')]=function(_0x547cc2,_0x2cbc19){return db['MailSubstatus'][_0xf7c9('0x47')](_0x547cc2['body'],{})[_0xf7c9('0x23')](respondWithResult(_0x2cbc19,0xc9))['catch'](handleError(_0x2cbc19,null));};exports[_0xf7c9('0x48')]=function(_0x296627,_0x2cad18){if(_0x296627[_0xf7c9('0x49')]['id']){delete _0x296627['body']['id'];}return db[_0xf7c9('0x2c')][_0xf7c9('0x46')]({'where':{'id':_0x296627[_0xf7c9('0x4a')]['id']}})[_0xf7c9('0x23')](handleEntityNotFound(_0x2cad18,null))[_0xf7c9('0x23')](saveUpdates(_0x296627[_0xf7c9('0x49')],null))[_0xf7c9('0x23')](respondWithResult(_0x2cad18,null))[_0xf7c9('0x43')](handleError(_0x2cad18,null));};exports[_0xf7c9('0x24')]=function(_0x4da3d6,_0x426208){return db[_0xf7c9('0x2c')][_0xf7c9('0x46')]({'where':{'id':_0x4da3d6[_0xf7c9('0x4a')]['id']}})[_0xf7c9('0x23')](handleEntityNotFound(_0x426208,null))[_0xf7c9('0x23')](removeEntity(_0x426208,null))[_0xf7c9('0x43')](handleError(_0x426208,null));};exports['describe']=function(_0x1ac42b,_0x2533f){return db[_0xf7c9('0x2c')][_0xf7c9('0x4b')]()[_0xf7c9('0x23')](respondWithResult(_0x2533f,null))[_0xf7c9('0x43')](handleError(_0x2533f,null));};