c9fbfc358062a8438e402fee11d5640a52f373e1
[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 _0xf7f3=['attributes','intersection','fields','length','nolimit','sort','where','merge','VIRTUAL','filter','options','includeAll','findAll','rows','catch','params','rawAttributes','include','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','util','path','to-csv','fs-extra','lodash','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','sendStatus','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','save','update','then','destroy','error','name','send','index','map','MailSubstatus','fieldName','type','model','keys','query','filters'];(function(_0x4a9fb1,_0x273043){var _0x348672=function(_0x142b69){while(--_0x142b69){_0x4a9fb1['push'](_0x4a9fb1['shift']());}};_0x348672(++_0x273043);}(_0xf7f3,0x12a));var _0x3f7f=function(_0x2e9770,_0xee3326){_0x2e9770=_0x2e9770-0x0;var _0x3bfbac=_0xf7f3[_0x2e9770];return _0x3bfbac;};'use strict';var emlformat=require(_0x3f7f('0x0'));var rimraf=require(_0x3f7f('0x1'));var zipdir=require(_0x3f7f('0x2'));var jsonpatch=require(_0x3f7f('0x3'));var rp=require(_0x3f7f('0x4'));var moment=require(_0x3f7f('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x3f7f('0x6'));var path=require(_0x3f7f('0x7'));var sox=require('sox');var csv=require(_0x3f7f('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3f7f('0x9'));var _=require(_0x3f7f('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x3f7f('0x8'));var querystring=require(_0x3f7f('0xb'));var Papa=require(_0x3f7f('0xc'));var Redis=require(_0x3f7f('0xd'));var authService=require(_0x3f7f('0xe'));var qs=require(_0x3f7f('0xf'));var as=require(_0x3f7f('0x10'));var hardwareService=require(_0x3f7f('0x11'));var logger=require('../../config/logger')('api');var utils=require(_0x3f7f('0x12'));var config=require(_0x3f7f('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x476a1b,_0x3427d1){_0x3427d1=_0x3427d1||0xcc;return function(_0x5b9d49){if(_0x5b9d49){return _0x476a1b[_0x3f7f('0x14')](_0x3427d1);}return _0x476a1b[_0x3f7f('0x15')](_0x3427d1)[_0x3f7f('0x16')]();};}function respondWithResult(_0x4dc9b4,_0x1f2303){_0x1f2303=_0x1f2303||0xc8;return function(_0xf4e693){if(_0xf4e693){return _0x4dc9b4[_0x3f7f('0x15')](_0x1f2303)[_0x3f7f('0x17')](_0xf4e693);}};}function respondWithFilteredResult(_0x3d8963,_0x53c24b){return function(_0x14c08e){if(_0x14c08e){var _0x5c7e42=typeof _0x53c24b[_0x3f7f('0x18')]===_0x3f7f('0x19')&&typeof _0x53c24b['limit']===_0x3f7f('0x19');var _0x59fd8b=_0x14c08e[_0x3f7f('0x1a')];var _0x4ce1c5=_0x5c7e42?0x0:_0x53c24b['offset'];var _0x4a9f51=_0x5c7e42?_0x14c08e['count']:_0x53c24b[_0x3f7f('0x18')]+_0x53c24b[_0x3f7f('0x1b')];var _0x3a47ce;if(_0x4a9f51>=_0x59fd8b){_0x4a9f51=_0x59fd8b;_0x3a47ce=0xc8;}else{_0x3a47ce=0xce;}_0x3d8963[_0x3f7f('0x15')](_0x3a47ce);return _0x3d8963['set'](_0x3f7f('0x1c'),_0x4ce1c5+'-'+_0x4a9f51+'/'+_0x59fd8b)[_0x3f7f('0x17')](_0x14c08e);}return null;};}function patchUpdates(_0x6e57b7){return function(_0x4197d1){try{jsonpatch[_0x3f7f('0x1d')](_0x4197d1,_0x6e57b7,!![]);}catch(_0x105fd9){return BPromise[_0x3f7f('0x1e')](_0x105fd9);}return _0x4197d1[_0x3f7f('0x1f')]();};}function saveUpdates(_0x4b2b3d,_0x4c5566){return function(_0xeb7e8){if(_0xeb7e8){return _0xeb7e8[_0x3f7f('0x20')](_0x4b2b3d)[_0x3f7f('0x21')](function(_0x4d52f1){return _0x4d52f1;});}return null;};}function removeEntity(_0x58c519,_0x5c1fdd){return function(_0x3e980f){if(_0x3e980f){return _0x3e980f[_0x3f7f('0x22')]()[_0x3f7f('0x21')](function(){_0x58c519[_0x3f7f('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x351bfc,_0x286784){return function(_0x913eda){if(!_0x913eda){_0x351bfc[_0x3f7f('0x14')](0x194);}return _0x913eda;};}function handleError(_0x59f0d6,_0x325ecb){_0x325ecb=_0x325ecb||0x1f4;return function(_0x487dea){logger[_0x3f7f('0x23')](_0x487dea['stack']);if(_0x487dea[_0x3f7f('0x24')]){delete _0x487dea['name'];}_0x59f0d6[_0x3f7f('0x15')](_0x325ecb)[_0x3f7f('0x25')](_0x487dea);};}exports[_0x3f7f('0x26')]=function(_0x182b52,_0xc1f65c){var _0x10ac1f={},_0x1167b8={},_0x266763={'count':0x0,'rows':[]};var _0x1f2b19=_[_0x3f7f('0x27')](db[_0x3f7f('0x28')]['rawAttributes'],function(_0x4da6f1){return{'name':_0x4da6f1[_0x3f7f('0x29')],'type':_0x4da6f1[_0x3f7f('0x2a')]['key']};});_0x1167b8[_0x3f7f('0x2b')]=_[_0x3f7f('0x27')](_0x1f2b19,_0x3f7f('0x24'));_0x1167b8['query']=_[_0x3f7f('0x2c')](_0x182b52[_0x3f7f('0x2d')]);_0x1167b8[_0x3f7f('0x2e')]=_['intersection'](_0x1167b8[_0x3f7f('0x2b')],_0x1167b8['query']);_0x10ac1f[_0x3f7f('0x2f')]=_[_0x3f7f('0x30')](_0x1167b8[_0x3f7f('0x2b')],qs['fields'](_0x182b52[_0x3f7f('0x2d')][_0x3f7f('0x31')]));_0x10ac1f[_0x3f7f('0x2f')]=_0x10ac1f[_0x3f7f('0x2f')][_0x3f7f('0x32')]?_0x10ac1f[_0x3f7f('0x2f')]:_0x1167b8[_0x3f7f('0x2b')];if(!_0x182b52[_0x3f7f('0x2d')]['hasOwnProperty'](_0x3f7f('0x33'))){_0x10ac1f['limit']=qs['limit'](_0x182b52[_0x3f7f('0x2d')][_0x3f7f('0x1b')]);_0x10ac1f[_0x3f7f('0x18')]=qs[_0x3f7f('0x18')](_0x182b52[_0x3f7f('0x2d')][_0x3f7f('0x18')]);}_0x10ac1f['order']=qs['sort'](_0x182b52[_0x3f7f('0x2d')][_0x3f7f('0x34')]);_0x10ac1f[_0x3f7f('0x35')]=qs[_0x3f7f('0x2e')](_['pick'](_0x182b52[_0x3f7f('0x2d')],_0x1167b8[_0x3f7f('0x2e')]),_0x1f2b19);if(_0x182b52[_0x3f7f('0x2d')]['filter']){_0x10ac1f[_0x3f7f('0x35')]=_[_0x3f7f('0x36')](_0x10ac1f[_0x3f7f('0x35')],{'$or':_['map'](_0x1f2b19,function(_0x1769ce){if(_0x1769ce[_0x3f7f('0x2a')]!==_0x3f7f('0x37')){var _0x5afd22={};_0x5afd22[_0x1769ce[_0x3f7f('0x24')]]={'$like':'%'+_0x182b52[_0x3f7f('0x2d')][_0x3f7f('0x38')]+'%'};return _0x5afd22;}})});}_0x10ac1f=_[_0x3f7f('0x36')]({},_0x10ac1f,_0x182b52[_0x3f7f('0x39')]);var _0x588939={'where':_0x10ac1f[_0x3f7f('0x35')]};return db[_0x3f7f('0x28')]['count'](_0x588939)['then'](function(_0xb7f12b){_0x266763['count']=_0xb7f12b;if(_0x182b52[_0x3f7f('0x2d')][_0x3f7f('0x3a')]){_0x10ac1f['include']=[{'all':!![]}];}return db[_0x3f7f('0x28')][_0x3f7f('0x3b')](_0x10ac1f);})[_0x3f7f('0x21')](function(_0x53587a){_0x266763[_0x3f7f('0x3c')]=_0x53587a;return _0x266763;})[_0x3f7f('0x21')](respondWithFilteredResult(_0xc1f65c,_0x10ac1f))[_0x3f7f('0x3d')](handleError(_0xc1f65c,null));};exports['show']=function(_0x1142d4,_0xb6ea25){var _0x1f3dbe={'raw':!![],'where':{'id':_0x1142d4[_0x3f7f('0x3e')]['id']}},_0x318556={};_0x318556[_0x3f7f('0x2b')]=_[_0x3f7f('0x2c')](db[_0x3f7f('0x28')][_0x3f7f('0x3f')]);_0x318556['query']=_[_0x3f7f('0x2c')](_0x1142d4['query']);_0x318556[_0x3f7f('0x2e')]=_[_0x3f7f('0x30')](_0x318556[_0x3f7f('0x2b')],_0x318556[_0x3f7f('0x2d')]);_0x1f3dbe['attributes']=_['intersection'](_0x318556[_0x3f7f('0x2b')],qs['fields'](_0x1142d4['query'][_0x3f7f('0x31')]));_0x1f3dbe[_0x3f7f('0x2f')]=_0x1f3dbe[_0x3f7f('0x2f')][_0x3f7f('0x32')]?_0x1f3dbe['attributes']:_0x318556[_0x3f7f('0x2b')];if(_0x1142d4[_0x3f7f('0x2d')][_0x3f7f('0x3a')]){_0x1f3dbe[_0x3f7f('0x40')]=[{'all':!![]}];}_0x1f3dbe=_[_0x3f7f('0x36')]({},_0x1f3dbe,_0x1142d4[_0x3f7f('0x39')]);return db[_0x3f7f('0x28')][_0x3f7f('0x41')](_0x1f3dbe)[_0x3f7f('0x21')](handleEntityNotFound(_0xb6ea25,null))[_0x3f7f('0x21')](respondWithResult(_0xb6ea25,null))[_0x3f7f('0x3d')](handleError(_0xb6ea25,null));};exports[_0x3f7f('0x42')]=function(_0x57c90e,_0x56479e){return db['MailSubstatus'][_0x3f7f('0x42')](_0x57c90e[_0x3f7f('0x43')],{})['then'](respondWithResult(_0x56479e,0xc9))[_0x3f7f('0x3d')](handleError(_0x56479e,null));};exports[_0x3f7f('0x20')]=function(_0x3d8dc0,_0x35f35e){if(_0x3d8dc0['body']['id']){delete _0x3d8dc0[_0x3f7f('0x43')]['id'];}return db[_0x3f7f('0x28')][_0x3f7f('0x41')]({'where':{'id':_0x3d8dc0[_0x3f7f('0x3e')]['id']}})[_0x3f7f('0x21')](handleEntityNotFound(_0x35f35e,null))['then'](saveUpdates(_0x3d8dc0[_0x3f7f('0x43')],null))[_0x3f7f('0x21')](respondWithResult(_0x35f35e,null))[_0x3f7f('0x3d')](handleError(_0x35f35e,null));};exports[_0x3f7f('0x22')]=function(_0x2041d3,_0x37d86e){return db[_0x3f7f('0x28')][_0x3f7f('0x41')]({'where':{'id':_0x2041d3[_0x3f7f('0x3e')]['id']}})[_0x3f7f('0x21')](handleEntityNotFound(_0x37d86e,null))[_0x3f7f('0x21')](removeEntity(_0x37d86e,null))['catch'](handleError(_0x37d86e,null));};exports[_0x3f7f('0x44')]=function(_0x25d767,_0x542cba){return db[_0x3f7f('0x28')]['describe']()[_0x3f7f('0x21')](respondWithResult(_0x542cba,null))['catch'](handleError(_0x542cba,null));};