Built motion from commit 598073ad.|2.5.44
[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 _0x32f4=['Content-Range','json','apply','reject','save','update','then','destroy','end','error','stack','name','send','index','map','MailSubstatus','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','limit','order','sort','pick','where','merge','type','VIRTUAL','filter','options','includeAll','include','findAll','rows','params','length','find','catch','create','body','eml-format','rimraf','fast-json-patch','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','crypto','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','undefined','count','offset'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x32f4,0x158));var _0x432f=function(_0x4db474,_0x2e74de){_0x4db474=_0x4db474-0x0;var _0x22520=_0x32f4[_0x4db474];return _0x22520;};'use strict';var emlformat=require(_0x432f('0x0'));var rimraf=require(_0x432f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x432f('0x2'));var rp=require('request-promise');var moment=require(_0x432f('0x3'));var BPromise=require(_0x432f('0x4'));var Mustache=require('mustache');var util=require(_0x432f('0x5'));var path=require(_0x432f('0x6'));var sox=require('sox');var csv=require(_0x432f('0x7'));var ejs=require(_0x432f('0x8'));var fs=require('fs');var fs_extra=require(_0x432f('0x9'));var _=require(_0x432f('0xa'));var squel=require('squel');var crypto=require(_0x432f('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x432f('0xc'));var toCsv=require(_0x432f('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x432f('0xd'));var qs=require(_0x432f('0xe'));var as=require(_0x432f('0xf'));var hardwareService=require(_0x432f('0x10'));var logger=require(_0x432f('0x11'))('api');var utils=require(_0x432f('0x12'));var config=require(_0x432f('0x13'));var licenseUtil=require('../../config/license/util');var db=require(_0x432f('0x14'))['db'];function respondWithStatusCode(_0x58a904,_0x53612e){_0x53612e=_0x53612e||0xcc;return function(_0x2ede8e){if(_0x2ede8e){return _0x58a904[_0x432f('0x15')](_0x53612e);}return _0x58a904[_0x432f('0x16')](_0x53612e)['end']();};}function respondWithResult(_0x4bb271,_0x39d1e4){_0x39d1e4=_0x39d1e4||0xc8;return function(_0x10418e){if(_0x10418e){return _0x4bb271[_0x432f('0x16')](_0x39d1e4)['json'](_0x10418e);}};}function respondWithFilteredResult(_0x40b1ce,_0x5d4abd){return function(_0x331a22){if(_0x331a22){var _0x804151=typeof _0x5d4abd['offset']===_0x432f('0x17')&&typeof _0x5d4abd['limit']==='undefined';var _0x504c6b=_0x331a22[_0x432f('0x18')];var _0xda18bb=_0x804151?0x0:_0x5d4abd[_0x432f('0x19')];var _0x2b28cd=_0x804151?_0x331a22['count']:_0x5d4abd[_0x432f('0x19')]+_0x5d4abd['limit'];var _0xe3adab;if(_0x2b28cd>=_0x504c6b){_0x2b28cd=_0x504c6b;_0xe3adab=0xc8;}else{_0xe3adab=0xce;}_0x40b1ce['status'](_0xe3adab);return _0x40b1ce['set'](_0x432f('0x1a'),_0xda18bb+'-'+_0x2b28cd+'/'+_0x504c6b)[_0x432f('0x1b')](_0x331a22);}return null;};}function patchUpdates(_0x4728f1){return function(_0x11f8eb){try{jsonpatch[_0x432f('0x1c')](_0x11f8eb,_0x4728f1,!![]);}catch(_0x2081e0){return BPromise[_0x432f('0x1d')](_0x2081e0);}return _0x11f8eb[_0x432f('0x1e')]();};}function saveUpdates(_0x218fb9,_0x34672a){return function(_0x373e73){if(_0x373e73){return _0x373e73[_0x432f('0x1f')](_0x218fb9)[_0x432f('0x20')](function(_0x36be35){return _0x36be35;});}return null;};}function removeEntity(_0x3d5373,_0x2dcc4d){return function(_0x580c0b){if(_0x580c0b){return _0x580c0b[_0x432f('0x21')]()[_0x432f('0x20')](function(){_0x3d5373[_0x432f('0x16')](0xcc)[_0x432f('0x22')]();});}};}function handleEntityNotFound(_0x45f274,_0x48063d){return function(_0x2927e6){if(!_0x2927e6){_0x45f274[_0x432f('0x15')](0x194);}return _0x2927e6;};}function handleError(_0x93607e,_0x48c2b6){_0x48c2b6=_0x48c2b6||0x1f4;return function(_0x1daf38){logger[_0x432f('0x23')](_0x1daf38[_0x432f('0x24')]);if(_0x1daf38['name']){delete _0x1daf38[_0x432f('0x25')];}_0x93607e[_0x432f('0x16')](_0x48c2b6)[_0x432f('0x26')](_0x1daf38);};}exports[_0x432f('0x27')]=function(_0x3071c9,_0x2bdaa3){var _0x5dfa8c={},_0x474047={},_0x149dc6={'count':0x0,'rows':[]};var _0x31e1e4=_[_0x432f('0x28')](db[_0x432f('0x29')][_0x432f('0x2a')],function(_0xa8d507){return{'name':_0xa8d507[_0x432f('0x2b')],'type':_0xa8d507['type'][_0x432f('0x2c')]};});_0x474047[_0x432f('0x2d')]=_[_0x432f('0x28')](_0x31e1e4,_0x432f('0x25'));_0x474047['query']=_[_0x432f('0x2e')](_0x3071c9[_0x432f('0x2f')]);_0x474047[_0x432f('0x30')]=_[_0x432f('0x31')](_0x474047['model'],_0x474047[_0x432f('0x2f')]);_0x5dfa8c[_0x432f('0x32')]=_[_0x432f('0x31')](_0x474047['model'],qs[_0x432f('0x33')](_0x3071c9[_0x432f('0x2f')]['fields']));_0x5dfa8c[_0x432f('0x32')]=_0x5dfa8c[_0x432f('0x32')]['length']?_0x5dfa8c[_0x432f('0x32')]:_0x474047[_0x432f('0x2d')];if(!_0x3071c9[_0x432f('0x2f')][_0x432f('0x34')](_0x432f('0x35'))){_0x5dfa8c[_0x432f('0x36')]=qs[_0x432f('0x36')](_0x3071c9['query']['limit']);_0x5dfa8c[_0x432f('0x19')]=qs['offset'](_0x3071c9[_0x432f('0x2f')][_0x432f('0x19')]);}_0x5dfa8c[_0x432f('0x37')]=qs[_0x432f('0x38')](_0x3071c9['query'][_0x432f('0x38')]);_0x5dfa8c['where']=qs[_0x432f('0x30')](_[_0x432f('0x39')](_0x3071c9[_0x432f('0x2f')],_0x474047[_0x432f('0x30')]),_0x31e1e4);if(_0x3071c9[_0x432f('0x2f')]['filter']){_0x5dfa8c[_0x432f('0x3a')]=_[_0x432f('0x3b')](_0x5dfa8c[_0x432f('0x3a')],{'$or':_['map'](_0x31e1e4,function(_0x28ee2e){if(_0x28ee2e[_0x432f('0x3c')]!==_0x432f('0x3d')){var _0x17ad59={};_0x17ad59[_0x28ee2e[_0x432f('0x25')]]={'$like':'%'+_0x3071c9[_0x432f('0x2f')][_0x432f('0x3e')]+'%'};return _0x17ad59;}})});}_0x5dfa8c=_[_0x432f('0x3b')]({},_0x5dfa8c,_0x3071c9[_0x432f('0x3f')]);var _0x3b81f3={'where':_0x5dfa8c[_0x432f('0x3a')]};return db[_0x432f('0x29')][_0x432f('0x18')](_0x3b81f3)[_0x432f('0x20')](function(_0xdaa7af){_0x149dc6[_0x432f('0x18')]=_0xdaa7af;if(_0x3071c9[_0x432f('0x2f')][_0x432f('0x40')]){_0x5dfa8c[_0x432f('0x41')]=[{'all':!![]}];}return db[_0x432f('0x29')][_0x432f('0x42')](_0x5dfa8c);})[_0x432f('0x20')](function(_0x53cd41){_0x149dc6[_0x432f('0x43')]=_0x53cd41;return _0x149dc6;})[_0x432f('0x20')](respondWithFilteredResult(_0x2bdaa3,_0x5dfa8c))['catch'](handleError(_0x2bdaa3,null));};exports['show']=function(_0x4af547,_0x1a4cf3){var _0x1887cb={'raw':!![],'where':{'id':_0x4af547[_0x432f('0x44')]['id']}},_0x2a0bcd={};_0x2a0bcd['model']=_['keys'](db['MailSubstatus'][_0x432f('0x2a')]);_0x2a0bcd[_0x432f('0x2f')]=_[_0x432f('0x2e')](_0x4af547[_0x432f('0x2f')]);_0x2a0bcd['filters']=_[_0x432f('0x31')](_0x2a0bcd[_0x432f('0x2d')],_0x2a0bcd[_0x432f('0x2f')]);_0x1887cb[_0x432f('0x32')]=_[_0x432f('0x31')](_0x2a0bcd[_0x432f('0x2d')],qs['fields'](_0x4af547[_0x432f('0x2f')][_0x432f('0x33')]));_0x1887cb[_0x432f('0x32')]=_0x1887cb[_0x432f('0x32')][_0x432f('0x45')]?_0x1887cb[_0x432f('0x32')]:_0x2a0bcd['model'];if(_0x4af547['query'][_0x432f('0x40')]){_0x1887cb['include']=[{'all':!![]}];}_0x1887cb=_[_0x432f('0x3b')]({},_0x1887cb,_0x4af547[_0x432f('0x3f')]);return db[_0x432f('0x29')][_0x432f('0x46')](_0x1887cb)['then'](handleEntityNotFound(_0x1a4cf3,null))[_0x432f('0x20')](respondWithResult(_0x1a4cf3,null))[_0x432f('0x47')](handleError(_0x1a4cf3,null));};exports[_0x432f('0x48')]=function(_0x36d433,_0xda65b8){return db[_0x432f('0x29')][_0x432f('0x48')](_0x36d433[_0x432f('0x49')],{})[_0x432f('0x20')](respondWithResult(_0xda65b8,0xc9))['catch'](handleError(_0xda65b8,null));};exports[_0x432f('0x1f')]=function(_0x1b3fe8,_0x5b16a8){if(_0x1b3fe8[_0x432f('0x49')]['id']){delete _0x1b3fe8[_0x432f('0x49')]['id'];}return db['MailSubstatus'][_0x432f('0x46')]({'where':{'id':_0x1b3fe8[_0x432f('0x44')]['id']}})[_0x432f('0x20')](handleEntityNotFound(_0x5b16a8,null))[_0x432f('0x20')](saveUpdates(_0x1b3fe8['body'],null))[_0x432f('0x20')](respondWithResult(_0x5b16a8,null))[_0x432f('0x47')](handleError(_0x5b16a8,null));};exports[_0x432f('0x21')]=function(_0x531cc5,_0x193fe1){return db[_0x432f('0x29')][_0x432f('0x46')]({'where':{'id':_0x531cc5['params']['id']}})[_0x432f('0x20')](handleEntityNotFound(_0x193fe1,null))[_0x432f('0x20')](removeEntity(_0x193fe1,null))[_0x432f('0x47')](handleError(_0x193fe1,null));};exports['describe']=function(_0x1eb17f,_0x482d1f){return db[_0x432f('0x29')]['describe']()[_0x432f('0x20')](respondWithResult(_0x482d1f,null))[_0x432f('0x47')](handleError(_0x482d1f,null));};