Built motion from commit 85328c08.|2.5.50
[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 _0x3f15=['fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','includeAll','catch','params','include','options','find','create','body','destroy','describe','eml-format','rimraf','zip-dir','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','undefined','limit','count','offset','set','json','apply','save','update','then','error','stack','name','send','index','map','SmsTransferReport','rawAttributes'];(function(_0x33c888,_0x12cd0a){var _0x38c0b=function(_0x58f328){while(--_0x58f328){_0x33c888['push'](_0x33c888['shift']());}};_0x38c0b(++_0x12cd0a);}(_0x3f15,0xb1));var _0x53f1=function(_0x151160,_0x30993c){_0x151160=_0x151160-0x0;var _0x56b206=_0x3f15[_0x151160];return _0x56b206;};'use strict';var emlformat=require(_0x53f1('0x0'));var rimraf=require(_0x53f1('0x1'));var zipdir=require(_0x53f1('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x53f1('0x3'));var BPromise=require(_0x53f1('0x4'));var Mustache=require(_0x53f1('0x5'));var util=require('util');var path=require('path');var sox=require(_0x53f1('0x6'));var csv=require(_0x53f1('0x7'));var ejs=require(_0x53f1('0x8'));var fs=require('fs');var fs_extra=require(_0x53f1('0x9'));var _=require('lodash');var squel=require(_0x53f1('0xa'));var crypto=require(_0x53f1('0xb'));var jsforce=require(_0x53f1('0xc'));var deskjs=require(_0x53f1('0xd'));var toCsv=require(_0x53f1('0x7'));var querystring=require(_0x53f1('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x53f1('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x53f1('0x10'));var hardwareService=require(_0x53f1('0x11'));var logger=require(_0x53f1('0x12'))(_0x53f1('0x13'));var utils=require(_0x53f1('0x14'));var config=require(_0x53f1('0x15'));var licenseUtil=require(_0x53f1('0x16'));var db=require(_0x53f1('0x17'))['db'];function respondWithStatusCode(_0x26415d,_0x7cb77c){_0x7cb77c=_0x7cb77c||0xcc;return function(_0x394cc7){if(_0x394cc7){return _0x26415d[_0x53f1('0x18')](_0x7cb77c);}return _0x26415d[_0x53f1('0x19')](_0x7cb77c)[_0x53f1('0x1a')]();};}function respondWithResult(_0x1920cb,_0x1a88a0){_0x1a88a0=_0x1a88a0||0xc8;return function(_0x3be239){if(_0x3be239){return _0x1920cb['status'](_0x1a88a0)['json'](_0x3be239);}};}function respondWithFilteredResult(_0x807f67,_0x1ee04f){return function(_0x3d14a2){if(_0x3d14a2){var _0x2c8ff9=typeof _0x1ee04f['offset']===_0x53f1('0x1b')&&typeof _0x1ee04f[_0x53f1('0x1c')]===_0x53f1('0x1b');var _0x28a986=_0x3d14a2[_0x53f1('0x1d')];var _0x52d3e6=_0x2c8ff9?0x0:_0x1ee04f[_0x53f1('0x1e')];var _0x2d3a1a=_0x2c8ff9?_0x3d14a2[_0x53f1('0x1d')]:_0x1ee04f['offset']+_0x1ee04f['limit'];var _0x2035f4;if(_0x2d3a1a>=_0x28a986){_0x2d3a1a=_0x28a986;_0x2035f4=0xc8;}else{_0x2035f4=0xce;}_0x807f67[_0x53f1('0x19')](_0x2035f4);return _0x807f67[_0x53f1('0x1f')]('Content-Range',_0x52d3e6+'-'+_0x2d3a1a+'/'+_0x28a986)[_0x53f1('0x20')](_0x3d14a2);}return null;};}function patchUpdates(_0xf9a5f){return function(_0x108aba){try{jsonpatch[_0x53f1('0x21')](_0x108aba,_0xf9a5f,!![]);}catch(_0x1ceefe){return BPromise['reject'](_0x1ceefe);}return _0x108aba[_0x53f1('0x22')]();};}function saveUpdates(_0x4fcfe8,_0x5a0f6f){return function(_0x43e04f){if(_0x43e04f){return _0x43e04f[_0x53f1('0x23')](_0x4fcfe8)[_0x53f1('0x24')](function(_0x13915f){return _0x13915f;});}return null;};}function removeEntity(_0x164ed6,_0x1ec3c6){return function(_0x4f0118){if(_0x4f0118){return _0x4f0118['destroy']()['then'](function(){_0x164ed6[_0x53f1('0x19')](0xcc)[_0x53f1('0x1a')]();});}};}function handleEntityNotFound(_0x554ea8,_0x441a9e){return function(_0x415986){if(!_0x415986){_0x554ea8[_0x53f1('0x18')](0x194);}return _0x415986;};}function handleError(_0x469cb7,_0x4e06bf){_0x4e06bf=_0x4e06bf||0x1f4;return function(_0x298c67){logger[_0x53f1('0x25')](_0x298c67[_0x53f1('0x26')]);if(_0x298c67[_0x53f1('0x27')]){delete _0x298c67[_0x53f1('0x27')];}_0x469cb7[_0x53f1('0x19')](_0x4e06bf)[_0x53f1('0x28')](_0x298c67);};}exports[_0x53f1('0x29')]=function(_0x928694,_0x4d3060){var _0x546083={},_0x5d9ddc={},_0x49bd4a={'count':0x0,'rows':[]};var _0x4ac591=_[_0x53f1('0x2a')](db[_0x53f1('0x2b')][_0x53f1('0x2c')],function(_0x5a3280){return{'name':_0x5a3280[_0x53f1('0x2d')],'type':_0x5a3280[_0x53f1('0x2e')][_0x53f1('0x2f')]};});_0x5d9ddc[_0x53f1('0x30')]=_[_0x53f1('0x2a')](_0x4ac591,_0x53f1('0x27'));_0x5d9ddc[_0x53f1('0x31')]=_[_0x53f1('0x32')](_0x928694[_0x53f1('0x31')]);_0x5d9ddc[_0x53f1('0x33')]=_['intersection'](_0x5d9ddc[_0x53f1('0x30')],_0x5d9ddc['query']);_0x546083[_0x53f1('0x34')]=_[_0x53f1('0x35')](_0x5d9ddc[_0x53f1('0x30')],qs[_0x53f1('0x36')](_0x928694[_0x53f1('0x31')][_0x53f1('0x36')]));_0x546083[_0x53f1('0x34')]=_0x546083[_0x53f1('0x34')][_0x53f1('0x37')]?_0x546083[_0x53f1('0x34')]:_0x5d9ddc[_0x53f1('0x30')];if(!_0x928694[_0x53f1('0x31')][_0x53f1('0x38')](_0x53f1('0x39'))){_0x546083['limit']=qs['limit'](_0x928694[_0x53f1('0x31')][_0x53f1('0x1c')]);_0x546083[_0x53f1('0x1e')]=qs['offset'](_0x928694['query']['offset']);}_0x546083[_0x53f1('0x3a')]=qs[_0x53f1('0x3b')](_0x928694[_0x53f1('0x31')][_0x53f1('0x3b')]);_0x546083['where']=qs[_0x53f1('0x33')](_['pick'](_0x928694['query'],_0x5d9ddc['filters']),_0x4ac591);if(_0x928694[_0x53f1('0x31')][_0x53f1('0x3c')]){_0x546083[_0x53f1('0x3d')]=_[_0x53f1('0x3e')](_0x546083[_0x53f1('0x3d')],{'$or':_[_0x53f1('0x2a')](_0x4ac591,function(_0x5e35a2){if(_0x5e35a2[_0x53f1('0x2e')]!==_0x53f1('0x3f')){var _0x2494bf={};_0x2494bf[_0x5e35a2[_0x53f1('0x27')]]={'$like':'%'+_0x928694[_0x53f1('0x31')][_0x53f1('0x3c')]+'%'};return _0x2494bf;}})});}_0x546083=_[_0x53f1('0x3e')]({},_0x546083,_0x928694['options']);var _0x5a127e={'where':_0x546083['where']};return db[_0x53f1('0x2b')][_0x53f1('0x1d')](_0x5a127e)[_0x53f1('0x24')](function(_0xb3c7e5){_0x49bd4a[_0x53f1('0x1d')]=_0xb3c7e5;if(_0x928694[_0x53f1('0x31')][_0x53f1('0x40')]){_0x546083['include']=[{'all':!![]}];}return db[_0x53f1('0x2b')]['findAll'](_0x546083);})[_0x53f1('0x24')](function(_0x703347){_0x49bd4a['rows']=_0x703347;return _0x49bd4a;})['then'](respondWithFilteredResult(_0x4d3060,_0x546083))[_0x53f1('0x41')](handleError(_0x4d3060,null));};exports['show']=function(_0x118669,_0xeec34e){var _0x387888={'raw':!![],'where':{'id':_0x118669[_0x53f1('0x42')]['id']}},_0x5255bd={};_0x5255bd[_0x53f1('0x30')]=_['keys'](db[_0x53f1('0x2b')]['rawAttributes']);_0x5255bd['query']=_[_0x53f1('0x32')](_0x118669['query']);_0x5255bd[_0x53f1('0x33')]=_['intersection'](_0x5255bd[_0x53f1('0x30')],_0x5255bd[_0x53f1('0x31')]);_0x387888['attributes']=_[_0x53f1('0x35')](_0x5255bd[_0x53f1('0x30')],qs[_0x53f1('0x36')](_0x118669[_0x53f1('0x31')][_0x53f1('0x36')]));_0x387888[_0x53f1('0x34')]=_0x387888[_0x53f1('0x34')][_0x53f1('0x37')]?_0x387888[_0x53f1('0x34')]:_0x5255bd['model'];if(_0x118669[_0x53f1('0x31')][_0x53f1('0x40')]){_0x387888[_0x53f1('0x43')]=[{'all':!![]}];}_0x387888=_['merge']({},_0x387888,_0x118669[_0x53f1('0x44')]);return db[_0x53f1('0x2b')][_0x53f1('0x45')](_0x387888)['then'](handleEntityNotFound(_0xeec34e,null))['then'](respondWithResult(_0xeec34e,null))[_0x53f1('0x41')](handleError(_0xeec34e,null));};exports['create']=function(_0x5ecb2b,_0x547a48){return db[_0x53f1('0x2b')][_0x53f1('0x46')](_0x5ecb2b[_0x53f1('0x47')],{})[_0x53f1('0x24')](respondWithResult(_0x547a48,0xc9))[_0x53f1('0x41')](handleError(_0x547a48,null));};exports['update']=function(_0x28ca05,_0x43c47c){if(_0x28ca05[_0x53f1('0x47')]['id']){delete _0x28ca05[_0x53f1('0x47')]['id'];}return db[_0x53f1('0x2b')][_0x53f1('0x45')]({'where':{'id':_0x28ca05[_0x53f1('0x42')]['id']}})[_0x53f1('0x24')](handleEntityNotFound(_0x43c47c,null))[_0x53f1('0x24')](saveUpdates(_0x28ca05['body'],null))[_0x53f1('0x24')](respondWithResult(_0x43c47c,null))[_0x53f1('0x41')](handleError(_0x43c47c,null));};exports[_0x53f1('0x48')]=function(_0x128f8f,_0x4016d2){return db[_0x53f1('0x2b')][_0x53f1('0x45')]({'where':{'id':_0x128f8f[_0x53f1('0x42')]['id']}})[_0x53f1('0x24')](handleEntityNotFound(_0x4016d2,null))[_0x53f1('0x24')](removeEntity(_0x4016d2,null))['catch'](handleError(_0x4016d2,null));};exports[_0x53f1('0x49')]=function(_0x50f828,_0x2b87c6){return db['SmsTransferReport'][_0x53f1('0x49')]()[_0x53f1('0x24')](respondWithResult(_0x2b87c6,null))[_0x53f1('0x41')](handleError(_0x2b87c6,null));};