Built motion from commit ddca4d0d.|2.5.47
[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 _0x124f=['status','json','offset','undefined','limit','set','Content-Range','apply','reject','save','then','destroy','error','name','map','MailSubstatus','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','filter','options','count','includeAll','include','findAll','rows','catch','params','fields','find','create','body','update','describe','eml-format','rimraf','zip-dir','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus'];(function(_0x484cac,_0x30ad3a){var _0x1d6e77=function(_0x4f5f16){while(--_0x4f5f16){_0x484cac['push'](_0x484cac['shift']());}};_0x1d6e77(++_0x30ad3a);}(_0x124f,0x1a8));var _0xf124=function(_0x3aa0dc,_0x24fd70){_0x3aa0dc=_0x3aa0dc-0x0;var _0x5ffe7b=_0x124f[_0x3aa0dc];return _0x5ffe7b;};'use strict';var emlformat=require(_0xf124('0x0'));var rimraf=require(_0xf124('0x1'));var zipdir=require(_0xf124('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xf124('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xf124('0x4'));var util=require(_0xf124('0x5'));var path=require(_0xf124('0x6'));var sox=require(_0xf124('0x7'));var csv=require(_0xf124('0x8'));var ejs=require(_0xf124('0x9'));var fs=require('fs');var fs_extra=require(_0xf124('0xa'));var _=require(_0xf124('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xf124('0xc'));var deskjs=require(_0xf124('0xd'));var toCsv=require(_0xf124('0x8'));var querystring=require(_0xf124('0xe'));var Papa=require(_0xf124('0xf'));var Redis=require(_0xf124('0x10'));var authService=require(_0xf124('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xf124('0x12'));var hardwareService=require(_0xf124('0x13'));var logger=require(_0xf124('0x14'))(_0xf124('0x15'));var utils=require('../../config/utils');var config=require(_0xf124('0x16'));var licenseUtil=require(_0xf124('0x17'));var db=require(_0xf124('0x18'))['db'];function respondWithStatusCode(_0xb0b447,_0x5e177f){_0x5e177f=_0x5e177f||0xcc;return function(_0x5ee9ee){if(_0x5ee9ee){return _0xb0b447[_0xf124('0x19')](_0x5e177f);}return _0xb0b447[_0xf124('0x1a')](_0x5e177f)['end']();};}function respondWithResult(_0x19883c,_0x33ae55){_0x33ae55=_0x33ae55||0xc8;return function(_0x274ea1){if(_0x274ea1){return _0x19883c['status'](_0x33ae55)[_0xf124('0x1b')](_0x274ea1);}};}function respondWithFilteredResult(_0x31f374,_0x512ab0){return function(_0x5d0133){if(_0x5d0133){var _0xbc7745=typeof _0x512ab0[_0xf124('0x1c')]===_0xf124('0x1d')&&typeof _0x512ab0[_0xf124('0x1e')]===_0xf124('0x1d');var _0x3385df=_0x5d0133['count'];var _0x350347=_0xbc7745?0x0:_0x512ab0['offset'];var _0x1edb07=_0xbc7745?_0x5d0133['count']:_0x512ab0[_0xf124('0x1c')]+_0x512ab0['limit'];var _0x41bcbc;if(_0x1edb07>=_0x3385df){_0x1edb07=_0x3385df;_0x41bcbc=0xc8;}else{_0x41bcbc=0xce;}_0x31f374['status'](_0x41bcbc);return _0x31f374[_0xf124('0x1f')](_0xf124('0x20'),_0x350347+'-'+_0x1edb07+'/'+_0x3385df)[_0xf124('0x1b')](_0x5d0133);}return null;};}function patchUpdates(_0x50706e){return function(_0x1aa8e4){try{jsonpatch[_0xf124('0x21')](_0x1aa8e4,_0x50706e,!![]);}catch(_0x18c0e3){return BPromise[_0xf124('0x22')](_0x18c0e3);}return _0x1aa8e4[_0xf124('0x23')]();};}function saveUpdates(_0x4db900,_0x522a6a){return function(_0x42bfb1){if(_0x42bfb1){return _0x42bfb1['update'](_0x4db900)[_0xf124('0x24')](function(_0x43e28f){return _0x43e28f;});}return null;};}function removeEntity(_0xaf954a,_0x53293c){return function(_0x4e0205){if(_0x4e0205){return _0x4e0205[_0xf124('0x25')]()[_0xf124('0x24')](function(){_0xaf954a[_0xf124('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4e530f,_0xf3ba6e){return function(_0x2cfac5){if(!_0x2cfac5){_0x4e530f[_0xf124('0x19')](0x194);}return _0x2cfac5;};}function handleError(_0x371942,_0x36a8ca){_0x36a8ca=_0x36a8ca||0x1f4;return function(_0x2d794b){logger[_0xf124('0x26')](_0x2d794b['stack']);if(_0x2d794b[_0xf124('0x27')]){delete _0x2d794b[_0xf124('0x27')];}_0x371942['status'](_0x36a8ca)['send'](_0x2d794b);};}exports['index']=function(_0x47d7e8,_0x41dc89){var _0x13ecb4={},_0x58e828={},_0x2f4d79={'count':0x0,'rows':[]};var _0x382665=_[_0xf124('0x28')](db[_0xf124('0x29')][_0xf124('0x2a')],function(_0x4c8a4c){return{'name':_0x4c8a4c[_0xf124('0x2b')],'type':_0x4c8a4c[_0xf124('0x2c')][_0xf124('0x2d')]};});_0x58e828[_0xf124('0x2e')]=_[_0xf124('0x28')](_0x382665,_0xf124('0x27'));_0x58e828[_0xf124('0x2f')]=_[_0xf124('0x30')](_0x47d7e8['query']);_0x58e828[_0xf124('0x31')]=_[_0xf124('0x32')](_0x58e828[_0xf124('0x2e')],_0x58e828['query']);_0x13ecb4[_0xf124('0x33')]=_[_0xf124('0x32')](_0x58e828['model'],qs['fields'](_0x47d7e8[_0xf124('0x2f')]['fields']));_0x13ecb4[_0xf124('0x33')]=_0x13ecb4[_0xf124('0x33')][_0xf124('0x34')]?_0x13ecb4[_0xf124('0x33')]:_0x58e828['model'];if(!_0x47d7e8[_0xf124('0x2f')][_0xf124('0x35')]('nolimit')){_0x13ecb4[_0xf124('0x1e')]=qs[_0xf124('0x1e')](_0x47d7e8[_0xf124('0x2f')][_0xf124('0x1e')]);_0x13ecb4[_0xf124('0x1c')]=qs[_0xf124('0x1c')](_0x47d7e8[_0xf124('0x2f')]['offset']);}_0x13ecb4[_0xf124('0x36')]=qs[_0xf124('0x37')](_0x47d7e8['query']['sort']);_0x13ecb4[_0xf124('0x38')]=qs[_0xf124('0x31')](_[_0xf124('0x39')](_0x47d7e8['query'],_0x58e828[_0xf124('0x31')]),_0x382665);if(_0x47d7e8[_0xf124('0x2f')]['filter']){_0x13ecb4[_0xf124('0x38')]=_[_0xf124('0x3a')](_0x13ecb4['where'],{'$or':_[_0xf124('0x28')](_0x382665,function(_0x4aeb98){if(_0x4aeb98['type']!==_0xf124('0x3b')){var _0x184855={};_0x184855[_0x4aeb98[_0xf124('0x27')]]={'$like':'%'+_0x47d7e8[_0xf124('0x2f')][_0xf124('0x3c')]+'%'};return _0x184855;}})});}_0x13ecb4=_[_0xf124('0x3a')]({},_0x13ecb4,_0x47d7e8[_0xf124('0x3d')]);var _0x5f365f={'where':_0x13ecb4[_0xf124('0x38')]};return db[_0xf124('0x29')][_0xf124('0x3e')](_0x5f365f)['then'](function(_0x2a6a4e){_0x2f4d79[_0xf124('0x3e')]=_0x2a6a4e;if(_0x47d7e8['query'][_0xf124('0x3f')]){_0x13ecb4[_0xf124('0x40')]=[{'all':!![]}];}return db[_0xf124('0x29')][_0xf124('0x41')](_0x13ecb4);})[_0xf124('0x24')](function(_0x2647ed){_0x2f4d79[_0xf124('0x42')]=_0x2647ed;return _0x2f4d79;})[_0xf124('0x24')](respondWithFilteredResult(_0x41dc89,_0x13ecb4))[_0xf124('0x43')](handleError(_0x41dc89,null));};exports['show']=function(_0x4a5083,_0x2271e9){var _0x25e6f6={'raw':!![],'where':{'id':_0x4a5083[_0xf124('0x44')]['id']}},_0x2e892e={};_0x2e892e[_0xf124('0x2e')]=_[_0xf124('0x30')](db[_0xf124('0x29')]['rawAttributes']);_0x2e892e['query']=_[_0xf124('0x30')](_0x4a5083['query']);_0x2e892e[_0xf124('0x31')]=_[_0xf124('0x32')](_0x2e892e[_0xf124('0x2e')],_0x2e892e['query']);_0x25e6f6[_0xf124('0x33')]=_[_0xf124('0x32')](_0x2e892e['model'],qs[_0xf124('0x45')](_0x4a5083['query'][_0xf124('0x45')]));_0x25e6f6['attributes']=_0x25e6f6['attributes'][_0xf124('0x34')]?_0x25e6f6[_0xf124('0x33')]:_0x2e892e[_0xf124('0x2e')];if(_0x4a5083[_0xf124('0x2f')][_0xf124('0x3f')]){_0x25e6f6['include']=[{'all':!![]}];}_0x25e6f6=_[_0xf124('0x3a')]({},_0x25e6f6,_0x4a5083[_0xf124('0x3d')]);return db['MailSubstatus'][_0xf124('0x46')](_0x25e6f6)['then'](handleEntityNotFound(_0x2271e9,null))[_0xf124('0x24')](respondWithResult(_0x2271e9,null))[_0xf124('0x43')](handleError(_0x2271e9,null));};exports[_0xf124('0x47')]=function(_0x2db0f9,_0x17c77f){return db[_0xf124('0x29')][_0xf124('0x47')](_0x2db0f9[_0xf124('0x48')],{})[_0xf124('0x24')](respondWithResult(_0x17c77f,0xc9))[_0xf124('0x43')](handleError(_0x17c77f,null));};exports[_0xf124('0x49')]=function(_0x286eb7,_0x5c2869){if(_0x286eb7[_0xf124('0x48')]['id']){delete _0x286eb7[_0xf124('0x48')]['id'];}return db['MailSubstatus'][_0xf124('0x46')]({'where':{'id':_0x286eb7[_0xf124('0x44')]['id']}})[_0xf124('0x24')](handleEntityNotFound(_0x5c2869,null))[_0xf124('0x24')](saveUpdates(_0x286eb7[_0xf124('0x48')],null))[_0xf124('0x24')](respondWithResult(_0x5c2869,null))[_0xf124('0x43')](handleError(_0x5c2869,null));};exports['destroy']=function(_0x5acbe9,_0x4dc607){return db[_0xf124('0x29')][_0xf124('0x46')]({'where':{'id':_0x5acbe9[_0xf124('0x44')]['id']}})[_0xf124('0x24')](handleEntityNotFound(_0x4dc607,null))[_0xf124('0x24')](removeEntity(_0x4dc607,null))[_0xf124('0x43')](handleError(_0x4dc607,null));};exports['describe']=function(_0x2ef9b6,_0x5af9cb){return db[_0xf124('0x29')][_0xf124('0x4a')]()[_0xf124('0x24')](respondWithResult(_0x5af9cb,null))[_0xf124('0x43')](handleError(_0x5af9cb,null));};