Built motion from commit 3c2ce842.|2.6.31
[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 _0xcb5f=['destroy','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','apply','save','update','then','error','name','send','index','SmsQueueReport','rawAttributes','fieldName','type','key','map','query','keys','filters','model','attributes','fields','length','nolimit','order','sort','where','pick','filter','VIRTUAL','options','rows','catch','show','params','includeAll','merge','create','body','find'];(function(_0x370dfe,_0x492b81){var _0x4a1f30=function(_0x442d81){while(--_0x442d81){_0x370dfe['push'](_0x370dfe['shift']());}};_0x4a1f30(++_0x492b81);}(_0xcb5f,0x174));var _0xfcb5=function(_0x40a045,_0x516f0e){_0x40a045=_0x40a045-0x0;var _0x1a687c=_0xcb5f[_0x40a045];return _0x1a687c;};'use strict';var emlformat=require(_0xfcb5('0x0'));var rimraf=require(_0xfcb5('0x1'));var zipdir=require(_0xfcb5('0x2'));var jsonpatch=require(_0xfcb5('0x3'));var rp=require(_0xfcb5('0x4'));var moment=require(_0xfcb5('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xfcb5('0x6'));var util=require(_0xfcb5('0x7'));var path=require('path');var sox=require(_0xfcb5('0x8'));var csv=require(_0xfcb5('0x9'));var ejs=require(_0xfcb5('0xa'));var fs=require('fs');var fs_extra=require(_0xfcb5('0xb'));var _=require(_0xfcb5('0xc'));var squel=require(_0xfcb5('0xd'));var crypto=require(_0xfcb5('0xe'));var jsforce=require(_0xfcb5('0xf'));var deskjs=require(_0xfcb5('0x10'));var toCsv=require(_0xfcb5('0x9'));var querystring=require('querystring');var Papa=require(_0xfcb5('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xfcb5('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xfcb5('0x13'));var logger=require(_0xfcb5('0x14'))('api');var utils=require(_0xfcb5('0x15'));var config=require(_0xfcb5('0x16'));var licenseUtil=require(_0xfcb5('0x17'));var db=require(_0xfcb5('0x18'))['db'];function respondWithStatusCode(_0x3d928d,_0x5b9712){_0x5b9712=_0x5b9712||0xcc;return function(_0x50eff9){if(_0x50eff9){return _0x3d928d[_0xfcb5('0x19')](_0x5b9712);}return _0x3d928d['status'](_0x5b9712)[_0xfcb5('0x1a')]();};}function respondWithResult(_0x2a3f54,_0xfcf00e){_0xfcf00e=_0xfcf00e||0xc8;return function(_0x2f9bd5){if(_0x2f9bd5){return _0x2a3f54[_0xfcb5('0x1b')](_0xfcf00e)[_0xfcb5('0x1c')](_0x2f9bd5);}};}function respondWithFilteredResult(_0x65687c,_0x326313){return function(_0x1a0c53){if(_0x1a0c53){var _0x554e2=typeof _0x326313[_0xfcb5('0x1d')]===_0xfcb5('0x1e')&&typeof _0x326313[_0xfcb5('0x1f')]===_0xfcb5('0x1e');var _0x56ebe4=_0x1a0c53['count'];var _0x358b94=_0x554e2?0x0:_0x326313[_0xfcb5('0x1d')];var _0x4cc7c8=_0x554e2?_0x1a0c53[_0xfcb5('0x20')]:_0x326313[_0xfcb5('0x1d')]+_0x326313[_0xfcb5('0x1f')];var _0x368e6c;if(_0x4cc7c8>=_0x56ebe4){_0x4cc7c8=_0x56ebe4;_0x368e6c=0xc8;}else{_0x368e6c=0xce;}_0x65687c['status'](_0x368e6c);return _0x65687c['set'](_0xfcb5('0x21'),_0x358b94+'-'+_0x4cc7c8+'/'+_0x56ebe4)[_0xfcb5('0x1c')](_0x1a0c53);}return null;};}function patchUpdates(_0x4267a8){return function(_0x323368){try{jsonpatch[_0xfcb5('0x22')](_0x323368,_0x4267a8,!![]);}catch(_0x5a021c){return BPromise['reject'](_0x5a021c);}return _0x323368[_0xfcb5('0x23')]();};}function saveUpdates(_0x5139bc,_0x4881e0){return function(_0x115df1){if(_0x115df1){return _0x115df1[_0xfcb5('0x24')](_0x5139bc)[_0xfcb5('0x25')](function(_0x21d05e){return _0x21d05e;});}return null;};}function removeEntity(_0x347e4c,_0x3734e0){return function(_0x23d5b0){if(_0x23d5b0){return _0x23d5b0['destroy']()[_0xfcb5('0x25')](function(){_0x347e4c['status'](0xcc)[_0xfcb5('0x1a')]();});}};}function handleEntityNotFound(_0x192903,_0x40246f){return function(_0x28371b){if(!_0x28371b){_0x192903[_0xfcb5('0x19')](0x194);}return _0x28371b;};}function handleError(_0x3cbbb8,_0x515d1d){_0x515d1d=_0x515d1d||0x1f4;return function(_0x5b23e7){logger[_0xfcb5('0x26')](_0x5b23e7['stack']);if(_0x5b23e7[_0xfcb5('0x27')]){delete _0x5b23e7[_0xfcb5('0x27')];}_0x3cbbb8[_0xfcb5('0x1b')](_0x515d1d)[_0xfcb5('0x28')](_0x5b23e7);};}exports[_0xfcb5('0x29')]=function(_0xd91a1b,_0xe0aad0){var _0x27ec9e={},_0x642450={},_0x1c6cfd={'count':0x0,'rows':[]};var _0x5f55e0=_['map'](db[_0xfcb5('0x2a')][_0xfcb5('0x2b')],function(_0x46060f){return{'name':_0x46060f[_0xfcb5('0x2c')],'type':_0x46060f[_0xfcb5('0x2d')][_0xfcb5('0x2e')]};});_0x642450['model']=_[_0xfcb5('0x2f')](_0x5f55e0,_0xfcb5('0x27'));_0x642450[_0xfcb5('0x30')]=_[_0xfcb5('0x31')](_0xd91a1b['query']);_0x642450[_0xfcb5('0x32')]=_['intersection'](_0x642450[_0xfcb5('0x33')],_0x642450[_0xfcb5('0x30')]);_0x27ec9e[_0xfcb5('0x34')]=_['intersection'](_0x642450[_0xfcb5('0x33')],qs[_0xfcb5('0x35')](_0xd91a1b[_0xfcb5('0x30')][_0xfcb5('0x35')]));_0x27ec9e[_0xfcb5('0x34')]=_0x27ec9e['attributes'][_0xfcb5('0x36')]?_0x27ec9e['attributes']:_0x642450[_0xfcb5('0x33')];if(!_0xd91a1b[_0xfcb5('0x30')]['hasOwnProperty'](_0xfcb5('0x37'))){_0x27ec9e[_0xfcb5('0x1f')]=qs['limit'](_0xd91a1b[_0xfcb5('0x30')][_0xfcb5('0x1f')]);_0x27ec9e[_0xfcb5('0x1d')]=qs[_0xfcb5('0x1d')](_0xd91a1b[_0xfcb5('0x30')][_0xfcb5('0x1d')]);}_0x27ec9e[_0xfcb5('0x38')]=qs[_0xfcb5('0x39')](_0xd91a1b[_0xfcb5('0x30')][_0xfcb5('0x39')]);_0x27ec9e[_0xfcb5('0x3a')]=qs[_0xfcb5('0x32')](_[_0xfcb5('0x3b')](_0xd91a1b['query'],_0x642450['filters']),_0x5f55e0);if(_0xd91a1b['query'][_0xfcb5('0x3c')]){_0x27ec9e[_0xfcb5('0x3a')]=_['merge'](_0x27ec9e[_0xfcb5('0x3a')],{'$or':_[_0xfcb5('0x2f')](_0x5f55e0,function(_0x18118f){if(_0x18118f[_0xfcb5('0x2d')]!==_0xfcb5('0x3d')){var _0x1b41d3={};_0x1b41d3[_0x18118f[_0xfcb5('0x27')]]={'$like':'%'+_0xd91a1b[_0xfcb5('0x30')][_0xfcb5('0x3c')]+'%'};return _0x1b41d3;}})});}_0x27ec9e=_['merge']({},_0x27ec9e,_0xd91a1b[_0xfcb5('0x3e')]);var _0x4dbb48={'where':_0x27ec9e['where']};return db['SmsQueueReport']['count'](_0x4dbb48)['then'](function(_0x4cfb39){_0x1c6cfd[_0xfcb5('0x20')]=_0x4cfb39;if(_0xd91a1b[_0xfcb5('0x30')]['includeAll']){_0x27ec9e['include']=[{'all':!![]}];}return db['SmsQueueReport']['findAll'](_0x27ec9e);})[_0xfcb5('0x25')](function(_0x57624c){_0x1c6cfd[_0xfcb5('0x3f')]=_0x57624c;return _0x1c6cfd;})['then'](respondWithFilteredResult(_0xe0aad0,_0x27ec9e))[_0xfcb5('0x40')](handleError(_0xe0aad0,null));};exports[_0xfcb5('0x41')]=function(_0x335f94,_0x2df98d){var _0x58cd88={'raw':!![],'where':{'id':_0x335f94[_0xfcb5('0x42')]['id']}},_0x3eff9a={};_0x3eff9a[_0xfcb5('0x33')]=_[_0xfcb5('0x31')](db['SmsQueueReport'][_0xfcb5('0x2b')]);_0x3eff9a[_0xfcb5('0x30')]=_[_0xfcb5('0x31')](_0x335f94[_0xfcb5('0x30')]);_0x3eff9a['filters']=_['intersection'](_0x3eff9a[_0xfcb5('0x33')],_0x3eff9a[_0xfcb5('0x30')]);_0x58cd88[_0xfcb5('0x34')]=_['intersection'](_0x3eff9a[_0xfcb5('0x33')],qs[_0xfcb5('0x35')](_0x335f94['query'][_0xfcb5('0x35')]));_0x58cd88[_0xfcb5('0x34')]=_0x58cd88[_0xfcb5('0x34')][_0xfcb5('0x36')]?_0x58cd88['attributes']:_0x3eff9a[_0xfcb5('0x33')];if(_0x335f94[_0xfcb5('0x30')][_0xfcb5('0x43')]){_0x58cd88['include']=[{'all':!![]}];}_0x58cd88=_[_0xfcb5('0x44')]({},_0x58cd88,_0x335f94[_0xfcb5('0x3e')]);return db[_0xfcb5('0x2a')]['find'](_0x58cd88)[_0xfcb5('0x25')](handleEntityNotFound(_0x2df98d,null))[_0xfcb5('0x25')](respondWithResult(_0x2df98d,null))[_0xfcb5('0x40')](handleError(_0x2df98d,null));};exports[_0xfcb5('0x45')]=function(_0x5002d9,_0x30d86c){return db['SmsQueueReport'][_0xfcb5('0x45')](_0x5002d9[_0xfcb5('0x46')],{})['then'](respondWithResult(_0x30d86c,0xc9))[_0xfcb5('0x40')](handleError(_0x30d86c,null));};exports[_0xfcb5('0x24')]=function(_0x9428f1,_0x537510){if(_0x9428f1[_0xfcb5('0x46')]['id']){delete _0x9428f1[_0xfcb5('0x46')]['id'];}return db[_0xfcb5('0x2a')][_0xfcb5('0x47')]({'where':{'id':_0x9428f1[_0xfcb5('0x42')]['id']}})[_0xfcb5('0x25')](handleEntityNotFound(_0x537510,null))['then'](saveUpdates(_0x9428f1[_0xfcb5('0x46')],null))[_0xfcb5('0x25')](respondWithResult(_0x537510,null))[_0xfcb5('0x40')](handleError(_0x537510,null));};exports[_0xfcb5('0x48')]=function(_0x402f09,_0x2b3f2e){return db[_0xfcb5('0x2a')][_0xfcb5('0x47')]({'where':{'id':_0x402f09[_0xfcb5('0x42')]['id']}})[_0xfcb5('0x25')](handleEntityNotFound(_0x2b3f2e,null))[_0xfcb5('0x25')](removeEntity(_0x2b3f2e,null))['catch'](handleError(_0x2b3f2e,null));};exports[_0xfcb5('0x49')]=function(_0x28afea,_0x3f6d6a){return db['SmsQueueReport'][_0xfcb5('0x49')]()[_0xfcb5('0x25')](respondWithResult(_0x3f6d6a,null))[_0xfcb5('0x40')](handleError(_0x3f6d6a,null));};