Built motion from commit da617fac.|2.6.6
[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 _0x5c9a=['model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','options','find','catch','create','body','describe','rimraf','zip-dir','moment','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','SmsQueueReport','rawAttributes','fieldName','type','key'];(function(_0x2fbadc,_0x57dac7){var _0x44a072=function(_0x2e845a){while(--_0x2e845a){_0x2fbadc['push'](_0x2fbadc['shift']());}};_0x44a072(++_0x57dac7);}(_0x5c9a,0x6a));var _0xa5c9=function(_0x57a670,_0x30e402){_0x57a670=_0x57a670-0x0;var _0x41ce21=_0x5c9a[_0x57a670];return _0x41ce21;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xa5c9('0x0'));var zipdir=require(_0xa5c9('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xa5c9('0x2'));var BPromise=require('bluebird');var Mustache=require(_0xa5c9('0x3'));var util=require('util');var path=require('path');var sox=require(_0xa5c9('0x4'));var csv=require(_0xa5c9('0x5'));var ejs=require(_0xa5c9('0x6'));var fs=require('fs');var fs_extra=require(_0xa5c9('0x7'));var _=require(_0xa5c9('0x8'));var squel=require(_0xa5c9('0x9'));var crypto=require('crypto');var jsforce=require(_0xa5c9('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xa5c9('0xb'));var Papa=require(_0xa5c9('0xc'));var Redis=require(_0xa5c9('0xd'));var authService=require(_0xa5c9('0xe'));var qs=require(_0xa5c9('0xf'));var as=require(_0xa5c9('0x10'));var hardwareService=require(_0xa5c9('0x11'));var logger=require(_0xa5c9('0x12'))('api');var utils=require(_0xa5c9('0x13'));var config=require(_0xa5c9('0x14'));var licenseUtil=require(_0xa5c9('0x15'));var db=require(_0xa5c9('0x16'))['db'];function respondWithStatusCode(_0x2c2ccc,_0x5f1561){_0x5f1561=_0x5f1561||0xcc;return function(_0x1529d2){if(_0x1529d2){return _0x2c2ccc[_0xa5c9('0x17')](_0x5f1561);}return _0x2c2ccc[_0xa5c9('0x18')](_0x5f1561)[_0xa5c9('0x19')]();};}function respondWithResult(_0x14382d,_0xd38d0a){_0xd38d0a=_0xd38d0a||0xc8;return function(_0x518aae){if(_0x518aae){return _0x14382d['status'](_0xd38d0a)[_0xa5c9('0x1a')](_0x518aae);}};}function respondWithFilteredResult(_0x411866,_0x373c4d){return function(_0x4f3749){if(_0x4f3749){var _0x423138=typeof _0x373c4d[_0xa5c9('0x1b')]===_0xa5c9('0x1c')&&typeof _0x373c4d['limit']==='undefined';var _0x15c01d=_0x4f3749['count'];var _0x267727=_0x423138?0x0:_0x373c4d[_0xa5c9('0x1b')];var _0x41c39d=_0x423138?_0x4f3749[_0xa5c9('0x1d')]:_0x373c4d[_0xa5c9('0x1b')]+_0x373c4d[_0xa5c9('0x1e')];var _0x30d87e;if(_0x41c39d>=_0x15c01d){_0x41c39d=_0x15c01d;_0x30d87e=0xc8;}else{_0x30d87e=0xce;}_0x411866['status'](_0x30d87e);return _0x411866[_0xa5c9('0x1f')](_0xa5c9('0x20'),_0x267727+'-'+_0x41c39d+'/'+_0x15c01d)[_0xa5c9('0x1a')](_0x4f3749);}return null;};}function patchUpdates(_0x13aa04){return function(_0x38ce47){try{jsonpatch[_0xa5c9('0x21')](_0x38ce47,_0x13aa04,!![]);}catch(_0x998b2e){return BPromise[_0xa5c9('0x22')](_0x998b2e);}return _0x38ce47[_0xa5c9('0x23')]();};}function saveUpdates(_0x278325,_0x192467){return function(_0x280410){if(_0x280410){return _0x280410[_0xa5c9('0x24')](_0x278325)[_0xa5c9('0x25')](function(_0x3bdcb3){return _0x3bdcb3;});}return null;};}function removeEntity(_0xea00b7,_0x588c06){return function(_0x4ce603){if(_0x4ce603){return _0x4ce603[_0xa5c9('0x26')]()[_0xa5c9('0x25')](function(){_0xea00b7['status'](0xcc)[_0xa5c9('0x19')]();});}};}function handleEntityNotFound(_0x2dfcea,_0x3ddda6){return function(_0x56f1a1){if(!_0x56f1a1){_0x2dfcea[_0xa5c9('0x17')](0x194);}return _0x56f1a1;};}function handleError(_0x5a7818,_0x1dcea5){_0x1dcea5=_0x1dcea5||0x1f4;return function(_0x487540){logger[_0xa5c9('0x27')](_0x487540[_0xa5c9('0x28')]);if(_0x487540[_0xa5c9('0x29')]){delete _0x487540['name'];}_0x5a7818[_0xa5c9('0x18')](_0x1dcea5)[_0xa5c9('0x2a')](_0x487540);};}exports[_0xa5c9('0x2b')]=function(_0x1c6995,_0x52afd7){var _0x3e9b54={},_0x4331fa={},_0x18bfd9={'count':0x0,'rows':[]};var _0x3f06bb=_[_0xa5c9('0x2c')](db[_0xa5c9('0x2d')][_0xa5c9('0x2e')],function(_0x497fc1){return{'name':_0x497fc1[_0xa5c9('0x2f')],'type':_0x497fc1[_0xa5c9('0x30')][_0xa5c9('0x31')]};});_0x4331fa[_0xa5c9('0x32')]=_[_0xa5c9('0x2c')](_0x3f06bb,_0xa5c9('0x29'));_0x4331fa[_0xa5c9('0x33')]=_[_0xa5c9('0x34')](_0x1c6995['query']);_0x4331fa[_0xa5c9('0x35')]=_[_0xa5c9('0x36')](_0x4331fa['model'],_0x4331fa[_0xa5c9('0x33')]);_0x3e9b54[_0xa5c9('0x37')]=_[_0xa5c9('0x36')](_0x4331fa['model'],qs[_0xa5c9('0x38')](_0x1c6995[_0xa5c9('0x33')][_0xa5c9('0x38')]));_0x3e9b54[_0xa5c9('0x37')]=_0x3e9b54[_0xa5c9('0x37')][_0xa5c9('0x39')]?_0x3e9b54['attributes']:_0x4331fa[_0xa5c9('0x32')];if(!_0x1c6995[_0xa5c9('0x33')][_0xa5c9('0x3a')](_0xa5c9('0x3b'))){_0x3e9b54['limit']=qs['limit'](_0x1c6995[_0xa5c9('0x33')][_0xa5c9('0x1e')]);_0x3e9b54[_0xa5c9('0x1b')]=qs[_0xa5c9('0x1b')](_0x1c6995[_0xa5c9('0x33')][_0xa5c9('0x1b')]);}_0x3e9b54[_0xa5c9('0x3c')]=qs[_0xa5c9('0x3d')](_0x1c6995['query']['sort']);_0x3e9b54[_0xa5c9('0x3e')]=qs[_0xa5c9('0x35')](_[_0xa5c9('0x3f')](_0x1c6995['query'],_0x4331fa[_0xa5c9('0x35')]),_0x3f06bb);if(_0x1c6995['query']['filter']){_0x3e9b54[_0xa5c9('0x3e')]=_[_0xa5c9('0x40')](_0x3e9b54['where'],{'$or':_[_0xa5c9('0x2c')](_0x3f06bb,function(_0x5cdc9a){if(_0x5cdc9a[_0xa5c9('0x30')]!==_0xa5c9('0x41')){var _0x206340={};_0x206340[_0x5cdc9a['name']]={'$like':'%'+_0x1c6995[_0xa5c9('0x33')]['filter']+'%'};return _0x206340;}})});}_0x3e9b54=_[_0xa5c9('0x40')]({},_0x3e9b54,_0x1c6995['options']);var _0x5da2f7={'where':_0x3e9b54['where']};return db[_0xa5c9('0x2d')][_0xa5c9('0x1d')](_0x5da2f7)[_0xa5c9('0x25')](function(_0xcacb4){_0x18bfd9[_0xa5c9('0x1d')]=_0xcacb4;if(_0x1c6995[_0xa5c9('0x33')][_0xa5c9('0x42')]){_0x3e9b54[_0xa5c9('0x43')]=[{'all':!![]}];}return db['SmsQueueReport'][_0xa5c9('0x44')](_0x3e9b54);})[_0xa5c9('0x25')](function(_0x151d89){_0x18bfd9[_0xa5c9('0x45')]=_0x151d89;return _0x18bfd9;})['then'](respondWithFilteredResult(_0x52afd7,_0x3e9b54))['catch'](handleError(_0x52afd7,null));};exports[_0xa5c9('0x46')]=function(_0x16bb87,_0x2e9983){var _0x4f570b={'raw':!![],'where':{'id':_0x16bb87[_0xa5c9('0x47')]['id']}},_0x72013b={};_0x72013b[_0xa5c9('0x32')]=_[_0xa5c9('0x34')](db['SmsQueueReport'][_0xa5c9('0x2e')]);_0x72013b[_0xa5c9('0x33')]=_[_0xa5c9('0x34')](_0x16bb87['query']);_0x72013b['filters']=_[_0xa5c9('0x36')](_0x72013b[_0xa5c9('0x32')],_0x72013b['query']);_0x4f570b[_0xa5c9('0x37')]=_['intersection'](_0x72013b[_0xa5c9('0x32')],qs[_0xa5c9('0x38')](_0x16bb87[_0xa5c9('0x33')][_0xa5c9('0x38')]));_0x4f570b[_0xa5c9('0x37')]=_0x4f570b[_0xa5c9('0x37')][_0xa5c9('0x39')]?_0x4f570b[_0xa5c9('0x37')]:_0x72013b['model'];if(_0x16bb87['query'][_0xa5c9('0x42')]){_0x4f570b[_0xa5c9('0x43')]=[{'all':!![]}];}_0x4f570b=_['merge']({},_0x4f570b,_0x16bb87[_0xa5c9('0x48')]);return db[_0xa5c9('0x2d')][_0xa5c9('0x49')](_0x4f570b)[_0xa5c9('0x25')](handleEntityNotFound(_0x2e9983,null))[_0xa5c9('0x25')](respondWithResult(_0x2e9983,null))[_0xa5c9('0x4a')](handleError(_0x2e9983,null));};exports[_0xa5c9('0x4b')]=function(_0x5e81e3,_0x3c5fad){return db[_0xa5c9('0x2d')][_0xa5c9('0x4b')](_0x5e81e3[_0xa5c9('0x4c')],{})['then'](respondWithResult(_0x3c5fad,0xc9))[_0xa5c9('0x4a')](handleError(_0x3c5fad,null));};exports[_0xa5c9('0x24')]=function(_0x57bd3d,_0x3e3be9){if(_0x57bd3d['body']['id']){delete _0x57bd3d[_0xa5c9('0x4c')]['id'];}return db[_0xa5c9('0x2d')][_0xa5c9('0x49')]({'where':{'id':_0x57bd3d['params']['id']}})[_0xa5c9('0x25')](handleEntityNotFound(_0x3e3be9,null))[_0xa5c9('0x25')](saveUpdates(_0x57bd3d[_0xa5c9('0x4c')],null))[_0xa5c9('0x25')](respondWithResult(_0x3e3be9,null))[_0xa5c9('0x4a')](handleError(_0x3e3be9,null));};exports[_0xa5c9('0x26')]=function(_0x50fa09,_0x2e96d1){return db[_0xa5c9('0x2d')][_0xa5c9('0x49')]({'where':{'id':_0x50fa09[_0xa5c9('0x47')]['id']}})[_0xa5c9('0x25')](handleEntityNotFound(_0x2e96d1,null))[_0xa5c9('0x25')](removeEntity(_0x2e96d1,null))[_0xa5c9('0x4a')](handleError(_0x2e96d1,null));};exports['describe']=function(_0x4b8188,_0x357650){return db['SmsQueueReport'][_0xa5c9('0x4d')]()[_0xa5c9('0x25')](respondWithResult(_0x357650,null))[_0xa5c9('0x4a')](handleError(_0x357650,null));};