b6764046977e8a25cee120ac59862b5904145dd7
[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 _0xce6a=['hasOwnProperty','nolimit','order','sort','pick','filter','merge','where','type','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','keys','include','find','create','body','destroy','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','to-csv','fs-extra','lodash','jsforce','desk.js','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','stack','name','send','index','map','MailSubstatus','rawAttributes','key','query','filters','intersection','model','attributes','fields','length'];(function(_0x962cfd,_0x1dc549){var _0x389071=function(_0x23efc7){while(--_0x23efc7){_0x962cfd['push'](_0x962cfd['shift']());}};_0x389071(++_0x1dc549);}(_0xce6a,0x1c8));var _0xace6=function(_0xfb3645,_0xcfe2c5){_0xfb3645=_0xfb3645-0x0;var _0x36aef8=_0xce6a[_0xfb3645];return _0x36aef8;};'use strict';var emlformat=require(_0xace6('0x0'));var rimraf=require(_0xace6('0x1'));var zipdir=require(_0xace6('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xace6('0x3'));var moment=require(_0xace6('0x4'));var BPromise=require(_0xace6('0x5'));var Mustache=require(_0xace6('0x6'));var util=require(_0xace6('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0xace6('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xace6('0x9'));var _=require(_0xace6('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xace6('0xb'));var deskjs=require(_0xace6('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xace6('0xd'));var qs=require(_0xace6('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xace6('0xf'));var logger=require(_0xace6('0x10'))(_0xace6('0x11'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5b91fd,_0x40def7){_0x40def7=_0x40def7||0xcc;return function(_0x44f8b7){if(_0x44f8b7){return _0x5b91fd[_0xace6('0x12')](_0x40def7);}return _0x5b91fd['status'](_0x40def7)[_0xace6('0x13')]();};}function respondWithResult(_0x187279,_0x1bda05){_0x1bda05=_0x1bda05||0xc8;return function(_0x109988){if(_0x109988){return _0x187279[_0xace6('0x14')](_0x1bda05)[_0xace6('0x15')](_0x109988);}};}function respondWithFilteredResult(_0x3a3954,_0x13fff0){return function(_0x129b46){if(_0x129b46){var _0x4a3dbd=typeof _0x13fff0[_0xace6('0x16')]===_0xace6('0x17')&&typeof _0x13fff0[_0xace6('0x18')]===_0xace6('0x17');var _0x559b35=_0x129b46[_0xace6('0x19')];var _0x345d31=_0x4a3dbd?0x0:_0x13fff0[_0xace6('0x16')];var _0x249e03=_0x4a3dbd?_0x129b46[_0xace6('0x19')]:_0x13fff0[_0xace6('0x16')]+_0x13fff0[_0xace6('0x18')];var _0x1b9e13;if(_0x249e03>=_0x559b35){_0x249e03=_0x559b35;_0x1b9e13=0xc8;}else{_0x1b9e13=0xce;}_0x3a3954[_0xace6('0x14')](_0x1b9e13);return _0x3a3954[_0xace6('0x1a')](_0xace6('0x1b'),_0x345d31+'-'+_0x249e03+'/'+_0x559b35)[_0xace6('0x15')](_0x129b46);}return null;};}function patchUpdates(_0x2817d8){return function(_0x4dc66f){try{jsonpatch[_0xace6('0x1c')](_0x4dc66f,_0x2817d8,!![]);}catch(_0x78f79){return BPromise[_0xace6('0x1d')](_0x78f79);}return _0x4dc66f[_0xace6('0x1e')]();};}function saveUpdates(_0x4796ca,_0x3e5921){return function(_0x2c7f93){if(_0x2c7f93){return _0x2c7f93[_0xace6('0x1f')](_0x4796ca)[_0xace6('0x20')](function(_0x2fcc29){return _0x2fcc29;});}return null;};}function removeEntity(_0x2944e9,_0x3fb3eb){return function(_0x365357){if(_0x365357){return _0x365357['destroy']()['then'](function(){_0x2944e9[_0xace6('0x14')](0xcc)[_0xace6('0x13')]();});}};}function handleEntityNotFound(_0x5e652d,_0x5002a6){return function(_0x34bcd1){if(!_0x34bcd1){_0x5e652d[_0xace6('0x12')](0x194);}return _0x34bcd1;};}function handleError(_0x56ba79,_0x3bf2fa){_0x3bf2fa=_0x3bf2fa||0x1f4;return function(_0x2536b6){logger['error'](_0x2536b6[_0xace6('0x21')]);if(_0x2536b6[_0xace6('0x22')]){delete _0x2536b6['name'];}_0x56ba79['status'](_0x3bf2fa)[_0xace6('0x23')](_0x2536b6);};}exports[_0xace6('0x24')]=function(_0x574a4d,_0x509f74){var _0x177e36={},_0x10d8d2={},_0x2a7b57={'count':0x0,'rows':[]};var _0x488c9d=_[_0xace6('0x25')](db[_0xace6('0x26')][_0xace6('0x27')],function(_0x5e3a93){return{'name':_0x5e3a93['fieldName'],'type':_0x5e3a93['type'][_0xace6('0x28')]};});_0x10d8d2['model']=_[_0xace6('0x25')](_0x488c9d,'name');_0x10d8d2[_0xace6('0x29')]=_['keys'](_0x574a4d[_0xace6('0x29')]);_0x10d8d2[_0xace6('0x2a')]=_[_0xace6('0x2b')](_0x10d8d2[_0xace6('0x2c')],_0x10d8d2[_0xace6('0x29')]);_0x177e36[_0xace6('0x2d')]=_[_0xace6('0x2b')](_0x10d8d2[_0xace6('0x2c')],qs[_0xace6('0x2e')](_0x574a4d[_0xace6('0x29')][_0xace6('0x2e')]));_0x177e36[_0xace6('0x2d')]=_0x177e36[_0xace6('0x2d')][_0xace6('0x2f')]?_0x177e36['attributes']:_0x10d8d2['model'];if(!_0x574a4d[_0xace6('0x29')][_0xace6('0x30')](_0xace6('0x31'))){_0x177e36[_0xace6('0x18')]=qs[_0xace6('0x18')](_0x574a4d[_0xace6('0x29')][_0xace6('0x18')]);_0x177e36[_0xace6('0x16')]=qs['offset'](_0x574a4d['query']['offset']);}_0x177e36[_0xace6('0x32')]=qs['sort'](_0x574a4d['query'][_0xace6('0x33')]);_0x177e36['where']=qs[_0xace6('0x2a')](_[_0xace6('0x34')](_0x574a4d[_0xace6('0x29')],_0x10d8d2[_0xace6('0x2a')]),_0x488c9d);if(_0x574a4d[_0xace6('0x29')][_0xace6('0x35')]){_0x177e36['where']=_[_0xace6('0x36')](_0x177e36[_0xace6('0x37')],{'$or':_[_0xace6('0x25')](_0x488c9d,function(_0x57a3ae){if(_0x57a3ae[_0xace6('0x38')]!==_0xace6('0x39')){var _0x5de40f={};_0x5de40f[_0x57a3ae[_0xace6('0x22')]]={'$like':'%'+_0x574a4d[_0xace6('0x29')][_0xace6('0x35')]+'%'};return _0x5de40f;}})});}_0x177e36=_[_0xace6('0x36')]({},_0x177e36,_0x574a4d[_0xace6('0x3a')]);var _0x5533a5={'where':_0x177e36['where']};return db[_0xace6('0x26')][_0xace6('0x19')](_0x5533a5)[_0xace6('0x20')](function(_0xf0844){_0x2a7b57[_0xace6('0x19')]=_0xf0844;if(_0x574a4d[_0xace6('0x29')][_0xace6('0x3b')]){_0x177e36['include']=[{'all':!![]}];}return db[_0xace6('0x26')][_0xace6('0x3c')](_0x177e36);})[_0xace6('0x20')](function(_0x962192){_0x2a7b57[_0xace6('0x3d')]=_0x962192;return _0x2a7b57;})[_0xace6('0x20')](respondWithFilteredResult(_0x509f74,_0x177e36))[_0xace6('0x3e')](handleError(_0x509f74,null));};exports[_0xace6('0x3f')]=function(_0x1d67b3,_0x4816b4){var _0x22ea82={'raw':!![],'where':{'id':_0x1d67b3[_0xace6('0x40')]['id']}},_0x5ddf0d={};_0x5ddf0d[_0xace6('0x2c')]=_['keys'](db['MailSubstatus'][_0xace6('0x27')]);_0x5ddf0d[_0xace6('0x29')]=_[_0xace6('0x41')](_0x1d67b3['query']);_0x5ddf0d[_0xace6('0x2a')]=_['intersection'](_0x5ddf0d[_0xace6('0x2c')],_0x5ddf0d[_0xace6('0x29')]);_0x22ea82[_0xace6('0x2d')]=_[_0xace6('0x2b')](_0x5ddf0d[_0xace6('0x2c')],qs[_0xace6('0x2e')](_0x1d67b3['query']['fields']));_0x22ea82[_0xace6('0x2d')]=_0x22ea82[_0xace6('0x2d')][_0xace6('0x2f')]?_0x22ea82[_0xace6('0x2d')]:_0x5ddf0d[_0xace6('0x2c')];if(_0x1d67b3[_0xace6('0x29')]['includeAll']){_0x22ea82[_0xace6('0x42')]=[{'all':!![]}];}_0x22ea82=_[_0xace6('0x36')]({},_0x22ea82,_0x1d67b3[_0xace6('0x3a')]);return db['MailSubstatus'][_0xace6('0x43')](_0x22ea82)[_0xace6('0x20')](handleEntityNotFound(_0x4816b4,null))[_0xace6('0x20')](respondWithResult(_0x4816b4,null))[_0xace6('0x3e')](handleError(_0x4816b4,null));};exports[_0xace6('0x44')]=function(_0x45ae88,_0x49950a){return db['MailSubstatus'][_0xace6('0x44')](_0x45ae88['body'],{})[_0xace6('0x20')](respondWithResult(_0x49950a,0xc9))['catch'](handleError(_0x49950a,null));};exports['update']=function(_0x2b940e,_0x313a2b){if(_0x2b940e['body']['id']){delete _0x2b940e['body']['id'];}return db[_0xace6('0x26')][_0xace6('0x43')]({'where':{'id':_0x2b940e[_0xace6('0x40')]['id']}})['then'](handleEntityNotFound(_0x313a2b,null))[_0xace6('0x20')](saveUpdates(_0x2b940e[_0xace6('0x45')],null))[_0xace6('0x20')](respondWithResult(_0x313a2b,null))[_0xace6('0x3e')](handleError(_0x313a2b,null));};exports[_0xace6('0x46')]=function(_0x4a215b,_0x308720){return db[_0xace6('0x26')][_0xace6('0x43')]({'where':{'id':_0x4a215b['params']['id']}})[_0xace6('0x20')](handleEntityNotFound(_0x308720,null))[_0xace6('0x20')](removeEntity(_0x308720,null))['catch'](handleError(_0x308720,null));};exports[_0xace6('0x47')]=function(_0x46df75,_0x5cdc70){return db[_0xace6('0x26')][_0xace6('0x47')]()[_0xace6('0x20')](respondWithResult(_0x5cdc70,null))[_0xace6('0x3e')](handleError(_0x5cdc70,null));};