Built motion from commit (unavailable).|2.2.1
[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 _0x5f2f=['Content-Range','apply','reject','save','destroy','then','stack','name','send','index','MailSubstatus','rawAttributes','model','keys','dateStart','query','dateEnd','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','day','add','merge','map','type','key','field','filter','options','includeAll','catch','show','params','intersection','body','find','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','api','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set'];(function(_0x5bd4f6,_0xf4e45c){var _0x33a165=function(_0x37eef6){while(--_0x37eef6){_0x5bd4f6['push'](_0x5bd4f6['shift']());}};_0x33a165(++_0xf4e45c);}(_0x5f2f,0x73));var _0xf5f2=function(_0x22d125,_0x299908){_0x22d125=_0x22d125-0x0;var _0x1fd4f9=_0x5f2f[_0x22d125];return _0x1fd4f9;};'use strict';var pdf=require(_0xf5f2('0x0'));var emlformat=require(_0xf5f2('0x1'));var rimraf=require(_0xf5f2('0x2'));var zipdir=require(_0xf5f2('0x3'));var jsonpatch=require(_0xf5f2('0x4'));var rp=require(_0xf5f2('0x5'));var moment=require(_0xf5f2('0x6'));var BPromise=require(_0xf5f2('0x7'));var Mustache=require('mustache');var util=require('util');var path=require(_0xf5f2('0x8'));var sox=require(_0xf5f2('0x9'));var csv=require(_0xf5f2('0xa'));var ejs=require(_0xf5f2('0xb'));var fs=require('fs');var _=require(_0xf5f2('0xc'));var squel=require(_0xf5f2('0xd'));var crypto=require('crypto');var jsforce=require(_0xf5f2('0xe'));var deskjs=require(_0xf5f2('0xf'));var toCsv=require(_0xf5f2('0xa'));var querystring=require('querystring');var Papa=require(_0xf5f2('0x10'));var Redis=require(_0xf5f2('0x11'));var qs=require(_0xf5f2('0x12'));var logger=require('../../config/logger')(_0xf5f2('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0xf5f2('0x14'))['db'];function respondWithStatusCode(_0x151aba,_0x4b78cd){_0x4b78cd=_0x4b78cd||0xcc;return function(_0x336f6b){if(_0x336f6b){return _0x151aba[_0xf5f2('0x15')](_0x4b78cd);}return _0x151aba[_0xf5f2('0x16')](_0x4b78cd)[_0xf5f2('0x17')]();};}function respondWithResult(_0x59bb6c,_0x3e5956){_0x3e5956=_0x3e5956||0xc8;return function(_0x5c01b8){if(_0x5c01b8){return _0x59bb6c[_0xf5f2('0x16')](_0x3e5956)[_0xf5f2('0x18')](_0x5c01b8);}};}function respondWithFilteredResult(_0x269909,_0x1c1a5c){return function(_0x422b55){if(_0x422b55){var _0x4d97fc=_0x422b55[_0xf5f2('0x19')],_0xafe430=_0x1c1a5c[_0xf5f2('0x1a')],_0x286197=_0x1c1a5c[_0xf5f2('0x1a')]+_0x1c1a5c[_0xf5f2('0x1b')],_0x17d656;if(_0x286197>=_0x4d97fc){_0x286197=_0x4d97fc;_0x17d656=0xc8;}else{_0x17d656=0xce;}_0x269909[_0xf5f2('0x16')](_0x17d656);return _0x269909[_0xf5f2('0x1c')](_0xf5f2('0x1d'),_0xafe430+'-'+_0x286197+'/'+_0x4d97fc)[_0xf5f2('0x18')](_0x422b55);}return null;};}function patchUpdates(_0x28e097){return function(_0x4ff59b){try{jsonpatch[_0xf5f2('0x1e')](_0x4ff59b,_0x28e097,!![]);}catch(_0x3cf5ea){return BPromise[_0xf5f2('0x1f')](_0x3cf5ea);}return _0x4ff59b[_0xf5f2('0x20')]();};}function saveUpdates(_0x56acc5,_0x34706d){return function(_0x47101e){if(_0x47101e){return _0x47101e['update'](_0x56acc5)['then'](function(_0x2d2805){return _0x2d2805;});}return null;};}function removeEntity(_0x388e6c,_0x4ae323){return function(_0x45b74f){if(_0x45b74f){return _0x45b74f[_0xf5f2('0x21')]()[_0xf5f2('0x22')](function(){_0x388e6c[_0xf5f2('0x16')](0xcc)[_0xf5f2('0x17')]();});}};}function handleEntityNotFound(_0x4c691a,_0x21cd91){return function(_0x4669a6){if(!_0x4669a6){_0x4c691a[_0xf5f2('0x15')](0x194);}return _0x4669a6;};}function handleError(_0x2833fe,_0x287ad5){_0x287ad5=_0x287ad5||0x1f4;return function(_0x5bdf4a){logger['error'](_0x5bdf4a[_0xf5f2('0x23')]);if(_0x5bdf4a[_0xf5f2('0x24')]){delete _0x5bdf4a[_0xf5f2('0x24')];}_0x2833fe[_0xf5f2('0x16')](_0x287ad5)[_0xf5f2('0x25')](_0x5bdf4a);};}exports[_0xf5f2('0x26')]=function(_0x13a3be,_0x281ec8){var _0x294414={},_0x4ab014={},_0xaa2602={'count':0x0,'rows':[]};var _0x102449=db[_0xf5f2('0x27')][_0xf5f2('0x28')];_0x4ab014[_0xf5f2('0x29')]=_[_0xf5f2('0x2a')](_0x102449);var _0x5b6672={'dateStart':_0x13a3be['query'][_0xf5f2('0x2b')],'dateEnd':_0x13a3be[_0xf5f2('0x2c')][_0xf5f2('0x2d')]};delete _0x13a3be['query']['dateStart'];delete _0x13a3be[_0xf5f2('0x2c')][_0xf5f2('0x2d')];_0x4ab014[_0xf5f2('0x2c')]=_[_0xf5f2('0x2a')](_0x13a3be[_0xf5f2('0x2c')]);_0x4ab014['filters']=_['intersection'](_0x4ab014[_0xf5f2('0x29')],_0x4ab014['query']);_0x294414[_0xf5f2('0x2e')]=_['intersection'](_0x4ab014[_0xf5f2('0x29')],qs[_0xf5f2('0x2f')](_0x13a3be[_0xf5f2('0x2c')][_0xf5f2('0x2f')]));_0x294414[_0xf5f2('0x2e')]=_0x294414[_0xf5f2('0x2e')][_0xf5f2('0x30')]?_0x294414[_0xf5f2('0x2e')]:_0x4ab014['model'];if(!_0x13a3be[_0xf5f2('0x2c')][_0xf5f2('0x31')](_0xf5f2('0x32'))){_0x294414[_0xf5f2('0x1b')]=qs[_0xf5f2('0x1b')](_0x13a3be[_0xf5f2('0x2c')][_0xf5f2('0x1b')]);_0x294414['offset']=qs[_0xf5f2('0x1a')](_0x13a3be[_0xf5f2('0x2c')]['offset']);}_0x294414[_0xf5f2('0x33')]=qs['sort'](_0x13a3be[_0xf5f2('0x2c')][_0xf5f2('0x34')]);_0x294414[_0xf5f2('0x35')]=qs[_0xf5f2('0x36')](_['pick'](_0x13a3be['query'],_0x4ab014[_0xf5f2('0x36')]));if(_0x5b6672[_0xf5f2('0x2b')]){if(_0x5b6672[_0xf5f2('0x2d')]){_0x5b6672['dateEnd']=moment(_0x5b6672[_0xf5f2('0x2d')])['add'](0x1,_0xf5f2('0x37'));}else{_0x5b6672['dateEnd']=moment(_0x5b6672[_0xf5f2('0x2b')])[_0xf5f2('0x38')](0x1,'day');}_[_0xf5f2('0x39')](_0x294414[_0xf5f2('0x35')],{'createdAt':{'$gte':_0x5b6672[_0xf5f2('0x2b')],'$lte':_0x5b6672[_0xf5f2('0x2d')]}});}if(_0x13a3be['query']['filter']){_0x294414[_0xf5f2('0x35')]=_[_0xf5f2('0x39')](_0x294414[_0xf5f2('0x35')],{'$or':_[_0xf5f2('0x3a')](_0x102449,function(_0x2c7f65){if(_0x2c7f65[_0xf5f2('0x3b')][_0xf5f2('0x3c')]!=='VIRTUAL'){var _0x110fe5={};_0x110fe5[_0x2c7f65[_0xf5f2('0x3d')]]={'$like':'%'+_0x13a3be['query'][_0xf5f2('0x3e')]+'%'};return _0x110fe5;}})});}_0x294414=_[_0xf5f2('0x39')]({},_0x294414,_0x13a3be[_0xf5f2('0x3f')]);var _0x85b6d0={'where':_0x294414[_0xf5f2('0x35')]};return db[_0xf5f2('0x27')][_0xf5f2('0x19')](_0x85b6d0)[_0xf5f2('0x22')](function(_0x574f24){_0xaa2602[_0xf5f2('0x19')]=_0x574f24;if(_0x13a3be[_0xf5f2('0x2c')][_0xf5f2('0x40')]){_0x294414['include']=[{'all':!![]}];}return db['MailSubstatus']['findAll'](_0x294414);})[_0xf5f2('0x22')](function(_0x2ad13c){_0xaa2602['rows']=_0x2ad13c;return _0xaa2602;})[_0xf5f2('0x22')](respondWithFilteredResult(_0x281ec8,_0x294414))[_0xf5f2('0x41')](handleError(_0x281ec8,null));};exports[_0xf5f2('0x42')]=function(_0x31f86c,_0x354c34){var _0x2b3b1c={'raw':!![],'where':{'id':_0x31f86c[_0xf5f2('0x43')]['id']}},_0x1a6ec1={};_0x1a6ec1[_0xf5f2('0x29')]=_[_0xf5f2('0x2a')](db[_0xf5f2('0x27')][_0xf5f2('0x28')]);_0x1a6ec1[_0xf5f2('0x2c')]=_[_0xf5f2('0x2a')](_0x31f86c['query']);_0x1a6ec1[_0xf5f2('0x36')]=_['intersection'](_0x1a6ec1[_0xf5f2('0x29')],_0x1a6ec1[_0xf5f2('0x2c')]);_0x2b3b1c[_0xf5f2('0x2e')]=_[_0xf5f2('0x44')](_0x1a6ec1[_0xf5f2('0x29')],qs[_0xf5f2('0x2f')](_0x31f86c['query'][_0xf5f2('0x2f')]));_0x2b3b1c[_0xf5f2('0x2e')]=_0x2b3b1c[_0xf5f2('0x2e')][_0xf5f2('0x30')]?_0x2b3b1c[_0xf5f2('0x2e')]:_0x1a6ec1[_0xf5f2('0x29')];if(_0x31f86c[_0xf5f2('0x2c')][_0xf5f2('0x40')]){_0x2b3b1c['include']=[{'all':!![]}];}_0x2b3b1c=_[_0xf5f2('0x39')]({},_0x2b3b1c,_0x31f86c[_0xf5f2('0x3f')]);return db[_0xf5f2('0x27')]['find'](_0x2b3b1c)[_0xf5f2('0x22')](handleEntityNotFound(_0x354c34,null))[_0xf5f2('0x22')](respondWithResult(_0x354c34,null))[_0xf5f2('0x41')](handleError(_0x354c34,null));};exports['create']=function(_0x57a7cb,_0x7bb942){return db[_0xf5f2('0x27')]['create'](_0x57a7cb[_0xf5f2('0x45')],{})['then'](respondWithResult(_0x7bb942,0xc9))[_0xf5f2('0x41')](handleError(_0x7bb942,null));};exports['update']=function(_0x2cbd9d,_0x5d9120){if(_0x2cbd9d[_0xf5f2('0x45')]['id']){delete _0x2cbd9d[_0xf5f2('0x45')]['id'];}return db[_0xf5f2('0x27')][_0xf5f2('0x46')]({'where':{'id':_0x2cbd9d['params']['id']}})[_0xf5f2('0x22')](handleEntityNotFound(_0x5d9120,null))[_0xf5f2('0x22')](saveUpdates(_0x2cbd9d['body'],null))['then'](respondWithResult(_0x5d9120,null))[_0xf5f2('0x41')](handleError(_0x5d9120,null));};exports[_0xf5f2('0x21')]=function(_0x57782c,_0x22b645){return db[_0xf5f2('0x27')][_0xf5f2('0x46')]({'where':{'id':_0x57782c[_0xf5f2('0x43')]['id']}})['then'](handleEntityNotFound(_0x22b645,null))['then'](removeEntity(_0x22b645,null))[_0xf5f2('0x41')](handleError(_0x22b645,null));};exports[_0xf5f2('0x47')]=function(_0x4b62fc,_0x40eef){return db[_0xf5f2('0x27')][_0xf5f2('0x47')]()[_0xf5f2('0x22')](respondWithResult(_0x40eef,null))[_0xf5f2('0x41')](handleError(_0x40eef,null));};