Built motion from commit b0a9a629.|2.6.33
[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 _0xae47=['error','name','send','map','MailSubstatus','rawAttributes','fieldName','model','query','keys','filters','intersection','fields','attributes','length','order','sort','where','pick','filter','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','merge','find','create','body','update','params','destroy','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../mysqldb','sendStatus','status','end','offset','limit','count','set','Content-Range','apply','reject','save','then'];(function(_0x2256ed,_0x316d4c){var _0xd0410f=function(_0x3597ab){while(--_0x3597ab){_0x2256ed['push'](_0x2256ed['shift']());}};_0xd0410f(++_0x316d4c);}(_0xae47,0x140));var _0x7ae4=function(_0x370e2a,_0x51086a){_0x370e2a=_0x370e2a-0x0;var _0x27c781=_0xae47[_0x370e2a];return _0x27c781;};'use strict';var emlformat=require(_0x7ae4('0x0'));var rimraf=require(_0x7ae4('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7ae4('0x2'));var rp=require(_0x7ae4('0x3'));var moment=require(_0x7ae4('0x4'));var BPromise=require(_0x7ae4('0x5'));var Mustache=require('mustache');var util=require(_0x7ae4('0x6'));var path=require(_0x7ae4('0x7'));var sox=require(_0x7ae4('0x8'));var csv=require(_0x7ae4('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x7ae4('0xa'));var _=require(_0x7ae4('0xb'));var squel=require('squel');var crypto=require(_0x7ae4('0xc'));var jsforce=require(_0x7ae4('0xd'));var deskjs=require(_0x7ae4('0xe'));var toCsv=require(_0x7ae4('0x9'));var querystring=require(_0x7ae4('0xf'));var Papa=require('papaparse');var Redis=require(_0x7ae4('0x10'));var authService=require(_0x7ae4('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x7ae4('0x12'));var hardwareService=require(_0x7ae4('0x13'));var logger=require('../../config/logger')(_0x7ae4('0x14'));var utils=require(_0x7ae4('0x15'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x7ae4('0x16'))['db'];function respondWithStatusCode(_0xf6054d,_0x4056d9){_0x4056d9=_0x4056d9||0xcc;return function(_0x4c2a8d){if(_0x4c2a8d){return _0xf6054d[_0x7ae4('0x17')](_0x4056d9);}return _0xf6054d[_0x7ae4('0x18')](_0x4056d9)[_0x7ae4('0x19')]();};}function respondWithResult(_0x58a895,_0x5ead8c){_0x5ead8c=_0x5ead8c||0xc8;return function(_0x4e7944){if(_0x4e7944){return _0x58a895[_0x7ae4('0x18')](_0x5ead8c)['json'](_0x4e7944);}};}function respondWithFilteredResult(_0x3ef5bd,_0x2c7616){return function(_0x507b64){if(_0x507b64){var _0x227dd4=typeof _0x2c7616[_0x7ae4('0x1a')]==='undefined'&&typeof _0x2c7616[_0x7ae4('0x1b')]==='undefined';var _0x28595b=_0x507b64[_0x7ae4('0x1c')];var _0x142ee1=_0x227dd4?0x0:_0x2c7616[_0x7ae4('0x1a')];var _0xe56a82=_0x227dd4?_0x507b64[_0x7ae4('0x1c')]:_0x2c7616['offset']+_0x2c7616[_0x7ae4('0x1b')];var _0x83ccfd;if(_0xe56a82>=_0x28595b){_0xe56a82=_0x28595b;_0x83ccfd=0xc8;}else{_0x83ccfd=0xce;}_0x3ef5bd['status'](_0x83ccfd);return _0x3ef5bd[_0x7ae4('0x1d')](_0x7ae4('0x1e'),_0x142ee1+'-'+_0xe56a82+'/'+_0x28595b)['json'](_0x507b64);}return null;};}function patchUpdates(_0x2e09d5){return function(_0x276e70){try{jsonpatch[_0x7ae4('0x1f')](_0x276e70,_0x2e09d5,!![]);}catch(_0x584917){return BPromise[_0x7ae4('0x20')](_0x584917);}return _0x276e70[_0x7ae4('0x21')]();};}function saveUpdates(_0xa06e38,_0x51f72c){return function(_0x4b5b03){if(_0x4b5b03){return _0x4b5b03['update'](_0xa06e38)[_0x7ae4('0x22')](function(_0x65efd3){return _0x65efd3;});}return null;};}function removeEntity(_0x1d0e4c,_0x2a877c){return function(_0x54252b){if(_0x54252b){return _0x54252b['destroy']()[_0x7ae4('0x22')](function(){_0x1d0e4c[_0x7ae4('0x18')](0xcc)[_0x7ae4('0x19')]();});}};}function handleEntityNotFound(_0x50af9a,_0xd031b3){return function(_0x3fa922){if(!_0x3fa922){_0x50af9a[_0x7ae4('0x17')](0x194);}return _0x3fa922;};}function handleError(_0xe92335,_0x56e088){_0x56e088=_0x56e088||0x1f4;return function(_0x2570a0){logger[_0x7ae4('0x23')](_0x2570a0['stack']);if(_0x2570a0[_0x7ae4('0x24')]){delete _0x2570a0['name'];}_0xe92335[_0x7ae4('0x18')](_0x56e088)[_0x7ae4('0x25')](_0x2570a0);};}exports['index']=function(_0x9b4a52,_0x17b096){var _0x42f718={},_0x2840ad={},_0x3afb7e={'count':0x0,'rows':[]};var _0x2626f0=_[_0x7ae4('0x26')](db[_0x7ae4('0x27')][_0x7ae4('0x28')],function(_0x104708){return{'name':_0x104708[_0x7ae4('0x29')],'type':_0x104708['type']['key']};});_0x2840ad[_0x7ae4('0x2a')]=_[_0x7ae4('0x26')](_0x2626f0,'name');_0x2840ad[_0x7ae4('0x2b')]=_[_0x7ae4('0x2c')](_0x9b4a52[_0x7ae4('0x2b')]);_0x2840ad[_0x7ae4('0x2d')]=_[_0x7ae4('0x2e')](_0x2840ad[_0x7ae4('0x2a')],_0x2840ad[_0x7ae4('0x2b')]);_0x42f718['attributes']=_[_0x7ae4('0x2e')](_0x2840ad[_0x7ae4('0x2a')],qs[_0x7ae4('0x2f')](_0x9b4a52[_0x7ae4('0x2b')]['fields']));_0x42f718['attributes']=_0x42f718[_0x7ae4('0x30')][_0x7ae4('0x31')]?_0x42f718['attributes']:_0x2840ad[_0x7ae4('0x2a')];if(!_0x9b4a52['query']['hasOwnProperty']('nolimit')){_0x42f718[_0x7ae4('0x1b')]=qs[_0x7ae4('0x1b')](_0x9b4a52[_0x7ae4('0x2b')]['limit']);_0x42f718[_0x7ae4('0x1a')]=qs[_0x7ae4('0x1a')](_0x9b4a52['query'][_0x7ae4('0x1a')]);}_0x42f718[_0x7ae4('0x32')]=qs[_0x7ae4('0x33')](_0x9b4a52[_0x7ae4('0x2b')][_0x7ae4('0x33')]);_0x42f718[_0x7ae4('0x34')]=qs['filters'](_[_0x7ae4('0x35')](_0x9b4a52[_0x7ae4('0x2b')],_0x2840ad['filters']),_0x2626f0);if(_0x9b4a52['query'][_0x7ae4('0x36')]){_0x42f718[_0x7ae4('0x34')]=_['merge'](_0x42f718[_0x7ae4('0x34')],{'$or':_[_0x7ae4('0x26')](_0x2626f0,function(_0x37ee58){if(_0x37ee58['type']!==_0x7ae4('0x37')){var _0x178461={};_0x178461[_0x37ee58[_0x7ae4('0x24')]]={'$like':'%'+_0x9b4a52[_0x7ae4('0x2b')][_0x7ae4('0x36')]+'%'};return _0x178461;}})});}_0x42f718=_['merge']({},_0x42f718,_0x9b4a52[_0x7ae4('0x38')]);var _0x41041f={'where':_0x42f718[_0x7ae4('0x34')]};return db[_0x7ae4('0x27')][_0x7ae4('0x1c')](_0x41041f)[_0x7ae4('0x22')](function(_0x9b14da){_0x3afb7e[_0x7ae4('0x1c')]=_0x9b14da;if(_0x9b4a52[_0x7ae4('0x2b')][_0x7ae4('0x39')]){_0x42f718[_0x7ae4('0x3a')]=[{'all':!![]}];}return db['MailSubstatus'][_0x7ae4('0x3b')](_0x42f718);})['then'](function(_0x17437f){_0x3afb7e[_0x7ae4('0x3c')]=_0x17437f;return _0x3afb7e;})[_0x7ae4('0x22')](respondWithFilteredResult(_0x17b096,_0x42f718))[_0x7ae4('0x3d')](handleError(_0x17b096,null));};exports[_0x7ae4('0x3e')]=function(_0x135d67,_0x4498ef){var _0x1af5b9={'raw':!![],'where':{'id':_0x135d67['params']['id']}},_0x11c963={};_0x11c963['model']=_['keys'](db['MailSubstatus']['rawAttributes']);_0x11c963[_0x7ae4('0x2b')]=_[_0x7ae4('0x2c')](_0x135d67[_0x7ae4('0x2b')]);_0x11c963[_0x7ae4('0x2d')]=_[_0x7ae4('0x2e')](_0x11c963[_0x7ae4('0x2a')],_0x11c963[_0x7ae4('0x2b')]);_0x1af5b9['attributes']=_[_0x7ae4('0x2e')](_0x11c963[_0x7ae4('0x2a')],qs['fields'](_0x135d67['query'][_0x7ae4('0x2f')]));_0x1af5b9[_0x7ae4('0x30')]=_0x1af5b9['attributes'][_0x7ae4('0x31')]?_0x1af5b9['attributes']:_0x11c963['model'];if(_0x135d67[_0x7ae4('0x2b')][_0x7ae4('0x39')]){_0x1af5b9[_0x7ae4('0x3a')]=[{'all':!![]}];}_0x1af5b9=_[_0x7ae4('0x3f')]({},_0x1af5b9,_0x135d67['options']);return db[_0x7ae4('0x27')][_0x7ae4('0x40')](_0x1af5b9)[_0x7ae4('0x22')](handleEntityNotFound(_0x4498ef,null))[_0x7ae4('0x22')](respondWithResult(_0x4498ef,null))[_0x7ae4('0x3d')](handleError(_0x4498ef,null));};exports[_0x7ae4('0x41')]=function(_0xd87b7c,_0x105c82){return db['MailSubstatus'][_0x7ae4('0x41')](_0xd87b7c[_0x7ae4('0x42')],{})[_0x7ae4('0x22')](respondWithResult(_0x105c82,0xc9))[_0x7ae4('0x3d')](handleError(_0x105c82,null));};exports[_0x7ae4('0x43')]=function(_0x5e1f2b,_0x5090b6){if(_0x5e1f2b[_0x7ae4('0x42')]['id']){delete _0x5e1f2b[_0x7ae4('0x42')]['id'];}return db['MailSubstatus']['find']({'where':{'id':_0x5e1f2b[_0x7ae4('0x44')]['id']}})[_0x7ae4('0x22')](handleEntityNotFound(_0x5090b6,null))[_0x7ae4('0x22')](saveUpdates(_0x5e1f2b['body'],null))['then'](respondWithResult(_0x5090b6,null))[_0x7ae4('0x3d')](handleError(_0x5090b6,null));};exports[_0x7ae4('0x45')]=function(_0x40f5e0,_0xc81030){return db['MailSubstatus'][_0x7ae4('0x40')]({'where':{'id':_0x40f5e0[_0x7ae4('0x44')]['id']}})[_0x7ae4('0x22')](handleEntityNotFound(_0xc81030,null))['then'](removeEntity(_0xc81030,null))[_0x7ae4('0x3d')](handleError(_0xc81030,null));};exports[_0x7ae4('0x46')]=function(_0x3ba6db,_0x3a51dd){return db[_0x7ae4('0x27')][_0x7ae4('0x46')]()[_0x7ae4('0x22')](respondWithResult(_0x3a51dd,null))['catch'](handleError(_0x3a51dd,null));};