2a6897b0e6229fc4e07b4a7d24a4e678e5514c43
[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 _0x87f4=['set','Content-Range','json','apply','reject','save','update','then','destroy','error','stack','name','index','SmsQueueReport','type','key','model','map','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','where','filter','merge','VIRTUAL','options','includeAll','include','catch','show','rawAttributes','find','create','body','params','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/environment','sendStatus','status','end','count','offset','limit'];(function(_0x1cc519,_0x4fd527){var _0x5418c5=function(_0x4d0639){while(--_0x4d0639){_0x1cc519['push'](_0x1cc519['shift']());}};_0x5418c5(++_0x4fd527);}(_0x87f4,0x73));var _0x487f=function(_0x4ae32d,_0x256489){_0x4ae32d=_0x4ae32d-0x0;var _0x550537=_0x87f4[_0x4ae32d];return _0x550537;};'use strict';var pdf=require(_0x487f('0x0'));var emlformat=require(_0x487f('0x1'));var rimraf=require(_0x487f('0x2'));var zipdir=require(_0x487f('0x3'));var jsonpatch=require(_0x487f('0x4'));var rp=require('request-promise');var moment=require(_0x487f('0x5'));var BPromise=require(_0x487f('0x6'));var Mustache=require(_0x487f('0x7'));var util=require(_0x487f('0x8'));var path=require('path');var sox=require(_0x487f('0x9'));var csv=require(_0x487f('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x487f('0xb'));var squel=require(_0x487f('0xc'));var crypto=require(_0x487f('0xd'));var jsforce=require(_0x487f('0xe'));var deskjs=require(_0x487f('0xf'));var toCsv=require(_0x487f('0xa'));var querystring=require(_0x487f('0x10'));var Papa=require(_0x487f('0x11'));var Redis=require('ioredis');var authService=require(_0x487f('0x12'));var qs=require(_0x487f('0x13'));var as=require(_0x487f('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x487f('0x15'))('api');var utils=require('../../config/utils');var config=require(_0x487f('0x16'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xcbb1ef,_0x52cc81){_0x52cc81=_0x52cc81||0xcc;return function(_0x54998d){if(_0x54998d){return _0xcbb1ef[_0x487f('0x17')](_0x52cc81);}return _0xcbb1ef[_0x487f('0x18')](_0x52cc81)[_0x487f('0x19')]();};}function respondWithResult(_0x3218ac,_0x19d67b){_0x19d67b=_0x19d67b||0xc8;return function(_0x5c399e){if(_0x5c399e){return _0x3218ac[_0x487f('0x18')](_0x19d67b)['json'](_0x5c399e);}};}function respondWithFilteredResult(_0x440efd,_0x272de2){return function(_0x214611){if(_0x214611){var _0x54475e=_0x214611[_0x487f('0x1a')],_0x4e502e=_0x272de2[_0x487f('0x1b')],_0x2b18af=_0x272de2['offset']+_0x272de2[_0x487f('0x1c')],_0xdf45e6;if(_0x2b18af>=_0x54475e){_0x2b18af=_0x54475e;_0xdf45e6=0xc8;}else{_0xdf45e6=0xce;}_0x440efd[_0x487f('0x18')](_0xdf45e6);return _0x440efd[_0x487f('0x1d')](_0x487f('0x1e'),_0x4e502e+'-'+_0x2b18af+'/'+_0x54475e)[_0x487f('0x1f')](_0x214611);}return null;};}function patchUpdates(_0x53f05e){return function(_0x147011){try{jsonpatch[_0x487f('0x20')](_0x147011,_0x53f05e,!![]);}catch(_0x273d0e){return BPromise[_0x487f('0x21')](_0x273d0e);}return _0x147011[_0x487f('0x22')]();};}function saveUpdates(_0x493115,_0x38a3a0){return function(_0x3a6cbf){if(_0x3a6cbf){return _0x3a6cbf[_0x487f('0x23')](_0x493115)[_0x487f('0x24')](function(_0x52139c){return _0x52139c;});}return null;};}function removeEntity(_0x216d4e,_0x1c8dc8){return function(_0x278b80){if(_0x278b80){return _0x278b80[_0x487f('0x25')]()[_0x487f('0x24')](function(){_0x216d4e[_0x487f('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1e2d47,_0x2caf25){return function(_0x178e6b){if(!_0x178e6b){_0x1e2d47[_0x487f('0x17')](0x194);}return _0x178e6b;};}function handleError(_0x4c917f,_0x32fa0a){_0x32fa0a=_0x32fa0a||0x1f4;return function(_0x58e9e6){logger[_0x487f('0x26')](_0x58e9e6[_0x487f('0x27')]);if(_0x58e9e6[_0x487f('0x28')]){delete _0x58e9e6['name'];}_0x4c917f[_0x487f('0x18')](_0x32fa0a)['send'](_0x58e9e6);};}exports[_0x487f('0x29')]=function(_0x498006,_0x1e2f64){var _0x105e74={},_0x3ab3cf={},_0xece87a={'count':0x0,'rows':[]};var _0x28f3ca=_['map'](db[_0x487f('0x2a')]['rawAttributes'],function(_0x10475d){return{'name':_0x10475d['fieldName'],'type':_0x10475d[_0x487f('0x2b')][_0x487f('0x2c')]};});_0x3ab3cf[_0x487f('0x2d')]=_[_0x487f('0x2e')](_0x28f3ca,'name');_0x3ab3cf[_0x487f('0x2f')]=_[_0x487f('0x30')](_0x498006[_0x487f('0x2f')]);_0x3ab3cf[_0x487f('0x31')]=_['intersection'](_0x3ab3cf[_0x487f('0x2d')],_0x3ab3cf['query']);_0x105e74[_0x487f('0x32')]=_[_0x487f('0x33')](_0x3ab3cf[_0x487f('0x2d')],qs[_0x487f('0x34')](_0x498006['query'][_0x487f('0x34')]));_0x105e74[_0x487f('0x32')]=_0x105e74[_0x487f('0x32')][_0x487f('0x35')]?_0x105e74[_0x487f('0x32')]:_0x3ab3cf[_0x487f('0x2d')];if(!_0x498006[_0x487f('0x2f')][_0x487f('0x36')](_0x487f('0x37'))){_0x105e74['limit']=qs['limit'](_0x498006[_0x487f('0x2f')][_0x487f('0x1c')]);_0x105e74[_0x487f('0x1b')]=qs[_0x487f('0x1b')](_0x498006['query']['offset']);}_0x105e74[_0x487f('0x38')]=qs['sort'](_0x498006[_0x487f('0x2f')]['sort']);_0x105e74[_0x487f('0x39')]=qs['filters'](_['pick'](_0x498006[_0x487f('0x2f')],_0x3ab3cf[_0x487f('0x31')]),_0x28f3ca);if(_0x498006[_0x487f('0x2f')][_0x487f('0x3a')]){_0x105e74['where']=_[_0x487f('0x3b')](_0x105e74[_0x487f('0x39')],{'$or':_[_0x487f('0x2e')](_0x28f3ca,function(_0x136108){if(_0x136108[_0x487f('0x2b')]!==_0x487f('0x3c')){var _0x32dec0={};_0x32dec0[_0x136108[_0x487f('0x28')]]={'$like':'%'+_0x498006['query'][_0x487f('0x3a')]+'%'};return _0x32dec0;}})});}_0x105e74=_[_0x487f('0x3b')]({},_0x105e74,_0x498006[_0x487f('0x3d')]);var _0x5a56ee={'where':_0x105e74['where']};return db[_0x487f('0x2a')][_0x487f('0x1a')](_0x5a56ee)[_0x487f('0x24')](function(_0x21533b){_0xece87a['count']=_0x21533b;if(_0x498006[_0x487f('0x2f')][_0x487f('0x3e')]){_0x105e74[_0x487f('0x3f')]=[{'all':!![]}];}return db[_0x487f('0x2a')]['findAll'](_0x105e74);})[_0x487f('0x24')](function(_0xa7ebfc){_0xece87a['rows']=_0xa7ebfc;return _0xece87a;})[_0x487f('0x24')](respondWithFilteredResult(_0x1e2f64,_0x105e74))[_0x487f('0x40')](handleError(_0x1e2f64,null));};exports[_0x487f('0x41')]=function(_0x28496a,_0x49d3ab){var _0x1a8689={'raw':!![],'where':{'id':_0x28496a['params']['id']}},_0x3ef12e={};_0x3ef12e[_0x487f('0x2d')]=_[_0x487f('0x30')](db[_0x487f('0x2a')][_0x487f('0x42')]);_0x3ef12e[_0x487f('0x2f')]=_[_0x487f('0x30')](_0x28496a[_0x487f('0x2f')]);_0x3ef12e[_0x487f('0x31')]=_['intersection'](_0x3ef12e[_0x487f('0x2d')],_0x3ef12e[_0x487f('0x2f')]);_0x1a8689[_0x487f('0x32')]=_[_0x487f('0x33')](_0x3ef12e['model'],qs[_0x487f('0x34')](_0x28496a[_0x487f('0x2f')][_0x487f('0x34')]));_0x1a8689[_0x487f('0x32')]=_0x1a8689['attributes']['length']?_0x1a8689['attributes']:_0x3ef12e[_0x487f('0x2d')];if(_0x28496a['query'][_0x487f('0x3e')]){_0x1a8689['include']=[{'all':!![]}];}_0x1a8689=_['merge']({},_0x1a8689,_0x28496a['options']);return db[_0x487f('0x2a')][_0x487f('0x43')](_0x1a8689)[_0x487f('0x24')](handleEntityNotFound(_0x49d3ab,null))[_0x487f('0x24')](respondWithResult(_0x49d3ab,null))[_0x487f('0x40')](handleError(_0x49d3ab,null));};exports['create']=function(_0x352c3c,_0x119525){return db['SmsQueueReport'][_0x487f('0x44')](_0x352c3c[_0x487f('0x45')],{})[_0x487f('0x24')](respondWithResult(_0x119525,0xc9))[_0x487f('0x40')](handleError(_0x119525,null));};exports[_0x487f('0x23')]=function(_0x2168e4,_0xb69f3a){if(_0x2168e4[_0x487f('0x45')]['id']){delete _0x2168e4[_0x487f('0x45')]['id'];}return db[_0x487f('0x2a')][_0x487f('0x43')]({'where':{'id':_0x2168e4[_0x487f('0x46')]['id']}})[_0x487f('0x24')](handleEntityNotFound(_0xb69f3a,null))[_0x487f('0x24')](saveUpdates(_0x2168e4[_0x487f('0x45')],null))[_0x487f('0x24')](respondWithResult(_0xb69f3a,null))[_0x487f('0x40')](handleError(_0xb69f3a,null));};exports[_0x487f('0x25')]=function(_0x5e276d,_0x3d31b3){return db[_0x487f('0x2a')]['find']({'where':{'id':_0x5e276d[_0x487f('0x46')]['id']}})[_0x487f('0x24')](handleEntityNotFound(_0x3d31b3,null))[_0x487f('0x24')](removeEntity(_0x3d31b3,null))[_0x487f('0x40')](handleError(_0x3d31b3,null));};exports[_0x487f('0x47')]=function(_0x156c6b,_0x232a29){return db[_0x487f('0x2a')][_0x487f('0x47')]()[_0x487f('0x24')](respondWithResult(_0x232a29,null))['catch'](handleError(_0x232a29,null));};