24223753837db3655ebcce90211f3af58f125792
[motion2.git] / server / api / smsTransferReport / smsTransferReport.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 _0xb8ff=['find','create','body','describe','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','crypto','desk.js','papaparse','ioredis','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','update','then','destroy','end','error','stack','name','send','map','SmsTransferReport','rawAttributes','fieldName','type','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','order','sort','pick','filter','where','VIRTUAL','options','includeAll','findAll','catch','show','params','include'];(function(_0x21854e,_0x1a4cd1){var _0x209a2b=function(_0x191146){while(--_0x191146){_0x21854e['push'](_0x21854e['shift']());}};_0x209a2b(++_0x1a4cd1);}(_0xb8ff,0x196));var _0xfb8f=function(_0x4cf089,_0x24c0ca){_0x4cf089=_0x4cf089-0x0;var _0x12fe3e=_0xb8ff[_0x4cf089];return _0x12fe3e;};'use strict';var emlformat=require(_0xfb8f('0x0'));var rimraf=require(_0xfb8f('0x1'));var zipdir=require(_0xfb8f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xfb8f('0x3'));var moment=require(_0xfb8f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xfb8f('0x5'));var util=require(_0xfb8f('0x6'));var path=require(_0xfb8f('0x7'));var sox=require(_0xfb8f('0x8'));var csv=require(_0xfb8f('0x9'));var ejs=require(_0xfb8f('0xa'));var fs=require('fs');var fs_extra=require(_0xfb8f('0xb'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xfb8f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xfb8f('0xd'));var toCsv=require(_0xfb8f('0x9'));var querystring=require('querystring');var Papa=require(_0xfb8f('0xe'));var Redis=require(_0xfb8f('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xfb8f('0x10'));var config=require(_0xfb8f('0x11'));var licenseUtil=require(_0xfb8f('0x12'));var db=require(_0xfb8f('0x13'))['db'];function respondWithStatusCode(_0x44e3d7,_0x5ea3a2){_0x5ea3a2=_0x5ea3a2||0xcc;return function(_0x3e9bb2){if(_0x3e9bb2){return _0x44e3d7[_0xfb8f('0x14')](_0x5ea3a2);}return _0x44e3d7[_0xfb8f('0x15')](_0x5ea3a2)['end']();};}function respondWithResult(_0x1674e5,_0x54a53d){_0x54a53d=_0x54a53d||0xc8;return function(_0x3bc0dd){if(_0x3bc0dd){return _0x1674e5[_0xfb8f('0x15')](_0x54a53d)[_0xfb8f('0x16')](_0x3bc0dd);}};}function respondWithFilteredResult(_0x5857cf,_0x124eee){return function(_0x25c9fd){if(_0x25c9fd){var _0x34b221=typeof _0x124eee[_0xfb8f('0x17')]===_0xfb8f('0x18')&&typeof _0x124eee[_0xfb8f('0x19')]===_0xfb8f('0x18');var _0x3d663b=_0x25c9fd[_0xfb8f('0x1a')];var _0x456aee=_0x34b221?0x0:_0x124eee['offset'];var _0x4228b2=_0x34b221?_0x25c9fd['count']:_0x124eee[_0xfb8f('0x17')]+_0x124eee[_0xfb8f('0x19')];var _0x140f16;if(_0x4228b2>=_0x3d663b){_0x4228b2=_0x3d663b;_0x140f16=0xc8;}else{_0x140f16=0xce;}_0x5857cf[_0xfb8f('0x15')](_0x140f16);return _0x5857cf[_0xfb8f('0x1b')]('Content-Range',_0x456aee+'-'+_0x4228b2+'/'+_0x3d663b)[_0xfb8f('0x16')](_0x25c9fd);}return null;};}function patchUpdates(_0x33257a){return function(_0x1299d4){try{jsonpatch['apply'](_0x1299d4,_0x33257a,!![]);}catch(_0x114984){return BPromise['reject'](_0x114984);}return _0x1299d4['save']();};}function saveUpdates(_0x24ff02,_0x39d17e){return function(_0x245acc){if(_0x245acc){return _0x245acc[_0xfb8f('0x1c')](_0x24ff02)[_0xfb8f('0x1d')](function(_0x473ea3){return _0x473ea3;});}return null;};}function removeEntity(_0x1e9428,_0x5c2dc8){return function(_0x3c9929){if(_0x3c9929){return _0x3c9929[_0xfb8f('0x1e')]()['then'](function(){_0x1e9428[_0xfb8f('0x15')](0xcc)[_0xfb8f('0x1f')]();});}};}function handleEntityNotFound(_0x4491da,_0x1fcc04){return function(_0x49797f){if(!_0x49797f){_0x4491da['sendStatus'](0x194);}return _0x49797f;};}function handleError(_0x8e9f86,_0x5720b4){_0x5720b4=_0x5720b4||0x1f4;return function(_0x216fd7){logger[_0xfb8f('0x20')](_0x216fd7[_0xfb8f('0x21')]);if(_0x216fd7[_0xfb8f('0x22')]){delete _0x216fd7[_0xfb8f('0x22')];}_0x8e9f86[_0xfb8f('0x15')](_0x5720b4)[_0xfb8f('0x23')](_0x216fd7);};}exports['index']=function(_0x466cd8,_0x53a42e){var _0x243cbe={},_0x29f424={},_0x5caf3d={'count':0x0,'rows':[]};var _0x113ec1=_[_0xfb8f('0x24')](db[_0xfb8f('0x25')][_0xfb8f('0x26')],function(_0x2195ae){return{'name':_0x2195ae[_0xfb8f('0x27')],'type':_0x2195ae[_0xfb8f('0x28')]['key']};});_0x29f424[_0xfb8f('0x29')]=_[_0xfb8f('0x24')](_0x113ec1,'name');_0x29f424['query']=_[_0xfb8f('0x2a')](_0x466cd8['query']);_0x29f424[_0xfb8f('0x2b')]=_[_0xfb8f('0x2c')](_0x29f424[_0xfb8f('0x29')],_0x29f424[_0xfb8f('0x2d')]);_0x243cbe[_0xfb8f('0x2e')]=_[_0xfb8f('0x2c')](_0x29f424[_0xfb8f('0x29')],qs[_0xfb8f('0x2f')](_0x466cd8[_0xfb8f('0x2d')][_0xfb8f('0x2f')]));_0x243cbe['attributes']=_0x243cbe[_0xfb8f('0x2e')][_0xfb8f('0x30')]?_0x243cbe['attributes']:_0x29f424[_0xfb8f('0x29')];if(!_0x466cd8['query'][_0xfb8f('0x31')]('nolimit')){_0x243cbe['limit']=qs[_0xfb8f('0x19')](_0x466cd8[_0xfb8f('0x2d')][_0xfb8f('0x19')]);_0x243cbe[_0xfb8f('0x17')]=qs['offset'](_0x466cd8['query'][_0xfb8f('0x17')]);}_0x243cbe[_0xfb8f('0x32')]=qs[_0xfb8f('0x33')](_0x466cd8[_0xfb8f('0x2d')]['sort']);_0x243cbe['where']=qs[_0xfb8f('0x2b')](_[_0xfb8f('0x34')](_0x466cd8[_0xfb8f('0x2d')],_0x29f424[_0xfb8f('0x2b')]),_0x113ec1);if(_0x466cd8[_0xfb8f('0x2d')][_0xfb8f('0x35')]){_0x243cbe['where']=_['merge'](_0x243cbe[_0xfb8f('0x36')],{'$or':_[_0xfb8f('0x24')](_0x113ec1,function(_0x5e90ea){if(_0x5e90ea[_0xfb8f('0x28')]!==_0xfb8f('0x37')){var _0x42302e={};_0x42302e[_0x5e90ea[_0xfb8f('0x22')]]={'$like':'%'+_0x466cd8[_0xfb8f('0x2d')]['filter']+'%'};return _0x42302e;}})});}_0x243cbe=_['merge']({},_0x243cbe,_0x466cd8[_0xfb8f('0x38')]);var _0x226833={'where':_0x243cbe['where']};return db[_0xfb8f('0x25')][_0xfb8f('0x1a')](_0x226833)[_0xfb8f('0x1d')](function(_0x197a6d){_0x5caf3d['count']=_0x197a6d;if(_0x466cd8[_0xfb8f('0x2d')][_0xfb8f('0x39')]){_0x243cbe['include']=[{'all':!![]}];}return db[_0xfb8f('0x25')][_0xfb8f('0x3a')](_0x243cbe);})['then'](function(_0x46304d){_0x5caf3d['rows']=_0x46304d;return _0x5caf3d;})[_0xfb8f('0x1d')](respondWithFilteredResult(_0x53a42e,_0x243cbe))[_0xfb8f('0x3b')](handleError(_0x53a42e,null));};exports[_0xfb8f('0x3c')]=function(_0x516840,_0x4c21e5){var _0xdff1d={'raw':!![],'where':{'id':_0x516840[_0xfb8f('0x3d')]['id']}},_0x3a56b6={};_0x3a56b6[_0xfb8f('0x29')]=_[_0xfb8f('0x2a')](db['SmsTransferReport']['rawAttributes']);_0x3a56b6[_0xfb8f('0x2d')]=_[_0xfb8f('0x2a')](_0x516840[_0xfb8f('0x2d')]);_0x3a56b6['filters']=_['intersection'](_0x3a56b6[_0xfb8f('0x29')],_0x3a56b6[_0xfb8f('0x2d')]);_0xdff1d['attributes']=_[_0xfb8f('0x2c')](_0x3a56b6['model'],qs[_0xfb8f('0x2f')](_0x516840['query'][_0xfb8f('0x2f')]));_0xdff1d[_0xfb8f('0x2e')]=_0xdff1d[_0xfb8f('0x2e')][_0xfb8f('0x30')]?_0xdff1d[_0xfb8f('0x2e')]:_0x3a56b6[_0xfb8f('0x29')];if(_0x516840[_0xfb8f('0x2d')][_0xfb8f('0x39')]){_0xdff1d[_0xfb8f('0x3e')]=[{'all':!![]}];}_0xdff1d=_['merge']({},_0xdff1d,_0x516840['options']);return db['SmsTransferReport'][_0xfb8f('0x3f')](_0xdff1d)[_0xfb8f('0x1d')](handleEntityNotFound(_0x4c21e5,null))['then'](respondWithResult(_0x4c21e5,null))[_0xfb8f('0x3b')](handleError(_0x4c21e5,null));};exports['create']=function(_0x404e44,_0x343e23){return db['SmsTransferReport'][_0xfb8f('0x40')](_0x404e44[_0xfb8f('0x41')],{})[_0xfb8f('0x1d')](respondWithResult(_0x343e23,0xc9))[_0xfb8f('0x3b')](handleError(_0x343e23,null));};exports['update']=function(_0x3828bc,_0x5f0779){if(_0x3828bc[_0xfb8f('0x41')]['id']){delete _0x3828bc[_0xfb8f('0x41')]['id'];}return db['SmsTransferReport'][_0xfb8f('0x3f')]({'where':{'id':_0x3828bc[_0xfb8f('0x3d')]['id']}})['then'](handleEntityNotFound(_0x5f0779,null))['then'](saveUpdates(_0x3828bc[_0xfb8f('0x41')],null))[_0xfb8f('0x1d')](respondWithResult(_0x5f0779,null))[_0xfb8f('0x3b')](handleError(_0x5f0779,null));};exports[_0xfb8f('0x1e')]=function(_0x5f57d3,_0x2de4c0){return db['SmsTransferReport']['find']({'where':{'id':_0x5f57d3['params']['id']}})[_0xfb8f('0x1d')](handleEntityNotFound(_0x2de4c0,null))[_0xfb8f('0x1d')](removeEntity(_0x2de4c0,null))[_0xfb8f('0x3b')](handleError(_0x2de4c0,null));};exports['describe']=function(_0x72e987,_0x223fc2){return db['SmsTransferReport'][_0xfb8f('0x42')]()[_0xfb8f('0x1d')](respondWithResult(_0x223fc2,null))['catch'](handleError(_0x223fc2,null));};