Built motion from commit 4c281f94.|2.6.31
[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 _0x311f=['type','model','keys','filters','intersection','attributes','fields','length','query','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','show','params','find','catch','create','body','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','limit','undefined','count','offset','set','Content-Range','apply','save','update','then','destroy','name','send','index','map','SmsTransferReport','rawAttributes','fieldName'];(function(_0x577bd7,_0x216ffa){var _0x5508b8=function(_0x2d1e34){while(--_0x2d1e34){_0x577bd7['push'](_0x577bd7['shift']());}};_0x5508b8(++_0x216ffa);}(_0x311f,0x188));var _0xf311=function(_0x4672d7,_0x378500){_0x4672d7=_0x4672d7-0x0;var _0x5cefb3=_0x311f[_0x4672d7];return _0x5cefb3;};'use strict';var emlformat=require(_0xf311('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf311('0x1'));var jsonpatch=require(_0xf311('0x2'));var rp=require(_0xf311('0x3'));var moment=require(_0xf311('0x4'));var BPromise=require(_0xf311('0x5'));var Mustache=require(_0xf311('0x6'));var util=require(_0xf311('0x7'));var path=require(_0xf311('0x8'));var sox=require('sox');var csv=require(_0xf311('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf311('0xa'));var _=require(_0xf311('0xb'));var squel=require(_0xf311('0xc'));var crypto=require(_0xf311('0xd'));var jsforce=require(_0xf311('0xe'));var deskjs=require(_0xf311('0xf'));var toCsv=require(_0xf311('0x9'));var querystring=require('querystring');var Papa=require(_0xf311('0x10'));var Redis=require(_0xf311('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xf311('0x12'));var as=require(_0xf311('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf311('0x14'))(_0xf311('0x15'));var utils=require(_0xf311('0x16'));var config=require(_0xf311('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xf311('0x18'))['db'];function respondWithStatusCode(_0x26dfca,_0x25249c){_0x25249c=_0x25249c||0xcc;return function(_0x434b36){if(_0x434b36){return _0x26dfca[_0xf311('0x19')](_0x25249c);}return _0x26dfca[_0xf311('0x1a')](_0x25249c)[_0xf311('0x1b')]();};}function respondWithResult(_0x28b75c,_0xa309d1){_0xa309d1=_0xa309d1||0xc8;return function(_0x4df120){if(_0x4df120){return _0x28b75c[_0xf311('0x1a')](_0xa309d1)['json'](_0x4df120);}};}function respondWithFilteredResult(_0x18955e,_0xc5caf5){return function(_0x1a4efb){if(_0x1a4efb){var _0x50ab4d=typeof _0xc5caf5['offset']==='undefined'&&typeof _0xc5caf5[_0xf311('0x1c')]===_0xf311('0x1d');var _0x41de5f=_0x1a4efb[_0xf311('0x1e')];var _0x3d10ff=_0x50ab4d?0x0:_0xc5caf5['offset'];var _0x438fb7=_0x50ab4d?_0x1a4efb[_0xf311('0x1e')]:_0xc5caf5[_0xf311('0x1f')]+_0xc5caf5['limit'];var _0xa00101;if(_0x438fb7>=_0x41de5f){_0x438fb7=_0x41de5f;_0xa00101=0xc8;}else{_0xa00101=0xce;}_0x18955e[_0xf311('0x1a')](_0xa00101);return _0x18955e[_0xf311('0x20')](_0xf311('0x21'),_0x3d10ff+'-'+_0x438fb7+'/'+_0x41de5f)['json'](_0x1a4efb);}return null;};}function patchUpdates(_0x4c0c64){return function(_0x493a60){try{jsonpatch[_0xf311('0x22')](_0x493a60,_0x4c0c64,!![]);}catch(_0x5e6472){return BPromise['reject'](_0x5e6472);}return _0x493a60[_0xf311('0x23')]();};}function saveUpdates(_0xe122f,_0x455738){return function(_0x11e105){if(_0x11e105){return _0x11e105[_0xf311('0x24')](_0xe122f)[_0xf311('0x25')](function(_0x2d6198){return _0x2d6198;});}return null;};}function removeEntity(_0x48f58a,_0x3f5bbe){return function(_0x336974){if(_0x336974){return _0x336974[_0xf311('0x26')]()[_0xf311('0x25')](function(){_0x48f58a['status'](0xcc)[_0xf311('0x1b')]();});}};}function handleEntityNotFound(_0x578b8c,_0x50d885){return function(_0x422780){if(!_0x422780){_0x578b8c[_0xf311('0x19')](0x194);}return _0x422780;};}function handleError(_0x366a99,_0x5f4807){_0x5f4807=_0x5f4807||0x1f4;return function(_0x59cfe4){logger['error'](_0x59cfe4['stack']);if(_0x59cfe4['name']){delete _0x59cfe4[_0xf311('0x27')];}_0x366a99[_0xf311('0x1a')](_0x5f4807)[_0xf311('0x28')](_0x59cfe4);};}exports[_0xf311('0x29')]=function(_0x55db90,_0x232346){var _0x116090={},_0x32c781={},_0x109df8={'count':0x0,'rows':[]};var _0x49a424=_[_0xf311('0x2a')](db[_0xf311('0x2b')][_0xf311('0x2c')],function(_0x428984){return{'name':_0x428984[_0xf311('0x2d')],'type':_0x428984[_0xf311('0x2e')]['key']};});_0x32c781[_0xf311('0x2f')]=_['map'](_0x49a424,'name');_0x32c781['query']=_[_0xf311('0x30')](_0x55db90['query']);_0x32c781[_0xf311('0x31')]=_[_0xf311('0x32')](_0x32c781['model'],_0x32c781['query']);_0x116090[_0xf311('0x33')]=_['intersection'](_0x32c781[_0xf311('0x2f')],qs[_0xf311('0x34')](_0x55db90['query'][_0xf311('0x34')]));_0x116090[_0xf311('0x33')]=_0x116090[_0xf311('0x33')][_0xf311('0x35')]?_0x116090[_0xf311('0x33')]:_0x32c781[_0xf311('0x2f')];if(!_0x55db90['query']['hasOwnProperty']('nolimit')){_0x116090['limit']=qs['limit'](_0x55db90[_0xf311('0x36')][_0xf311('0x1c')]);_0x116090[_0xf311('0x1f')]=qs[_0xf311('0x1f')](_0x55db90[_0xf311('0x36')][_0xf311('0x1f')]);}_0x116090[_0xf311('0x37')]=qs[_0xf311('0x38')](_0x55db90['query'][_0xf311('0x38')]);_0x116090[_0xf311('0x39')]=qs[_0xf311('0x31')](_[_0xf311('0x3a')](_0x55db90[_0xf311('0x36')],_0x32c781[_0xf311('0x31')]),_0x49a424);if(_0x55db90[_0xf311('0x36')][_0xf311('0x3b')]){_0x116090[_0xf311('0x39')]=_[_0xf311('0x3c')](_0x116090['where'],{'$or':_[_0xf311('0x2a')](_0x49a424,function(_0x588b98){if(_0x588b98[_0xf311('0x2e')]!==_0xf311('0x3d')){var _0xc8b775={};_0xc8b775[_0x588b98[_0xf311('0x27')]]={'$like':'%'+_0x55db90[_0xf311('0x36')][_0xf311('0x3b')]+'%'};return _0xc8b775;}})});}_0x116090=_['merge']({},_0x116090,_0x55db90[_0xf311('0x3e')]);var _0x3fd515={'where':_0x116090['where']};return db[_0xf311('0x2b')][_0xf311('0x1e')](_0x3fd515)[_0xf311('0x25')](function(_0x228182){_0x109df8[_0xf311('0x1e')]=_0x228182;if(_0x55db90[_0xf311('0x36')][_0xf311('0x3f')]){_0x116090[_0xf311('0x40')]=[{'all':!![]}];}return db['SmsTransferReport'][_0xf311('0x41')](_0x116090);})[_0xf311('0x25')](function(_0x5a8e03){_0x109df8['rows']=_0x5a8e03;return _0x109df8;})['then'](respondWithFilteredResult(_0x232346,_0x116090))['catch'](handleError(_0x232346,null));};exports[_0xf311('0x42')]=function(_0x13e9b9,_0xabbb8e){var _0x3eb7da={'raw':!![],'where':{'id':_0x13e9b9[_0xf311('0x43')]['id']}},_0x122d30={};_0x122d30['model']=_[_0xf311('0x30')](db[_0xf311('0x2b')][_0xf311('0x2c')]);_0x122d30[_0xf311('0x36')]=_[_0xf311('0x30')](_0x13e9b9['query']);_0x122d30[_0xf311('0x31')]=_['intersection'](_0x122d30[_0xf311('0x2f')],_0x122d30['query']);_0x3eb7da[_0xf311('0x33')]=_[_0xf311('0x32')](_0x122d30['model'],qs['fields'](_0x13e9b9[_0xf311('0x36')][_0xf311('0x34')]));_0x3eb7da['attributes']=_0x3eb7da[_0xf311('0x33')][_0xf311('0x35')]?_0x3eb7da['attributes']:_0x122d30[_0xf311('0x2f')];if(_0x13e9b9[_0xf311('0x36')][_0xf311('0x3f')]){_0x3eb7da[_0xf311('0x40')]=[{'all':!![]}];}_0x3eb7da=_['merge']({},_0x3eb7da,_0x13e9b9[_0xf311('0x3e')]);return db[_0xf311('0x2b')][_0xf311('0x44')](_0x3eb7da)[_0xf311('0x25')](handleEntityNotFound(_0xabbb8e,null))['then'](respondWithResult(_0xabbb8e,null))[_0xf311('0x45')](handleError(_0xabbb8e,null));};exports['create']=function(_0x5b017a,_0x259305){return db['SmsTransferReport'][_0xf311('0x46')](_0x5b017a['body'],{})[_0xf311('0x25')](respondWithResult(_0x259305,0xc9))['catch'](handleError(_0x259305,null));};exports[_0xf311('0x24')]=function(_0x28a909,_0x14b1bd){if(_0x28a909[_0xf311('0x47')]['id']){delete _0x28a909[_0xf311('0x47')]['id'];}return db['SmsTransferReport'][_0xf311('0x44')]({'where':{'id':_0x28a909[_0xf311('0x43')]['id']}})[_0xf311('0x25')](handleEntityNotFound(_0x14b1bd,null))[_0xf311('0x25')](saveUpdates(_0x28a909[_0xf311('0x47')],null))[_0xf311('0x25')](respondWithResult(_0x14b1bd,null))[_0xf311('0x45')](handleError(_0x14b1bd,null));};exports[_0xf311('0x26')]=function(_0x5b1892,_0x1ebe3f){return db[_0xf311('0x2b')]['find']({'where':{'id':_0x5b1892['params']['id']}})[_0xf311('0x25')](handleEntityNotFound(_0x1ebe3f,null))['then'](removeEntity(_0x1ebe3f,null))[_0xf311('0x45')](handleError(_0x1ebe3f,null));};exports[_0xf311('0x48')]=function(_0x1aead5,_0x41bdc4){return db[_0xf311('0x2b')][_0xf311('0x48')]()[_0xf311('0x25')](respondWithResult(_0x41bdc4,null))[_0xf311('0x45')](handleError(_0x41bdc4,null));};