Built motion from commit 9d0783e6.|2.6.13
[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 _0x5bc1=['index','map','MailSubstatus','rawAttributes','fieldName','key','model','query','keys','filters','intersection','fields','attributes','nolimit','sort','where','filter','merge','type','includeAll','include','findAll','rows','catch','show','options','find','create','update','body','params','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','then','error','stack','name','send'];(function(_0x2e1d0d,_0x449fcb){var _0x3ff2b6=function(_0x8b7369){while(--_0x8b7369){_0x2e1d0d['push'](_0x2e1d0d['shift']());}};_0x3ff2b6(++_0x449fcb);}(_0x5bc1,0xf8));var _0x15bc=function(_0x1734ab,_0x254bb2){_0x1734ab=_0x1734ab-0x0;var _0x41008e=_0x5bc1[_0x1734ab];return _0x41008e;};'use strict';var emlformat=require(_0x15bc('0x0'));var rimraf=require(_0x15bc('0x1'));var zipdir=require(_0x15bc('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x15bc('0x3'));var moment=require(_0x15bc('0x4'));var BPromise=require(_0x15bc('0x5'));var Mustache=require(_0x15bc('0x6'));var util=require(_0x15bc('0x7'));var path=require(_0x15bc('0x8'));var sox=require(_0x15bc('0x9'));var csv=require(_0x15bc('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x15bc('0xb'));var crypto=require(_0x15bc('0xc'));var jsforce=require(_0x15bc('0xd'));var deskjs=require(_0x15bc('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x15bc('0xf'));var Redis=require(_0x15bc('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x15bc('0x11'));var hardwareService=require(_0x15bc('0x12'));var logger=require('../../config/logger')(_0x15bc('0x13'));var utils=require(_0x15bc('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x15bc('0x15'));var db=require(_0x15bc('0x16'))['db'];function respondWithStatusCode(_0x4f107c,_0x4f9ed9){_0x4f9ed9=_0x4f9ed9||0xcc;return function(_0x3821da){if(_0x3821da){return _0x4f107c[_0x15bc('0x17')](_0x4f9ed9);}return _0x4f107c[_0x15bc('0x18')](_0x4f9ed9)[_0x15bc('0x19')]();};}function respondWithResult(_0x4ac1f5,_0x3da703){_0x3da703=_0x3da703||0xc8;return function(_0x196e31){if(_0x196e31){return _0x4ac1f5[_0x15bc('0x18')](_0x3da703)[_0x15bc('0x1a')](_0x196e31);}};}function respondWithFilteredResult(_0x1cd724,_0x400104){return function(_0x4e0688){if(_0x4e0688){var _0x28abbf=typeof _0x400104[_0x15bc('0x1b')]===_0x15bc('0x1c')&&typeof _0x400104[_0x15bc('0x1d')]===_0x15bc('0x1c');var _0xa8d7fe=_0x4e0688['count'];var _0xd7f74=_0x28abbf?0x0:_0x400104['offset'];var _0x1bcab9=_0x28abbf?_0x4e0688[_0x15bc('0x1e')]:_0x400104[_0x15bc('0x1b')]+_0x400104[_0x15bc('0x1d')];var _0x53a02d;if(_0x1bcab9>=_0xa8d7fe){_0x1bcab9=_0xa8d7fe;_0x53a02d=0xc8;}else{_0x53a02d=0xce;}_0x1cd724[_0x15bc('0x18')](_0x53a02d);return _0x1cd724[_0x15bc('0x1f')](_0x15bc('0x20'),_0xd7f74+'-'+_0x1bcab9+'/'+_0xa8d7fe)['json'](_0x4e0688);}return null;};}function patchUpdates(_0x3be890){return function(_0x54e9fb){try{jsonpatch[_0x15bc('0x21')](_0x54e9fb,_0x3be890,!![]);}catch(_0x4853ee){return BPromise[_0x15bc('0x22')](_0x4853ee);}return _0x54e9fb['save']();};}function saveUpdates(_0xbec85d,_0x46a09b){return function(_0x2469a2){if(_0x2469a2){return _0x2469a2['update'](_0xbec85d)['then'](function(_0x331ecd){return _0x331ecd;});}return null;};}function removeEntity(_0x18656b,_0xcf2efd){return function(_0x15d35c){if(_0x15d35c){return _0x15d35c['destroy']()[_0x15bc('0x23')](function(){_0x18656b['status'](0xcc)[_0x15bc('0x19')]();});}};}function handleEntityNotFound(_0x53869b,_0xab443d){return function(_0x555c5e){if(!_0x555c5e){_0x53869b['sendStatus'](0x194);}return _0x555c5e;};}function handleError(_0x263889,_0x7dc462){_0x7dc462=_0x7dc462||0x1f4;return function(_0x4026b5){logger[_0x15bc('0x24')](_0x4026b5[_0x15bc('0x25')]);if(_0x4026b5[_0x15bc('0x26')]){delete _0x4026b5[_0x15bc('0x26')];}_0x263889[_0x15bc('0x18')](_0x7dc462)[_0x15bc('0x27')](_0x4026b5);};}exports[_0x15bc('0x28')]=function(_0x1ec291,_0x4773e8){var _0xb2d755={},_0x28d77d={},_0x3c6317={'count':0x0,'rows':[]};var _0x7a2dc7=_[_0x15bc('0x29')](db[_0x15bc('0x2a')][_0x15bc('0x2b')],function(_0x3fed13){return{'name':_0x3fed13[_0x15bc('0x2c')],'type':_0x3fed13['type'][_0x15bc('0x2d')]};});_0x28d77d[_0x15bc('0x2e')]=_[_0x15bc('0x29')](_0x7a2dc7,_0x15bc('0x26'));_0x28d77d[_0x15bc('0x2f')]=_[_0x15bc('0x30')](_0x1ec291[_0x15bc('0x2f')]);_0x28d77d[_0x15bc('0x31')]=_[_0x15bc('0x32')](_0x28d77d[_0x15bc('0x2e')],_0x28d77d['query']);_0xb2d755['attributes']=_[_0x15bc('0x32')](_0x28d77d['model'],qs[_0x15bc('0x33')](_0x1ec291[_0x15bc('0x2f')]['fields']));_0xb2d755[_0x15bc('0x34')]=_0xb2d755['attributes']['length']?_0xb2d755['attributes']:_0x28d77d['model'];if(!_0x1ec291[_0x15bc('0x2f')]['hasOwnProperty'](_0x15bc('0x35'))){_0xb2d755['limit']=qs[_0x15bc('0x1d')](_0x1ec291['query']['limit']);_0xb2d755['offset']=qs[_0x15bc('0x1b')](_0x1ec291['query']['offset']);}_0xb2d755['order']=qs[_0x15bc('0x36')](_0x1ec291[_0x15bc('0x2f')][_0x15bc('0x36')]);_0xb2d755[_0x15bc('0x37')]=qs['filters'](_['pick'](_0x1ec291[_0x15bc('0x2f')],_0x28d77d['filters']),_0x7a2dc7);if(_0x1ec291[_0x15bc('0x2f')][_0x15bc('0x38')]){_0xb2d755[_0x15bc('0x37')]=_[_0x15bc('0x39')](_0xb2d755[_0x15bc('0x37')],{'$or':_[_0x15bc('0x29')](_0x7a2dc7,function(_0x115cb4){if(_0x115cb4[_0x15bc('0x3a')]!=='VIRTUAL'){var _0x40445a={};_0x40445a[_0x115cb4[_0x15bc('0x26')]]={'$like':'%'+_0x1ec291['query'][_0x15bc('0x38')]+'%'};return _0x40445a;}})});}_0xb2d755=_[_0x15bc('0x39')]({},_0xb2d755,_0x1ec291['options']);var _0xd9b848={'where':_0xb2d755[_0x15bc('0x37')]};return db[_0x15bc('0x2a')]['count'](_0xd9b848)['then'](function(_0x224c11){_0x3c6317[_0x15bc('0x1e')]=_0x224c11;if(_0x1ec291[_0x15bc('0x2f')][_0x15bc('0x3b')]){_0xb2d755[_0x15bc('0x3c')]=[{'all':!![]}];}return db['MailSubstatus'][_0x15bc('0x3d')](_0xb2d755);})[_0x15bc('0x23')](function(_0x4989bc){_0x3c6317[_0x15bc('0x3e')]=_0x4989bc;return _0x3c6317;})[_0x15bc('0x23')](respondWithFilteredResult(_0x4773e8,_0xb2d755))[_0x15bc('0x3f')](handleError(_0x4773e8,null));};exports[_0x15bc('0x40')]=function(_0x333e0a,_0x213f19){var _0x17b485={'raw':!![],'where':{'id':_0x333e0a['params']['id']}},_0xa5046e={};_0xa5046e[_0x15bc('0x2e')]=_[_0x15bc('0x30')](db[_0x15bc('0x2a')][_0x15bc('0x2b')]);_0xa5046e[_0x15bc('0x2f')]=_[_0x15bc('0x30')](_0x333e0a[_0x15bc('0x2f')]);_0xa5046e['filters']=_[_0x15bc('0x32')](_0xa5046e[_0x15bc('0x2e')],_0xa5046e[_0x15bc('0x2f')]);_0x17b485[_0x15bc('0x34')]=_[_0x15bc('0x32')](_0xa5046e[_0x15bc('0x2e')],qs[_0x15bc('0x33')](_0x333e0a[_0x15bc('0x2f')]['fields']));_0x17b485['attributes']=_0x17b485[_0x15bc('0x34')]['length']?_0x17b485['attributes']:_0xa5046e[_0x15bc('0x2e')];if(_0x333e0a[_0x15bc('0x2f')][_0x15bc('0x3b')]){_0x17b485[_0x15bc('0x3c')]=[{'all':!![]}];}_0x17b485=_[_0x15bc('0x39')]({},_0x17b485,_0x333e0a[_0x15bc('0x41')]);return db['MailSubstatus'][_0x15bc('0x42')](_0x17b485)[_0x15bc('0x23')](handleEntityNotFound(_0x213f19,null))[_0x15bc('0x23')](respondWithResult(_0x213f19,null))[_0x15bc('0x3f')](handleError(_0x213f19,null));};exports[_0x15bc('0x43')]=function(_0x3a341d,_0x599866){return db[_0x15bc('0x2a')][_0x15bc('0x43')](_0x3a341d['body'],{})[_0x15bc('0x23')](respondWithResult(_0x599866,0xc9))[_0x15bc('0x3f')](handleError(_0x599866,null));};exports[_0x15bc('0x44')]=function(_0x207f6e,_0xe96c59){if(_0x207f6e[_0x15bc('0x45')]['id']){delete _0x207f6e[_0x15bc('0x45')]['id'];}return db[_0x15bc('0x2a')]['find']({'where':{'id':_0x207f6e['params']['id']}})[_0x15bc('0x23')](handleEntityNotFound(_0xe96c59,null))[_0x15bc('0x23')](saveUpdates(_0x207f6e['body'],null))[_0x15bc('0x23')](respondWithResult(_0xe96c59,null))[_0x15bc('0x3f')](handleError(_0xe96c59,null));};exports['destroy']=function(_0x3dfae8,_0xadeab3){return db[_0x15bc('0x2a')][_0x15bc('0x42')]({'where':{'id':_0x3dfae8[_0x15bc('0x46')]['id']}})[_0x15bc('0x23')](handleEntityNotFound(_0xadeab3,null))['then'](removeEntity(_0xadeab3,null))['catch'](handleError(_0xadeab3,null));};exports[_0x15bc('0x47')]=function(_0x2168fd,_0x4b6421){return db[_0x15bc('0x2a')][_0x15bc('0x47')]()[_0x15bc('0x23')](respondWithResult(_0x4b6421,null))[_0x15bc('0x3f')](handleError(_0x4b6421,null));};