Built motion from commit f7863d46.|2.5.41
[motion2.git] / server / api / smsQueueReport / smsQueueReport.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 _0x6fce=['include','findAll','catch','show','params','includeAll','find','body','describe','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','sox','to-csv','fs-extra','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','error','name','send','index','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','SmsQueueReport'];(function(_0x13a102,_0x7f6c67){var _0x3a37d2=function(_0x418744){while(--_0x418744){_0x13a102['push'](_0x13a102['shift']());}};_0x3a37d2(++_0x7f6c67);}(_0x6fce,0x12d));var _0xe6fc=function(_0x68c979,_0x431cff){_0x68c979=_0x68c979-0x0;var _0x4f0001=_0x6fce[_0x68c979];return _0x4f0001;};'use strict';var emlformat=require(_0xe6fc('0x0'));var rimraf=require(_0xe6fc('0x1'));var zipdir=require(_0xe6fc('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe6fc('0x3'));var moment=require('moment');var BPromise=require(_0xe6fc('0x4'));var Mustache=require(_0xe6fc('0x5'));var util=require('util');var path=require('path');var sox=require(_0xe6fc('0x6'));var csv=require(_0xe6fc('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xe6fc('0x8'));var _=require(_0xe6fc('0x9'));var squel=require(_0xe6fc('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xe6fc('0xb'));var toCsv=require(_0xe6fc('0x7'));var querystring=require('querystring');var Papa=require(_0xe6fc('0xc'));var Redis=require(_0xe6fc('0xd'));var authService=require(_0xe6fc('0xe'));var qs=require(_0xe6fc('0xf'));var as=require(_0xe6fc('0x10'));var hardwareService=require(_0xe6fc('0x11'));var logger=require(_0xe6fc('0x12'))(_0xe6fc('0x13'));var utils=require(_0xe6fc('0x14'));var config=require(_0xe6fc('0x15'));var licenseUtil=require(_0xe6fc('0x16'));var db=require(_0xe6fc('0x17'))['db'];function respondWithStatusCode(_0x5cfbcf,_0x2e714d){_0x2e714d=_0x2e714d||0xcc;return function(_0x545ebe){if(_0x545ebe){return _0x5cfbcf[_0xe6fc('0x18')](_0x2e714d);}return _0x5cfbcf[_0xe6fc('0x19')](_0x2e714d)[_0xe6fc('0x1a')]();};}function respondWithResult(_0x38ea70,_0x3162ec){_0x3162ec=_0x3162ec||0xc8;return function(_0x50375e){if(_0x50375e){return _0x38ea70[_0xe6fc('0x19')](_0x3162ec)[_0xe6fc('0x1b')](_0x50375e);}};}function respondWithFilteredResult(_0x5f5582,_0x8ff381){return function(_0x2b0b64){if(_0x2b0b64){var _0x1c0d4e=typeof _0x8ff381[_0xe6fc('0x1c')]==='undefined'&&typeof _0x8ff381[_0xe6fc('0x1d')]==='undefined';var _0x32e022=_0x2b0b64[_0xe6fc('0x1e')];var _0x60ec23=_0x1c0d4e?0x0:_0x8ff381[_0xe6fc('0x1c')];var _0x146e63=_0x1c0d4e?_0x2b0b64[_0xe6fc('0x1e')]:_0x8ff381['offset']+_0x8ff381['limit'];var _0x2ade9f;if(_0x146e63>=_0x32e022){_0x146e63=_0x32e022;_0x2ade9f=0xc8;}else{_0x2ade9f=0xce;}_0x5f5582['status'](_0x2ade9f);return _0x5f5582[_0xe6fc('0x1f')](_0xe6fc('0x20'),_0x60ec23+'-'+_0x146e63+'/'+_0x32e022)['json'](_0x2b0b64);}return null;};}function patchUpdates(_0x411a24){return function(_0xc85820){try{jsonpatch[_0xe6fc('0x21')](_0xc85820,_0x411a24,!![]);}catch(_0x1c7377){return BPromise[_0xe6fc('0x22')](_0x1c7377);}return _0xc85820[_0xe6fc('0x23')]();};}function saveUpdates(_0x15a8ba,_0x51749a){return function(_0x2920f4){if(_0x2920f4){return _0x2920f4[_0xe6fc('0x24')](_0x15a8ba)[_0xe6fc('0x25')](function(_0x5a9a41){return _0x5a9a41;});}return null;};}function removeEntity(_0x5a02a0,_0x37e5e5){return function(_0x582f8){if(_0x582f8){return _0x582f8[_0xe6fc('0x26')]()[_0xe6fc('0x25')](function(){_0x5a02a0[_0xe6fc('0x19')](0xcc)[_0xe6fc('0x1a')]();});}};}function handleEntityNotFound(_0x25113b,_0x4f4bae){return function(_0x7d8292){if(!_0x7d8292){_0x25113b[_0xe6fc('0x18')](0x194);}return _0x7d8292;};}function handleError(_0x484d67,_0x79f1cd){_0x79f1cd=_0x79f1cd||0x1f4;return function(_0x31ee99){logger[_0xe6fc('0x27')](_0x31ee99['stack']);if(_0x31ee99[_0xe6fc('0x28')]){delete _0x31ee99[_0xe6fc('0x28')];}_0x484d67[_0xe6fc('0x19')](_0x79f1cd)[_0xe6fc('0x29')](_0x31ee99);};}exports[_0xe6fc('0x2a')]=function(_0xfb8948,_0x5b7a31){var _0x144460={},_0x5567b4={},_0x2181ed={'count':0x0,'rows':[]};var _0x23d61d=_[_0xe6fc('0x2b')](db['SmsQueueReport'][_0xe6fc('0x2c')],function(_0xde81d5){return{'name':_0xde81d5[_0xe6fc('0x2d')],'type':_0xde81d5[_0xe6fc('0x2e')]['key']};});_0x5567b4[_0xe6fc('0x2f')]=_['map'](_0x23d61d,_0xe6fc('0x28'));_0x5567b4[_0xe6fc('0x30')]=_[_0xe6fc('0x31')](_0xfb8948[_0xe6fc('0x30')]);_0x5567b4[_0xe6fc('0x32')]=_[_0xe6fc('0x33')](_0x5567b4[_0xe6fc('0x2f')],_0x5567b4[_0xe6fc('0x30')]);_0x144460['attributes']=_[_0xe6fc('0x33')](_0x5567b4[_0xe6fc('0x2f')],qs[_0xe6fc('0x34')](_0xfb8948[_0xe6fc('0x30')][_0xe6fc('0x34')]));_0x144460[_0xe6fc('0x35')]=_0x144460[_0xe6fc('0x35')][_0xe6fc('0x36')]?_0x144460[_0xe6fc('0x35')]:_0x5567b4[_0xe6fc('0x2f')];if(!_0xfb8948[_0xe6fc('0x30')][_0xe6fc('0x37')](_0xe6fc('0x38'))){_0x144460['limit']=qs[_0xe6fc('0x1d')](_0xfb8948[_0xe6fc('0x30')][_0xe6fc('0x1d')]);_0x144460[_0xe6fc('0x1c')]=qs[_0xe6fc('0x1c')](_0xfb8948[_0xe6fc('0x30')][_0xe6fc('0x1c')]);}_0x144460[_0xe6fc('0x39')]=qs[_0xe6fc('0x3a')](_0xfb8948[_0xe6fc('0x30')]['sort']);_0x144460[_0xe6fc('0x3b')]=qs['filters'](_['pick'](_0xfb8948['query'],_0x5567b4[_0xe6fc('0x32')]),_0x23d61d);if(_0xfb8948[_0xe6fc('0x30')][_0xe6fc('0x3c')]){_0x144460[_0xe6fc('0x3b')]=_[_0xe6fc('0x3d')](_0x144460[_0xe6fc('0x3b')],{'$or':_['map'](_0x23d61d,function(_0x180c6e){if(_0x180c6e['type']!=='VIRTUAL'){var _0x2c2f84={};_0x2c2f84[_0x180c6e['name']]={'$like':'%'+_0xfb8948['query']['filter']+'%'};return _0x2c2f84;}})});}_0x144460=_[_0xe6fc('0x3d')]({},_0x144460,_0xfb8948[_0xe6fc('0x3e')]);var _0x4c5de7={'where':_0x144460[_0xe6fc('0x3b')]};return db[_0xe6fc('0x3f')]['count'](_0x4c5de7)['then'](function(_0x3955ba){_0x2181ed[_0xe6fc('0x1e')]=_0x3955ba;if(_0xfb8948['query']['includeAll']){_0x144460[_0xe6fc('0x40')]=[{'all':!![]}];}return db[_0xe6fc('0x3f')][_0xe6fc('0x41')](_0x144460);})[_0xe6fc('0x25')](function(_0x11502a){_0x2181ed['rows']=_0x11502a;return _0x2181ed;})['then'](respondWithFilteredResult(_0x5b7a31,_0x144460))[_0xe6fc('0x42')](handleError(_0x5b7a31,null));};exports[_0xe6fc('0x43')]=function(_0x4aa5e1,_0x42de4d){var _0x5b9bac={'raw':!![],'where':{'id':_0x4aa5e1[_0xe6fc('0x44')]['id']}},_0x22471d={};_0x22471d[_0xe6fc('0x2f')]=_['keys'](db[_0xe6fc('0x3f')][_0xe6fc('0x2c')]);_0x22471d[_0xe6fc('0x30')]=_[_0xe6fc('0x31')](_0x4aa5e1['query']);_0x22471d['filters']=_['intersection'](_0x22471d[_0xe6fc('0x2f')],_0x22471d[_0xe6fc('0x30')]);_0x5b9bac[_0xe6fc('0x35')]=_[_0xe6fc('0x33')](_0x22471d[_0xe6fc('0x2f')],qs[_0xe6fc('0x34')](_0x4aa5e1['query'][_0xe6fc('0x34')]));_0x5b9bac[_0xe6fc('0x35')]=_0x5b9bac[_0xe6fc('0x35')]['length']?_0x5b9bac[_0xe6fc('0x35')]:_0x22471d[_0xe6fc('0x2f')];if(_0x4aa5e1['query'][_0xe6fc('0x45')]){_0x5b9bac[_0xe6fc('0x40')]=[{'all':!![]}];}_0x5b9bac=_[_0xe6fc('0x3d')]({},_0x5b9bac,_0x4aa5e1[_0xe6fc('0x3e')]);return db[_0xe6fc('0x3f')][_0xe6fc('0x46')](_0x5b9bac)[_0xe6fc('0x25')](handleEntityNotFound(_0x42de4d,null))[_0xe6fc('0x25')](respondWithResult(_0x42de4d,null))[_0xe6fc('0x42')](handleError(_0x42de4d,null));};exports['create']=function(_0x22ab41,_0x1610ba){return db[_0xe6fc('0x3f')]['create'](_0x22ab41[_0xe6fc('0x47')],{})['then'](respondWithResult(_0x1610ba,0xc9))[_0xe6fc('0x42')](handleError(_0x1610ba,null));};exports['update']=function(_0xffe4f1,_0x7de27c){if(_0xffe4f1[_0xe6fc('0x47')]['id']){delete _0xffe4f1[_0xe6fc('0x47')]['id'];}return db[_0xe6fc('0x3f')]['find']({'where':{'id':_0xffe4f1[_0xe6fc('0x44')]['id']}})[_0xe6fc('0x25')](handleEntityNotFound(_0x7de27c,null))[_0xe6fc('0x25')](saveUpdates(_0xffe4f1[_0xe6fc('0x47')],null))['then'](respondWithResult(_0x7de27c,null))[_0xe6fc('0x42')](handleError(_0x7de27c,null));};exports[_0xe6fc('0x26')]=function(_0x11bd5d,_0x25cf67){return db[_0xe6fc('0x3f')][_0xe6fc('0x46')]({'where':{'id':_0x11bd5d[_0xe6fc('0x44')]['id']}})[_0xe6fc('0x25')](handleEntityNotFound(_0x25cf67,null))[_0xe6fc('0x25')](removeEntity(_0x25cf67,null))[_0xe6fc('0x42')](handleError(_0x25cf67,null));};exports['describe']=function(_0x5e490c,_0xf243a7){return db['SmsQueueReport'][_0xe6fc('0x48')]()[_0xe6fc('0x25')](respondWithResult(_0xf243a7,null))[_0xe6fc('0x42')](handleError(_0xf243a7,null));};