Built motion from commit 3e059bc2.|2.5.32
[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 _0x50f1=['describe','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','destroy','error','stack','name','send','index','map','fieldName','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','SmsQueueReport','then','includeAll','include','findAll','rows','show','params','keys','rawAttributes','options','find','catch','create','body'];(function(_0x1fd92b,_0x42475b){var _0x40993e=function(_0x5c6dc9){while(--_0x5c6dc9){_0x1fd92b['push'](_0x1fd92b['shift']());}};_0x40993e(++_0x42475b);}(_0x50f1,0x13d));var _0x150f=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x50f1[_0x20a584];return _0x4b41a8;};'use strict';var emlformat=require(_0x150f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x150f('0x1'));var jsonpatch=require(_0x150f('0x2'));var rp=require(_0x150f('0x3'));var moment=require('moment');var BPromise=require(_0x150f('0x4'));var Mustache=require(_0x150f('0x5'));var util=require(_0x150f('0x6'));var path=require(_0x150f('0x7'));var sox=require('sox');var csv=require(_0x150f('0x8'));var ejs=require(_0x150f('0x9'));var fs=require('fs');var fs_extra=require(_0x150f('0xa'));var _=require('lodash');var squel=require(_0x150f('0xb'));var crypto=require(_0x150f('0xc'));var jsforce=require(_0x150f('0xd'));var deskjs=require(_0x150f('0xe'));var toCsv=require(_0x150f('0x8'));var querystring=require('querystring');var Papa=require(_0x150f('0xf'));var Redis=require(_0x150f('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x150f('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x150f('0x12'))(_0x150f('0x13'));var utils=require(_0x150f('0x14'));var config=require(_0x150f('0x15'));var licenseUtil=require(_0x150f('0x16'));var db=require(_0x150f('0x17'))['db'];function respondWithStatusCode(_0x2f5017,_0xc4e153){_0xc4e153=_0xc4e153||0xcc;return function(_0x27be21){if(_0x27be21){return _0x2f5017[_0x150f('0x18')](_0xc4e153);}return _0x2f5017['status'](_0xc4e153)[_0x150f('0x19')]();};}function respondWithResult(_0x202894,_0x317e84){_0x317e84=_0x317e84||0xc8;return function(_0x4ac7b8){if(_0x4ac7b8){return _0x202894[_0x150f('0x1a')](_0x317e84)[_0x150f('0x1b')](_0x4ac7b8);}};}function respondWithFilteredResult(_0x5b66ea,_0x154ddf){return function(_0x117853){if(_0x117853){var _0x11903d=typeof _0x154ddf['offset']===_0x150f('0x1c')&&typeof _0x154ddf[_0x150f('0x1d')]===_0x150f('0x1c');var _0x446cee=_0x117853[_0x150f('0x1e')];var _0x509599=_0x11903d?0x0:_0x154ddf[_0x150f('0x1f')];var _0x4767cf=_0x11903d?_0x117853[_0x150f('0x1e')]:_0x154ddf[_0x150f('0x1f')]+_0x154ddf['limit'];var _0x35724c;if(_0x4767cf>=_0x446cee){_0x4767cf=_0x446cee;_0x35724c=0xc8;}else{_0x35724c=0xce;}_0x5b66ea[_0x150f('0x1a')](_0x35724c);return _0x5b66ea[_0x150f('0x20')](_0x150f('0x21'),_0x509599+'-'+_0x4767cf+'/'+_0x446cee)[_0x150f('0x1b')](_0x117853);}return null;};}function patchUpdates(_0x4071ce){return function(_0x1b937c){try{jsonpatch[_0x150f('0x22')](_0x1b937c,_0x4071ce,!![]);}catch(_0x44ae3b){return BPromise[_0x150f('0x23')](_0x44ae3b);}return _0x1b937c[_0x150f('0x24')]();};}function saveUpdates(_0x5968cc,_0x5e18ab){return function(_0x17eb02){if(_0x17eb02){return _0x17eb02[_0x150f('0x25')](_0x5968cc)['then'](function(_0x193e1a){return _0x193e1a;});}return null;};}function removeEntity(_0x5ccf8f,_0x1f21d1){return function(_0x5f0fa5){if(_0x5f0fa5){return _0x5f0fa5[_0x150f('0x26')]()['then'](function(){_0x5ccf8f['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x3200a5,_0x2b78ca){return function(_0x5da23b){if(!_0x5da23b){_0x3200a5[_0x150f('0x18')](0x194);}return _0x5da23b;};}function handleError(_0x3ac1eb,_0x324271){_0x324271=_0x324271||0x1f4;return function(_0xf81734){logger[_0x150f('0x27')](_0xf81734[_0x150f('0x28')]);if(_0xf81734[_0x150f('0x29')]){delete _0xf81734[_0x150f('0x29')];}_0x3ac1eb[_0x150f('0x1a')](_0x324271)[_0x150f('0x2a')](_0xf81734);};}exports[_0x150f('0x2b')]=function(_0x5ef7cb,_0x445c90){var _0x2de71a={},_0x1696c7={},_0x4210ed={'count':0x0,'rows':[]};var _0x1ca5f4=_[_0x150f('0x2c')](db['SmsQueueReport']['rawAttributes'],function(_0x2ca5d8){return{'name':_0x2ca5d8[_0x150f('0x2d')],'type':_0x2ca5d8['type']['key']};});_0x1696c7[_0x150f('0x2e')]=_[_0x150f('0x2c')](_0x1ca5f4,'name');_0x1696c7[_0x150f('0x2f')]=_['keys'](_0x5ef7cb[_0x150f('0x2f')]);_0x1696c7[_0x150f('0x30')]=_['intersection'](_0x1696c7[_0x150f('0x2e')],_0x1696c7[_0x150f('0x2f')]);_0x2de71a['attributes']=_[_0x150f('0x31')](_0x1696c7[_0x150f('0x2e')],qs[_0x150f('0x32')](_0x5ef7cb['query'][_0x150f('0x32')]));_0x2de71a[_0x150f('0x33')]=_0x2de71a[_0x150f('0x33')][_0x150f('0x34')]?_0x2de71a[_0x150f('0x33')]:_0x1696c7[_0x150f('0x2e')];if(!_0x5ef7cb[_0x150f('0x2f')][_0x150f('0x35')](_0x150f('0x36'))){_0x2de71a[_0x150f('0x1d')]=qs['limit'](_0x5ef7cb['query']['limit']);_0x2de71a[_0x150f('0x1f')]=qs[_0x150f('0x1f')](_0x5ef7cb[_0x150f('0x2f')]['offset']);}_0x2de71a[_0x150f('0x37')]=qs[_0x150f('0x38')](_0x5ef7cb['query'][_0x150f('0x38')]);_0x2de71a[_0x150f('0x39')]=qs['filters'](_[_0x150f('0x3a')](_0x5ef7cb['query'],_0x1696c7[_0x150f('0x30')]),_0x1ca5f4);if(_0x5ef7cb[_0x150f('0x2f')][_0x150f('0x3b')]){_0x2de71a[_0x150f('0x39')]=_[_0x150f('0x3c')](_0x2de71a[_0x150f('0x39')],{'$or':_['map'](_0x1ca5f4,function(_0x4d1bb8){if(_0x4d1bb8[_0x150f('0x3d')]!==_0x150f('0x3e')){var _0x54bfff={};_0x54bfff[_0x4d1bb8[_0x150f('0x29')]]={'$like':'%'+_0x5ef7cb[_0x150f('0x2f')]['filter']+'%'};return _0x54bfff;}})});}_0x2de71a=_[_0x150f('0x3c')]({},_0x2de71a,_0x5ef7cb['options']);var _0x1d9a1e={'where':_0x2de71a[_0x150f('0x39')]};return db[_0x150f('0x3f')]['count'](_0x1d9a1e)[_0x150f('0x40')](function(_0x60eda5){_0x4210ed[_0x150f('0x1e')]=_0x60eda5;if(_0x5ef7cb['query'][_0x150f('0x41')]){_0x2de71a[_0x150f('0x42')]=[{'all':!![]}];}return db[_0x150f('0x3f')][_0x150f('0x43')](_0x2de71a);})[_0x150f('0x40')](function(_0x3b5377){_0x4210ed[_0x150f('0x44')]=_0x3b5377;return _0x4210ed;})[_0x150f('0x40')](respondWithFilteredResult(_0x445c90,_0x2de71a))['catch'](handleError(_0x445c90,null));};exports[_0x150f('0x45')]=function(_0x2f1966,_0x58d109){var _0x380f4e={'raw':!![],'where':{'id':_0x2f1966[_0x150f('0x46')]['id']}},_0xb813bc={};_0xb813bc[_0x150f('0x2e')]=_[_0x150f('0x47')](db[_0x150f('0x3f')][_0x150f('0x48')]);_0xb813bc[_0x150f('0x2f')]=_[_0x150f('0x47')](_0x2f1966['query']);_0xb813bc['filters']=_[_0x150f('0x31')](_0xb813bc[_0x150f('0x2e')],_0xb813bc[_0x150f('0x2f')]);_0x380f4e['attributes']=_[_0x150f('0x31')](_0xb813bc[_0x150f('0x2e')],qs[_0x150f('0x32')](_0x2f1966[_0x150f('0x2f')][_0x150f('0x32')]));_0x380f4e[_0x150f('0x33')]=_0x380f4e[_0x150f('0x33')][_0x150f('0x34')]?_0x380f4e['attributes']:_0xb813bc[_0x150f('0x2e')];if(_0x2f1966[_0x150f('0x2f')]['includeAll']){_0x380f4e['include']=[{'all':!![]}];}_0x380f4e=_[_0x150f('0x3c')]({},_0x380f4e,_0x2f1966[_0x150f('0x49')]);return db[_0x150f('0x3f')][_0x150f('0x4a')](_0x380f4e)['then'](handleEntityNotFound(_0x58d109,null))['then'](respondWithResult(_0x58d109,null))[_0x150f('0x4b')](handleError(_0x58d109,null));};exports['create']=function(_0x2a7ecd,_0x51c663){return db[_0x150f('0x3f')][_0x150f('0x4c')](_0x2a7ecd[_0x150f('0x4d')],{})['then'](respondWithResult(_0x51c663,0xc9))[_0x150f('0x4b')](handleError(_0x51c663,null));};exports[_0x150f('0x25')]=function(_0x7422cf,_0x39c7a7){if(_0x7422cf['body']['id']){delete _0x7422cf[_0x150f('0x4d')]['id'];}return db[_0x150f('0x3f')][_0x150f('0x4a')]({'where':{'id':_0x7422cf[_0x150f('0x46')]['id']}})['then'](handleEntityNotFound(_0x39c7a7,null))['then'](saveUpdates(_0x7422cf[_0x150f('0x4d')],null))[_0x150f('0x40')](respondWithResult(_0x39c7a7,null))[_0x150f('0x4b')](handleError(_0x39c7a7,null));};exports[_0x150f('0x26')]=function(_0x28f298,_0x5bee87){return db['SmsQueueReport'][_0x150f('0x4a')]({'where':{'id':_0x28f298[_0x150f('0x46')]['id']}})[_0x150f('0x40')](handleEntityNotFound(_0x5bee87,null))['then'](removeEntity(_0x5bee87,null))['catch'](handleError(_0x5bee87,null));};exports[_0x150f('0x4e')]=function(_0x35b73d,_0x14cb62){return db[_0x150f('0x3f')][_0x150f('0x4e')]()['then'](respondWithResult(_0x14cb62,null))[_0x150f('0x4b')](handleError(_0x14cb62,null));};