169648c20fcca0c924f452c62a6cef39be894126
[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 _0xf176=['sort','where','pick','filter','merge','VIRTUAL','options','SmsQueueReport','includeAll','include','rows','catch','show','params','find','create','body','update','describe','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','jsforce','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','then','destroy','end','sendStatus','error','stack','name','send','index','map','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order'];(function(_0x819464,_0x46fc91){var _0x49dcc0=function(_0x36b2b2){while(--_0x36b2b2){_0x819464['push'](_0x819464['shift']());}};_0x49dcc0(++_0x46fc91);}(_0xf176,0x185));var _0x6f17=function(_0x424b2a,_0xf4f64b){_0x424b2a=_0x424b2a-0x0;var _0x8d54b7=_0xf176[_0x424b2a];return _0x8d54b7;};'use strict';var emlformat=require(_0x6f17('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x6f17('0x1'));var rp=require(_0x6f17('0x2'));var moment=require(_0x6f17('0x3'));var BPromise=require(_0x6f17('0x4'));var Mustache=require(_0x6f17('0x5'));var util=require(_0x6f17('0x6'));var path=require(_0x6f17('0x7'));var sox=require(_0x6f17('0x8'));var csv=require(_0x6f17('0x9'));var ejs=require(_0x6f17('0xa'));var fs=require('fs');var fs_extra=require(_0x6f17('0xb'));var _=require('lodash');var squel=require(_0x6f17('0xc'));var crypto=require('crypto');var jsforce=require(_0x6f17('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x6f17('0x9'));var querystring=require('querystring');var Papa=require(_0x6f17('0xe'));var Redis=require(_0x6f17('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x6f17('0x10'));var as=require(_0x6f17('0x11'));var hardwareService=require(_0x6f17('0x12'));var logger=require(_0x6f17('0x13'))('api');var utils=require(_0x6f17('0x14'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x6f17('0x15'))['db'];function respondWithStatusCode(_0x12c231,_0x33d664){_0x33d664=_0x33d664||0xcc;return function(_0x364c5b){if(_0x364c5b){return _0x12c231['sendStatus'](_0x33d664);}return _0x12c231[_0x6f17('0x16')](_0x33d664)['end']();};}function respondWithResult(_0xde491e,_0x4f8099){_0x4f8099=_0x4f8099||0xc8;return function(_0x50aa12){if(_0x50aa12){return _0xde491e[_0x6f17('0x16')](_0x4f8099)[_0x6f17('0x17')](_0x50aa12);}};}function respondWithFilteredResult(_0xa40e2a,_0x2378b6){return function(_0x22728f){if(_0x22728f){var _0x46f538=typeof _0x2378b6[_0x6f17('0x18')]===_0x6f17('0x19')&&typeof _0x2378b6[_0x6f17('0x1a')]===_0x6f17('0x19');var _0x450b1e=_0x22728f['count'];var _0x36e932=_0x46f538?0x0:_0x2378b6[_0x6f17('0x18')];var _0x411fea=_0x46f538?_0x22728f[_0x6f17('0x1b')]:_0x2378b6[_0x6f17('0x18')]+_0x2378b6[_0x6f17('0x1a')];var _0x2fd768;if(_0x411fea>=_0x450b1e){_0x411fea=_0x450b1e;_0x2fd768=0xc8;}else{_0x2fd768=0xce;}_0xa40e2a['status'](_0x2fd768);return _0xa40e2a[_0x6f17('0x1c')](_0x6f17('0x1d'),_0x36e932+'-'+_0x411fea+'/'+_0x450b1e)[_0x6f17('0x17')](_0x22728f);}return null;};}function patchUpdates(_0x33f852){return function(_0x1172b8){try{jsonpatch[_0x6f17('0x1e')](_0x1172b8,_0x33f852,!![]);}catch(_0x103a4a){return BPromise['reject'](_0x103a4a);}return _0x1172b8[_0x6f17('0x1f')]();};}function saveUpdates(_0x4da213,_0x3e3c06){return function(_0x2744a7){if(_0x2744a7){return _0x2744a7['update'](_0x4da213)[_0x6f17('0x20')](function(_0x3ce420){return _0x3ce420;});}return null;};}function removeEntity(_0x30cacb,_0x4e3ca7){return function(_0x56f2ac){if(_0x56f2ac){return _0x56f2ac[_0x6f17('0x21')]()['then'](function(){_0x30cacb[_0x6f17('0x16')](0xcc)[_0x6f17('0x22')]();});}};}function handleEntityNotFound(_0x345a1e,_0x4fc84c){return function(_0x41aae3){if(!_0x41aae3){_0x345a1e[_0x6f17('0x23')](0x194);}return _0x41aae3;};}function handleError(_0x3fb19c,_0x3d3167){_0x3d3167=_0x3d3167||0x1f4;return function(_0x7e6607){logger[_0x6f17('0x24')](_0x7e6607[_0x6f17('0x25')]);if(_0x7e6607['name']){delete _0x7e6607[_0x6f17('0x26')];}_0x3fb19c[_0x6f17('0x16')](_0x3d3167)[_0x6f17('0x27')](_0x7e6607);};}exports[_0x6f17('0x28')]=function(_0x5e6777,_0x575012){var _0x24c7df={},_0x21ec9b={},_0x3c80fb={'count':0x0,'rows':[]};var _0x4e2ac6=_[_0x6f17('0x29')](db['SmsQueueReport'][_0x6f17('0x2a')],function(_0x3255f8){return{'name':_0x3255f8['fieldName'],'type':_0x3255f8[_0x6f17('0x2b')][_0x6f17('0x2c')]};});_0x21ec9b[_0x6f17('0x2d')]=_['map'](_0x4e2ac6,_0x6f17('0x26'));_0x21ec9b[_0x6f17('0x2e')]=_[_0x6f17('0x2f')](_0x5e6777['query']);_0x21ec9b[_0x6f17('0x30')]=_[_0x6f17('0x31')](_0x21ec9b[_0x6f17('0x2d')],_0x21ec9b['query']);_0x24c7df[_0x6f17('0x32')]=_[_0x6f17('0x31')](_0x21ec9b[_0x6f17('0x2d')],qs['fields'](_0x5e6777['query'][_0x6f17('0x33')]));_0x24c7df[_0x6f17('0x32')]=_0x24c7df[_0x6f17('0x32')][_0x6f17('0x34')]?_0x24c7df['attributes']:_0x21ec9b[_0x6f17('0x2d')];if(!_0x5e6777[_0x6f17('0x2e')][_0x6f17('0x35')]('nolimit')){_0x24c7df[_0x6f17('0x1a')]=qs[_0x6f17('0x1a')](_0x5e6777['query']['limit']);_0x24c7df[_0x6f17('0x18')]=qs[_0x6f17('0x18')](_0x5e6777[_0x6f17('0x2e')][_0x6f17('0x18')]);}_0x24c7df[_0x6f17('0x36')]=qs[_0x6f17('0x37')](_0x5e6777[_0x6f17('0x2e')][_0x6f17('0x37')]);_0x24c7df[_0x6f17('0x38')]=qs[_0x6f17('0x30')](_[_0x6f17('0x39')](_0x5e6777['query'],_0x21ec9b[_0x6f17('0x30')]),_0x4e2ac6);if(_0x5e6777['query'][_0x6f17('0x3a')]){_0x24c7df[_0x6f17('0x38')]=_[_0x6f17('0x3b')](_0x24c7df[_0x6f17('0x38')],{'$or':_['map'](_0x4e2ac6,function(_0x48fd87){if(_0x48fd87[_0x6f17('0x2b')]!==_0x6f17('0x3c')){var _0x489647={};_0x489647[_0x48fd87[_0x6f17('0x26')]]={'$like':'%'+_0x5e6777[_0x6f17('0x2e')][_0x6f17('0x3a')]+'%'};return _0x489647;}})});}_0x24c7df=_[_0x6f17('0x3b')]({},_0x24c7df,_0x5e6777[_0x6f17('0x3d')]);var _0x59df16={'where':_0x24c7df[_0x6f17('0x38')]};return db[_0x6f17('0x3e')][_0x6f17('0x1b')](_0x59df16)[_0x6f17('0x20')](function(_0x264a06){_0x3c80fb[_0x6f17('0x1b')]=_0x264a06;if(_0x5e6777[_0x6f17('0x2e')][_0x6f17('0x3f')]){_0x24c7df[_0x6f17('0x40')]=[{'all':!![]}];}return db[_0x6f17('0x3e')]['findAll'](_0x24c7df);})[_0x6f17('0x20')](function(_0x18d786){_0x3c80fb[_0x6f17('0x41')]=_0x18d786;return _0x3c80fb;})[_0x6f17('0x20')](respondWithFilteredResult(_0x575012,_0x24c7df))[_0x6f17('0x42')](handleError(_0x575012,null));};exports[_0x6f17('0x43')]=function(_0x4188fa,_0x43f7bf){var _0x2ad444={'raw':!![],'where':{'id':_0x4188fa[_0x6f17('0x44')]['id']}},_0x5773e9={};_0x5773e9['model']=_[_0x6f17('0x2f')](db[_0x6f17('0x3e')]['rawAttributes']);_0x5773e9[_0x6f17('0x2e')]=_[_0x6f17('0x2f')](_0x4188fa['query']);_0x5773e9[_0x6f17('0x30')]=_['intersection'](_0x5773e9[_0x6f17('0x2d')],_0x5773e9[_0x6f17('0x2e')]);_0x2ad444[_0x6f17('0x32')]=_['intersection'](_0x5773e9[_0x6f17('0x2d')],qs[_0x6f17('0x33')](_0x4188fa[_0x6f17('0x2e')]['fields']));_0x2ad444[_0x6f17('0x32')]=_0x2ad444[_0x6f17('0x32')][_0x6f17('0x34')]?_0x2ad444[_0x6f17('0x32')]:_0x5773e9['model'];if(_0x4188fa[_0x6f17('0x2e')][_0x6f17('0x3f')]){_0x2ad444[_0x6f17('0x40')]=[{'all':!![]}];}_0x2ad444=_[_0x6f17('0x3b')]({},_0x2ad444,_0x4188fa[_0x6f17('0x3d')]);return db['SmsQueueReport'][_0x6f17('0x45')](_0x2ad444)['then'](handleEntityNotFound(_0x43f7bf,null))[_0x6f17('0x20')](respondWithResult(_0x43f7bf,null))[_0x6f17('0x42')](handleError(_0x43f7bf,null));};exports[_0x6f17('0x46')]=function(_0x4f9f6f,_0x372854){return db[_0x6f17('0x3e')][_0x6f17('0x46')](_0x4f9f6f[_0x6f17('0x47')],{})[_0x6f17('0x20')](respondWithResult(_0x372854,0xc9))['catch'](handleError(_0x372854,null));};exports[_0x6f17('0x48')]=function(_0x255f78,_0x552633){if(_0x255f78[_0x6f17('0x47')]['id']){delete _0x255f78[_0x6f17('0x47')]['id'];}return db['SmsQueueReport']['find']({'where':{'id':_0x255f78[_0x6f17('0x44')]['id']}})[_0x6f17('0x20')](handleEntityNotFound(_0x552633,null))['then'](saveUpdates(_0x255f78['body'],null))[_0x6f17('0x20')](respondWithResult(_0x552633,null))[_0x6f17('0x42')](handleError(_0x552633,null));};exports[_0x6f17('0x21')]=function(_0x506584,_0x74a5e8){return db['SmsQueueReport'][_0x6f17('0x45')]({'where':{'id':_0x506584[_0x6f17('0x44')]['id']}})[_0x6f17('0x20')](handleEntityNotFound(_0x74a5e8,null))[_0x6f17('0x20')](removeEntity(_0x74a5e8,null))[_0x6f17('0x42')](handleError(_0x74a5e8,null));};exports['describe']=function(_0x277a33,_0x2fc9b3){return db[_0x6f17('0x3e')][_0x6f17('0x49')]()[_0x6f17('0x20')](respondWithResult(_0x2fc9b3,null))[_0x6f17('0x42')](handleError(_0x2fc9b3,null));};