4310072421bdc7ce321d1d839e1c931591230000
[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 _0x89f0=['util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','status','end','json','offset','undefined','count','set','apply','save','update','then','destroy','stack','name','send','index','map','MailSubstatus','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','limit','order','pick','filter','where','merge','includeAll','include','findAll','show','params','options','find','catch','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird'];(function(_0x381379,_0x3f3b86){var _0x3e1063=function(_0x4c282d){while(--_0x4c282d){_0x381379['push'](_0x381379['shift']());}};_0x3e1063(++_0x3f3b86);}(_0x89f0,0x1af));var _0x089f=function(_0x5970d7,_0x1d87a0){_0x5970d7=_0x5970d7-0x0;var _0x53691e=_0x89f0[_0x5970d7];return _0x53691e;};'use strict';var emlformat=require(_0x089f('0x0'));var rimraf=require(_0x089f('0x1'));var zipdir=require(_0x089f('0x2'));var jsonpatch=require(_0x089f('0x3'));var rp=require(_0x089f('0x4'));var moment=require(_0x089f('0x5'));var BPromise=require(_0x089f('0x6'));var Mustache=require('mustache');var util=require(_0x089f('0x7'));var path=require(_0x089f('0x8'));var sox=require(_0x089f('0x9'));var csv=require(_0x089f('0xa'));var ejs=require(_0x089f('0xb'));var fs=require('fs');var fs_extra=require(_0x089f('0xc'));var _=require(_0x089f('0xd'));var squel=require(_0x089f('0xe'));var crypto=require(_0x089f('0xf'));var jsforce=require(_0x089f('0x10'));var deskjs=require('desk.js');var toCsv=require(_0x089f('0xa'));var querystring=require(_0x089f('0x11'));var Papa=require('papaparse');var Redis=require(_0x089f('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x089f('0x13'));var hardwareService=require(_0x089f('0x14'));var logger=require(_0x089f('0x15'))(_0x089f('0x16'));var utils=require('../../config/utils');var config=require(_0x089f('0x17'));var licenseUtil=require(_0x089f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x9b52c0,_0x1ca921){_0x1ca921=_0x1ca921||0xcc;return function(_0x2fe961){if(_0x2fe961){return _0x9b52c0['sendStatus'](_0x1ca921);}return _0x9b52c0[_0x089f('0x19')](_0x1ca921)[_0x089f('0x1a')]();};}function respondWithResult(_0x1f8d8c,_0x51dce5){_0x51dce5=_0x51dce5||0xc8;return function(_0x1026ee){if(_0x1026ee){return _0x1f8d8c[_0x089f('0x19')](_0x51dce5)[_0x089f('0x1b')](_0x1026ee);}};}function respondWithFilteredResult(_0x4a062c,_0x2ec329){return function(_0x1ad76e){if(_0x1ad76e){var _0x1e1115=typeof _0x2ec329[_0x089f('0x1c')]===_0x089f('0x1d')&&typeof _0x2ec329['limit']==='undefined';var _0x19a08d=_0x1ad76e[_0x089f('0x1e')];var _0x1c9369=_0x1e1115?0x0:_0x2ec329['offset'];var _0x162984=_0x1e1115?_0x1ad76e[_0x089f('0x1e')]:_0x2ec329[_0x089f('0x1c')]+_0x2ec329['limit'];var _0x48e917;if(_0x162984>=_0x19a08d){_0x162984=_0x19a08d;_0x48e917=0xc8;}else{_0x48e917=0xce;}_0x4a062c[_0x089f('0x19')](_0x48e917);return _0x4a062c[_0x089f('0x1f')]('Content-Range',_0x1c9369+'-'+_0x162984+'/'+_0x19a08d)[_0x089f('0x1b')](_0x1ad76e);}return null;};}function patchUpdates(_0x949a80){return function(_0x58c42a){try{jsonpatch[_0x089f('0x20')](_0x58c42a,_0x949a80,!![]);}catch(_0x57113c){return BPromise['reject'](_0x57113c);}return _0x58c42a[_0x089f('0x21')]();};}function saveUpdates(_0x20422a,_0x25a694){return function(_0x33eb90){if(_0x33eb90){return _0x33eb90[_0x089f('0x22')](_0x20422a)[_0x089f('0x23')](function(_0x232fdf){return _0x232fdf;});}return null;};}function removeEntity(_0x28bb2a,_0x136506){return function(_0x3318f8){if(_0x3318f8){return _0x3318f8[_0x089f('0x24')]()[_0x089f('0x23')](function(){_0x28bb2a[_0x089f('0x19')](0xcc)[_0x089f('0x1a')]();});}};}function handleEntityNotFound(_0x17c70b,_0xf298c7){return function(_0xc51950){if(!_0xc51950){_0x17c70b['sendStatus'](0x194);}return _0xc51950;};}function handleError(_0x17cd59,_0x443362){_0x443362=_0x443362||0x1f4;return function(_0x435187){logger['error'](_0x435187[_0x089f('0x25')]);if(_0x435187[_0x089f('0x26')]){delete _0x435187[_0x089f('0x26')];}_0x17cd59[_0x089f('0x19')](_0x443362)[_0x089f('0x27')](_0x435187);};}exports[_0x089f('0x28')]=function(_0x5eb8fd,_0x3cfe8f){var _0x58d644={},_0x2978f4={},_0x488c7d={'count':0x0,'rows':[]};var _0x480043=_[_0x089f('0x29')](db[_0x089f('0x2a')][_0x089f('0x2b')],function(_0x92b166){return{'name':_0x92b166[_0x089f('0x2c')],'type':_0x92b166[_0x089f('0x2d')][_0x089f('0x2e')]};});_0x2978f4[_0x089f('0x2f')]=_[_0x089f('0x29')](_0x480043,'name');_0x2978f4['query']=_[_0x089f('0x30')](_0x5eb8fd[_0x089f('0x31')]);_0x2978f4[_0x089f('0x32')]=_['intersection'](_0x2978f4[_0x089f('0x2f')],_0x2978f4['query']);_0x58d644[_0x089f('0x33')]=_[_0x089f('0x34')](_0x2978f4[_0x089f('0x2f')],qs[_0x089f('0x35')](_0x5eb8fd[_0x089f('0x31')][_0x089f('0x35')]));_0x58d644[_0x089f('0x33')]=_0x58d644[_0x089f('0x33')][_0x089f('0x36')]?_0x58d644[_0x089f('0x33')]:_0x2978f4[_0x089f('0x2f')];if(!_0x5eb8fd[_0x089f('0x31')][_0x089f('0x37')]('nolimit')){_0x58d644[_0x089f('0x38')]=qs['limit'](_0x5eb8fd[_0x089f('0x31')][_0x089f('0x38')]);_0x58d644['offset']=qs[_0x089f('0x1c')](_0x5eb8fd[_0x089f('0x31')][_0x089f('0x1c')]);}_0x58d644[_0x089f('0x39')]=qs['sort'](_0x5eb8fd[_0x089f('0x31')]['sort']);_0x58d644['where']=qs['filters'](_[_0x089f('0x3a')](_0x5eb8fd[_0x089f('0x31')],_0x2978f4['filters']),_0x480043);if(_0x5eb8fd[_0x089f('0x31')][_0x089f('0x3b')]){_0x58d644[_0x089f('0x3c')]=_[_0x089f('0x3d')](_0x58d644[_0x089f('0x3c')],{'$or':_[_0x089f('0x29')](_0x480043,function(_0x5769a1){if(_0x5769a1[_0x089f('0x2d')]!=='VIRTUAL'){var _0x4e5429={};_0x4e5429[_0x5769a1['name']]={'$like':'%'+_0x5eb8fd[_0x089f('0x31')]['filter']+'%'};return _0x4e5429;}})});}_0x58d644=_[_0x089f('0x3d')]({},_0x58d644,_0x5eb8fd['options']);var _0x508f9f={'where':_0x58d644['where']};return db[_0x089f('0x2a')][_0x089f('0x1e')](_0x508f9f)[_0x089f('0x23')](function(_0x2ba2f1){_0x488c7d['count']=_0x2ba2f1;if(_0x5eb8fd[_0x089f('0x31')][_0x089f('0x3e')]){_0x58d644[_0x089f('0x3f')]=[{'all':!![]}];}return db[_0x089f('0x2a')][_0x089f('0x40')](_0x58d644);})['then'](function(_0x315ee6){_0x488c7d['rows']=_0x315ee6;return _0x488c7d;})[_0x089f('0x23')](respondWithFilteredResult(_0x3cfe8f,_0x58d644))['catch'](handleError(_0x3cfe8f,null));};exports[_0x089f('0x41')]=function(_0x328c70,_0x36c13b){var _0x177849={'raw':!![],'where':{'id':_0x328c70[_0x089f('0x42')]['id']}},_0x4ff22b={};_0x4ff22b[_0x089f('0x2f')]=_[_0x089f('0x30')](db[_0x089f('0x2a')][_0x089f('0x2b')]);_0x4ff22b[_0x089f('0x31')]=_[_0x089f('0x30')](_0x328c70[_0x089f('0x31')]);_0x4ff22b[_0x089f('0x32')]=_[_0x089f('0x34')](_0x4ff22b[_0x089f('0x2f')],_0x4ff22b[_0x089f('0x31')]);_0x177849[_0x089f('0x33')]=_[_0x089f('0x34')](_0x4ff22b[_0x089f('0x2f')],qs[_0x089f('0x35')](_0x328c70[_0x089f('0x31')][_0x089f('0x35')]));_0x177849[_0x089f('0x33')]=_0x177849[_0x089f('0x33')][_0x089f('0x36')]?_0x177849['attributes']:_0x4ff22b[_0x089f('0x2f')];if(_0x328c70[_0x089f('0x31')][_0x089f('0x3e')]){_0x177849[_0x089f('0x3f')]=[{'all':!![]}];}_0x177849=_[_0x089f('0x3d')]({},_0x177849,_0x328c70[_0x089f('0x43')]);return db[_0x089f('0x2a')][_0x089f('0x44')](_0x177849)['then'](handleEntityNotFound(_0x36c13b,null))[_0x089f('0x23')](respondWithResult(_0x36c13b,null))[_0x089f('0x45')](handleError(_0x36c13b,null));};exports[_0x089f('0x46')]=function(_0x440d4b,_0x4e1090){return db[_0x089f('0x2a')]['create'](_0x440d4b[_0x089f('0x47')],{})[_0x089f('0x23')](respondWithResult(_0x4e1090,0xc9))[_0x089f('0x45')](handleError(_0x4e1090,null));};exports[_0x089f('0x22')]=function(_0x1c0e90,_0xa01067){if(_0x1c0e90['body']['id']){delete _0x1c0e90[_0x089f('0x47')]['id'];}return db[_0x089f('0x2a')][_0x089f('0x44')]({'where':{'id':_0x1c0e90['params']['id']}})['then'](handleEntityNotFound(_0xa01067,null))[_0x089f('0x23')](saveUpdates(_0x1c0e90[_0x089f('0x47')],null))['then'](respondWithResult(_0xa01067,null))[_0x089f('0x45')](handleError(_0xa01067,null));};exports[_0x089f('0x24')]=function(_0x291570,_0x19c290){return db['MailSubstatus'][_0x089f('0x44')]({'where':{'id':_0x291570[_0x089f('0x42')]['id']}})[_0x089f('0x23')](handleEntityNotFound(_0x19c290,null))[_0x089f('0x23')](removeEntity(_0x19c290,null))[_0x089f('0x45')](handleError(_0x19c290,null));};exports[_0x089f('0x48')]=function(_0x1170ce,_0x771421){return db[_0x089f('0x2a')][_0x089f('0x48')]()[_0x089f('0x23')](respondWithResult(_0x771421,null))[_0x089f('0x45')](handleError(_0x771421,null));};