abfe9b06f7757c42ad292f1d176ffcd2bc780311
[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 _0x6f7f=['findAll','rows','catch','params','keys','includeAll','find','create','body','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','fs-extra','squel','crypto','jsforce','desk.js','querystring','ioredis','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','offset','limit','undefined','count','set','Content-Range','json','apply','reject','update','then','destroy','end','error','stack','name','send','index','map','rawAttributes','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','MailSubstatus','include'];(function(_0x8f4554,_0x97e1f8){var _0x2b7465=function(_0x5d8390){while(--_0x5d8390){_0x8f4554['push'](_0x8f4554['shift']());}};_0x2b7465(++_0x97e1f8);}(_0x6f7f,0x177));var _0xf6f7=function(_0x957513,_0x3c3451){_0x957513=_0x957513-0x0;var _0x49b71f=_0x6f7f[_0x957513];return _0x49b71f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf6f7('0x0'));var zipdir=require(_0xf6f7('0x1'));var jsonpatch=require(_0xf6f7('0x2'));var rp=require(_0xf6f7('0x3'));var moment=require(_0xf6f7('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xf6f7('0x5'));var util=require('util');var path=require(_0xf6f7('0x6'));var sox=require(_0xf6f7('0x7'));var csv=require(_0xf6f7('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf6f7('0x9'));var _=require('lodash');var squel=require(_0xf6f7('0xa'));var crypto=require(_0xf6f7('0xb'));var jsforce=require(_0xf6f7('0xc'));var deskjs=require(_0xf6f7('0xd'));var toCsv=require(_0xf6f7('0x8'));var querystring=require(_0xf6f7('0xe'));var Papa=require('papaparse');var Redis=require(_0xf6f7('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf6f7('0x10'));var logger=require(_0xf6f7('0x11'))(_0xf6f7('0x12'));var utils=require(_0xf6f7('0x13'));var config=require(_0xf6f7('0x14'));var licenseUtil=require(_0xf6f7('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x47c447,_0x2493ec){_0x2493ec=_0x2493ec||0xcc;return function(_0x37f2ce){if(_0x37f2ce){return _0x47c447[_0xf6f7('0x16')](_0x2493ec);}return _0x47c447[_0xf6f7('0x17')](_0x2493ec)['end']();};}function respondWithResult(_0x568242,_0xc4fe52){_0xc4fe52=_0xc4fe52||0xc8;return function(_0x4f8d9b){if(_0x4f8d9b){return _0x568242[_0xf6f7('0x17')](_0xc4fe52)['json'](_0x4f8d9b);}};}function respondWithFilteredResult(_0x3f9293,_0x2ca201){return function(_0x35958e){if(_0x35958e){var _0x2758c0=typeof _0x2ca201[_0xf6f7('0x18')]==='undefined'&&typeof _0x2ca201[_0xf6f7('0x19')]===_0xf6f7('0x1a');var _0x566589=_0x35958e[_0xf6f7('0x1b')];var _0x438e3d=_0x2758c0?0x0:_0x2ca201[_0xf6f7('0x18')];var _0x5cc7a1=_0x2758c0?_0x35958e['count']:_0x2ca201[_0xf6f7('0x18')]+_0x2ca201[_0xf6f7('0x19')];var _0x512b07;if(_0x5cc7a1>=_0x566589){_0x5cc7a1=_0x566589;_0x512b07=0xc8;}else{_0x512b07=0xce;}_0x3f9293[_0xf6f7('0x17')](_0x512b07);return _0x3f9293[_0xf6f7('0x1c')](_0xf6f7('0x1d'),_0x438e3d+'-'+_0x5cc7a1+'/'+_0x566589)[_0xf6f7('0x1e')](_0x35958e);}return null;};}function patchUpdates(_0x3143d1){return function(_0x93bbfc){try{jsonpatch[_0xf6f7('0x1f')](_0x93bbfc,_0x3143d1,!![]);}catch(_0x564e5f){return BPromise[_0xf6f7('0x20')](_0x564e5f);}return _0x93bbfc['save']();};}function saveUpdates(_0x58ca0f,_0x66e5e4){return function(_0x532ee4){if(_0x532ee4){return _0x532ee4[_0xf6f7('0x21')](_0x58ca0f)[_0xf6f7('0x22')](function(_0x50b550){return _0x50b550;});}return null;};}function removeEntity(_0x3ce38d,_0x5ec44f){return function(_0x4c349d){if(_0x4c349d){return _0x4c349d[_0xf6f7('0x23')]()[_0xf6f7('0x22')](function(){_0x3ce38d[_0xf6f7('0x17')](0xcc)[_0xf6f7('0x24')]();});}};}function handleEntityNotFound(_0xa903ff,_0x5d3370){return function(_0x4c1ecd){if(!_0x4c1ecd){_0xa903ff[_0xf6f7('0x16')](0x194);}return _0x4c1ecd;};}function handleError(_0x2620a4,_0x277023){_0x277023=_0x277023||0x1f4;return function(_0x1de269){logger[_0xf6f7('0x25')](_0x1de269[_0xf6f7('0x26')]);if(_0x1de269['name']){delete _0x1de269[_0xf6f7('0x27')];}_0x2620a4[_0xf6f7('0x17')](_0x277023)[_0xf6f7('0x28')](_0x1de269);};}exports[_0xf6f7('0x29')]=function(_0x35a384,_0x3556e5){var _0x3be42f={},_0x4b3100={},_0x47f9ef={'count':0x0,'rows':[]};var _0x4bd86c=_[_0xf6f7('0x2a')](db['MailSubstatus'][_0xf6f7('0x2b')],function(_0x35b586){return{'name':_0x35b586['fieldName'],'type':_0x35b586['type'][_0xf6f7('0x2c')]};});_0x4b3100[_0xf6f7('0x2d')]=_[_0xf6f7('0x2a')](_0x4bd86c,'name');_0x4b3100[_0xf6f7('0x2e')]=_['keys'](_0x35a384[_0xf6f7('0x2e')]);_0x4b3100[_0xf6f7('0x2f')]=_[_0xf6f7('0x30')](_0x4b3100[_0xf6f7('0x2d')],_0x4b3100[_0xf6f7('0x2e')]);_0x3be42f[_0xf6f7('0x31')]=_[_0xf6f7('0x30')](_0x4b3100[_0xf6f7('0x2d')],qs[_0xf6f7('0x32')](_0x35a384[_0xf6f7('0x2e')][_0xf6f7('0x32')]));_0x3be42f[_0xf6f7('0x31')]=_0x3be42f['attributes'][_0xf6f7('0x33')]?_0x3be42f['attributes']:_0x4b3100[_0xf6f7('0x2d')];if(!_0x35a384[_0xf6f7('0x2e')][_0xf6f7('0x34')](_0xf6f7('0x35'))){_0x3be42f[_0xf6f7('0x19')]=qs[_0xf6f7('0x19')](_0x35a384[_0xf6f7('0x2e')][_0xf6f7('0x19')]);_0x3be42f[_0xf6f7('0x18')]=qs['offset'](_0x35a384['query'][_0xf6f7('0x18')]);}_0x3be42f[_0xf6f7('0x36')]=qs[_0xf6f7('0x37')](_0x35a384[_0xf6f7('0x2e')][_0xf6f7('0x37')]);_0x3be42f[_0xf6f7('0x38')]=qs[_0xf6f7('0x2f')](_[_0xf6f7('0x39')](_0x35a384[_0xf6f7('0x2e')],_0x4b3100[_0xf6f7('0x2f')]),_0x4bd86c);if(_0x35a384[_0xf6f7('0x2e')][_0xf6f7('0x3a')]){_0x3be42f[_0xf6f7('0x38')]=_[_0xf6f7('0x3b')](_0x3be42f[_0xf6f7('0x38')],{'$or':_[_0xf6f7('0x2a')](_0x4bd86c,function(_0x4cd474){if(_0x4cd474['type']!==_0xf6f7('0x3c')){var _0x1de44f={};_0x1de44f[_0x4cd474[_0xf6f7('0x27')]]={'$like':'%'+_0x35a384[_0xf6f7('0x2e')][_0xf6f7('0x3a')]+'%'};return _0x1de44f;}})});}_0x3be42f=_[_0xf6f7('0x3b')]({},_0x3be42f,_0x35a384['options']);var _0x309002={'where':_0x3be42f[_0xf6f7('0x38')]};return db[_0xf6f7('0x3d')][_0xf6f7('0x1b')](_0x309002)['then'](function(_0x489c39){_0x47f9ef[_0xf6f7('0x1b')]=_0x489c39;if(_0x35a384['query']['includeAll']){_0x3be42f[_0xf6f7('0x3e')]=[{'all':!![]}];}return db[_0xf6f7('0x3d')][_0xf6f7('0x3f')](_0x3be42f);})['then'](function(_0x1ecb03){_0x47f9ef[_0xf6f7('0x40')]=_0x1ecb03;return _0x47f9ef;})[_0xf6f7('0x22')](respondWithFilteredResult(_0x3556e5,_0x3be42f))[_0xf6f7('0x41')](handleError(_0x3556e5,null));};exports['show']=function(_0x50738f,_0x44c326){var _0x49bfca={'raw':!![],'where':{'id':_0x50738f[_0xf6f7('0x42')]['id']}},_0x4788f0={};_0x4788f0['model']=_[_0xf6f7('0x43')](db['MailSubstatus']['rawAttributes']);_0x4788f0['query']=_[_0xf6f7('0x43')](_0x50738f[_0xf6f7('0x2e')]);_0x4788f0[_0xf6f7('0x2f')]=_[_0xf6f7('0x30')](_0x4788f0['model'],_0x4788f0[_0xf6f7('0x2e')]);_0x49bfca['attributes']=_[_0xf6f7('0x30')](_0x4788f0['model'],qs['fields'](_0x50738f[_0xf6f7('0x2e')][_0xf6f7('0x32')]));_0x49bfca[_0xf6f7('0x31')]=_0x49bfca['attributes'][_0xf6f7('0x33')]?_0x49bfca[_0xf6f7('0x31')]:_0x4788f0['model'];if(_0x50738f['query'][_0xf6f7('0x44')]){_0x49bfca['include']=[{'all':!![]}];}_0x49bfca=_[_0xf6f7('0x3b')]({},_0x49bfca,_0x50738f['options']);return db['MailSubstatus'][_0xf6f7('0x45')](_0x49bfca)['then'](handleEntityNotFound(_0x44c326,null))[_0xf6f7('0x22')](respondWithResult(_0x44c326,null))['catch'](handleError(_0x44c326,null));};exports[_0xf6f7('0x46')]=function(_0x4b55d2,_0x4afd83){return db[_0xf6f7('0x3d')][_0xf6f7('0x46')](_0x4b55d2[_0xf6f7('0x47')],{})[_0xf6f7('0x22')](respondWithResult(_0x4afd83,0xc9))[_0xf6f7('0x41')](handleError(_0x4afd83,null));};exports[_0xf6f7('0x21')]=function(_0x1d944a,_0xa5a85){if(_0x1d944a[_0xf6f7('0x47')]['id']){delete _0x1d944a[_0xf6f7('0x47')]['id'];}return db[_0xf6f7('0x3d')][_0xf6f7('0x45')]({'where':{'id':_0x1d944a['params']['id']}})[_0xf6f7('0x22')](handleEntityNotFound(_0xa5a85,null))['then'](saveUpdates(_0x1d944a[_0xf6f7('0x47')],null))[_0xf6f7('0x22')](respondWithResult(_0xa5a85,null))[_0xf6f7('0x41')](handleError(_0xa5a85,null));};exports['destroy']=function(_0x142cb4,_0x1cc654){return db[_0xf6f7('0x3d')][_0xf6f7('0x45')]({'where':{'id':_0x142cb4[_0xf6f7('0x42')]['id']}})['then'](handleEntityNotFound(_0x1cc654,null))[_0xf6f7('0x22')](removeEntity(_0x1cc654,null))['catch'](handleError(_0x1cc654,null));};exports[_0xf6f7('0x48')]=function(_0x1bfc9a,_0x39df53){return db['MailSubstatus']['describe']()[_0xf6f7('0x22')](respondWithResult(_0x39df53,null))[_0xf6f7('0x41')](handleError(_0x39df53,null));};