61dd4c008f54e863efd64bae14f7dd7a348513f7
[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 _0xfcf0=['rawAttributes','key','keys','query','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','pick','filter','where','merge','type','options','includeAll','include','findAll','rows','catch','params','find','create','body','describe','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','index','map','MailSubstatus'];(function(_0x41085f,_0x4c4675){var _0x1fb4b2=function(_0x1a7b51){while(--_0x1a7b51){_0x41085f['push'](_0x41085f['shift']());}};_0x1fb4b2(++_0x4c4675);}(_0xfcf0,0x138));var _0x0fcf=function(_0x108d5f,_0x33f82d){_0x108d5f=_0x108d5f-0x0;var _0x456ea3=_0xfcf0[_0x108d5f];return _0x456ea3;};'use strict';var pdf=require(_0x0fcf('0x0'));var emlformat=require(_0x0fcf('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x0fcf('0x2'));var jsonpatch=require(_0x0fcf('0x3'));var rp=require(_0x0fcf('0x4'));var moment=require(_0x0fcf('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x0fcf('0x6'));var util=require(_0x0fcf('0x7'));var path=require(_0x0fcf('0x8'));var sox=require(_0x0fcf('0x9'));var csv=require(_0x0fcf('0xa'));var ejs=require(_0x0fcf('0xb'));var fs=require('fs');var _=require(_0x0fcf('0xc'));var squel=require(_0x0fcf('0xd'));var crypto=require('crypto');var jsforce=require(_0x0fcf('0xe'));var deskjs=require(_0x0fcf('0xf'));var toCsv=require(_0x0fcf('0xa'));var querystring=require('querystring');var Papa=require(_0x0fcf('0x10'));var Redis=require(_0x0fcf('0x11'));var authService=require(_0x0fcf('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x0fcf('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x0fcf('0x14'))(_0x0fcf('0x15'));var utils=require(_0x0fcf('0x16'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x29336a,_0x3c999e){_0x3c999e=_0x3c999e||0xcc;return function(_0x4b4904){if(_0x4b4904){return _0x29336a[_0x0fcf('0x17')](_0x3c999e);}return _0x29336a[_0x0fcf('0x18')](_0x3c999e)[_0x0fcf('0x19')]();};}function respondWithResult(_0x26b169,_0x25fadc){_0x25fadc=_0x25fadc||0xc8;return function(_0x48bba6){if(_0x48bba6){return _0x26b169[_0x0fcf('0x18')](_0x25fadc)[_0x0fcf('0x1a')](_0x48bba6);}};}function respondWithFilteredResult(_0x1fcb47,_0x5e867f){return function(_0x3c09c4){if(_0x3c09c4){var _0x610106=_0x3c09c4[_0x0fcf('0x1b')],_0x445207=_0x5e867f[_0x0fcf('0x1c')],_0x177c8f=_0x5e867f[_0x0fcf('0x1c')]+_0x5e867f[_0x0fcf('0x1d')],_0x48dd53;if(_0x177c8f>=_0x610106){_0x177c8f=_0x610106;_0x48dd53=0xc8;}else{_0x48dd53=0xce;}_0x1fcb47[_0x0fcf('0x18')](_0x48dd53);return _0x1fcb47['set'](_0x0fcf('0x1e'),_0x445207+'-'+_0x177c8f+'/'+_0x610106)[_0x0fcf('0x1a')](_0x3c09c4);}return null;};}function patchUpdates(_0x5dad87){return function(_0x152686){try{jsonpatch[_0x0fcf('0x1f')](_0x152686,_0x5dad87,!![]);}catch(_0x4da7e3){return BPromise[_0x0fcf('0x20')](_0x4da7e3);}return _0x152686['save']();};}function saveUpdates(_0x3fc9e6,_0x13454e){return function(_0x5c8279){if(_0x5c8279){return _0x5c8279[_0x0fcf('0x21')](_0x3fc9e6)[_0x0fcf('0x22')](function(_0x29dbdf){return _0x29dbdf;});}return null;};}function removeEntity(_0x5c459c,_0x2f03ce){return function(_0x1dafc8){if(_0x1dafc8){return _0x1dafc8[_0x0fcf('0x23')]()[_0x0fcf('0x22')](function(){_0x5c459c[_0x0fcf('0x18')](0xcc)[_0x0fcf('0x19')]();});}};}function handleEntityNotFound(_0x5841a9,_0x2eef74){return function(_0x253641){if(!_0x253641){_0x5841a9[_0x0fcf('0x17')](0x194);}return _0x253641;};}function handleError(_0xd6f8b5,_0x233ac9){_0x233ac9=_0x233ac9||0x1f4;return function(_0x3cf074){logger[_0x0fcf('0x24')](_0x3cf074[_0x0fcf('0x25')]);if(_0x3cf074[_0x0fcf('0x26')]){delete _0x3cf074['name'];}_0xd6f8b5[_0x0fcf('0x18')](_0x233ac9)[_0x0fcf('0x27')](_0x3cf074);};}exports[_0x0fcf('0x28')]=function(_0x2f198b,_0x3876ed){var _0x38fe0e={},_0x2730b0={},_0x527d43={'count':0x0,'rows':[]};var _0x137e10=_[_0x0fcf('0x29')](db[_0x0fcf('0x2a')][_0x0fcf('0x2b')],function(_0x49fd0e){return{'name':_0x49fd0e['fieldName'],'type':_0x49fd0e['type'][_0x0fcf('0x2c')]};});_0x2730b0['model']=_[_0x0fcf('0x29')](_0x137e10,_0x0fcf('0x26'));_0x2730b0['query']=_[_0x0fcf('0x2d')](_0x2f198b[_0x0fcf('0x2e')]);_0x2730b0[_0x0fcf('0x2f')]=_[_0x0fcf('0x30')](_0x2730b0[_0x0fcf('0x31')],_0x2730b0[_0x0fcf('0x2e')]);_0x38fe0e['attributes']=_[_0x0fcf('0x30')](_0x2730b0[_0x0fcf('0x31')],qs[_0x0fcf('0x32')](_0x2f198b[_0x0fcf('0x2e')][_0x0fcf('0x32')]));_0x38fe0e[_0x0fcf('0x33')]=_0x38fe0e['attributes'][_0x0fcf('0x34')]?_0x38fe0e[_0x0fcf('0x33')]:_0x2730b0[_0x0fcf('0x31')];if(!_0x2f198b[_0x0fcf('0x2e')][_0x0fcf('0x35')](_0x0fcf('0x36'))){_0x38fe0e[_0x0fcf('0x1d')]=qs[_0x0fcf('0x1d')](_0x2f198b[_0x0fcf('0x2e')][_0x0fcf('0x1d')]);_0x38fe0e[_0x0fcf('0x1c')]=qs[_0x0fcf('0x1c')](_0x2f198b[_0x0fcf('0x2e')][_0x0fcf('0x1c')]);}_0x38fe0e['order']=qs['sort'](_0x2f198b[_0x0fcf('0x2e')]['sort']);_0x38fe0e['where']=qs[_0x0fcf('0x2f')](_[_0x0fcf('0x37')](_0x2f198b[_0x0fcf('0x2e')],_0x2730b0['filters']));if(_0x2f198b['query'][_0x0fcf('0x38')]){_0x38fe0e[_0x0fcf('0x39')]=_[_0x0fcf('0x3a')](_0x38fe0e['where'],{'$or':_[_0x0fcf('0x29')](_0x137e10,function(_0x1d2f3b){if(_0x1d2f3b[_0x0fcf('0x3b')]!=='VIRTUAL'){var _0x4c75e6={};_0x4c75e6[_0x1d2f3b['name']]={'$like':'%'+_0x2f198b[_0x0fcf('0x2e')][_0x0fcf('0x38')]+'%'};return _0x4c75e6;}})});}_0x38fe0e=_[_0x0fcf('0x3a')]({},_0x38fe0e,_0x2f198b[_0x0fcf('0x3c')]);var _0x370699={'where':_0x38fe0e['where']};return db[_0x0fcf('0x2a')][_0x0fcf('0x1b')](_0x370699)[_0x0fcf('0x22')](function(_0x4cbc84){_0x527d43['count']=_0x4cbc84;if(_0x2f198b[_0x0fcf('0x2e')][_0x0fcf('0x3d')]){_0x38fe0e[_0x0fcf('0x3e')]=[{'all':!![]}];}return db[_0x0fcf('0x2a')][_0x0fcf('0x3f')](_0x38fe0e);})['then'](function(_0x1dc2f7){_0x527d43[_0x0fcf('0x40')]=_0x1dc2f7;return _0x527d43;})[_0x0fcf('0x22')](respondWithFilteredResult(_0x3876ed,_0x38fe0e))[_0x0fcf('0x41')](handleError(_0x3876ed,null));};exports['show']=function(_0x5f3800,_0x252000){var _0x2444a6={'raw':!![],'where':{'id':_0x5f3800[_0x0fcf('0x42')]['id']}},_0x5544e3={};_0x5544e3[_0x0fcf('0x31')]=_['keys'](db[_0x0fcf('0x2a')][_0x0fcf('0x2b')]);_0x5544e3[_0x0fcf('0x2e')]=_[_0x0fcf('0x2d')](_0x5f3800[_0x0fcf('0x2e')]);_0x5544e3['filters']=_[_0x0fcf('0x30')](_0x5544e3[_0x0fcf('0x31')],_0x5544e3['query']);_0x2444a6['attributes']=_[_0x0fcf('0x30')](_0x5544e3['model'],qs['fields'](_0x5f3800[_0x0fcf('0x2e')][_0x0fcf('0x32')]));_0x2444a6[_0x0fcf('0x33')]=_0x2444a6[_0x0fcf('0x33')][_0x0fcf('0x34')]?_0x2444a6[_0x0fcf('0x33')]:_0x5544e3[_0x0fcf('0x31')];if(_0x5f3800[_0x0fcf('0x2e')][_0x0fcf('0x3d')]){_0x2444a6[_0x0fcf('0x3e')]=[{'all':!![]}];}_0x2444a6=_['merge']({},_0x2444a6,_0x5f3800[_0x0fcf('0x3c')]);return db[_0x0fcf('0x2a')][_0x0fcf('0x43')](_0x2444a6)['then'](handleEntityNotFound(_0x252000,null))['then'](respondWithResult(_0x252000,null))[_0x0fcf('0x41')](handleError(_0x252000,null));};exports[_0x0fcf('0x44')]=function(_0x1587df,_0x405bbe){return db['MailSubstatus']['create'](_0x1587df[_0x0fcf('0x45')],{})[_0x0fcf('0x22')](respondWithResult(_0x405bbe,0xc9))[_0x0fcf('0x41')](handleError(_0x405bbe,null));};exports[_0x0fcf('0x21')]=function(_0x345188,_0x1a7475){if(_0x345188[_0x0fcf('0x45')]['id']){delete _0x345188[_0x0fcf('0x45')]['id'];}return db['MailSubstatus']['find']({'where':{'id':_0x345188[_0x0fcf('0x42')]['id']}})[_0x0fcf('0x22')](handleEntityNotFound(_0x1a7475,null))[_0x0fcf('0x22')](saveUpdates(_0x345188[_0x0fcf('0x45')],null))[_0x0fcf('0x22')](respondWithResult(_0x1a7475,null))[_0x0fcf('0x41')](handleError(_0x1a7475,null));};exports['destroy']=function(_0x2b6ad3,_0x2aa7c4){return db['MailSubstatus'][_0x0fcf('0x43')]({'where':{'id':_0x2b6ad3[_0x0fcf('0x42')]['id']}})[_0x0fcf('0x22')](handleEntityNotFound(_0x2aa7c4,null))[_0x0fcf('0x22')](removeEntity(_0x2aa7c4,null))['catch'](handleError(_0x2aa7c4,null));};exports[_0x0fcf('0x46')]=function(_0x382448,_0x1bb062){return db[_0x0fcf('0x2a')][_0x0fcf('0x46')]()[_0x0fcf('0x22')](respondWithResult(_0x1bb062,null))[_0x0fcf('0x41')](handleError(_0x1bb062,null));};