2a75179f1e7cbeae8ff9e122fd468d9b6d598e19
[motion2.git] / server / api / smsTransferReport / smsTransferReport.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 _0x0f52=['pick','merge','VIRTUAL','filter','options','then','includeAll','include','findAll','rows','catch','show','keys','filters','create','body','update','find','params','describe','html-pdf','fast-json-patch','request-promise','moment','bluebird','mustache','util','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','count','limit','Content-Range','reject','save','error','stack','name','send','index','map','SmsTransferReport','fieldName','type','model','query','intersection','attributes','fields','length','hasOwnProperty','offset','sort','where'];(function(_0x38a0e7,_0x28232e){var _0x2739f2=function(_0x1a45e8){while(--_0x1a45e8){_0x38a0e7['push'](_0x38a0e7['shift']());}};_0x2739f2(++_0x28232e);}(_0x0f52,0x1b8));var _0x20f5=function(_0x423097,_0x8a09f4){_0x423097=_0x423097-0x0;var _0x3a73f1=_0x0f52[_0x423097];return _0x3a73f1;};'use strict';var pdf=require(_0x20f5('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x20f5('0x1'));var rp=require(_0x20f5('0x2'));var moment=require(_0x20f5('0x3'));var BPromise=require(_0x20f5('0x4'));var Mustache=require(_0x20f5('0x5'));var util=require(_0x20f5('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x20f5('0x7'));var fs=require('fs');var _=require(_0x20f5('0x8'));var squel=require(_0x20f5('0x9'));var crypto=require(_0x20f5('0xa'));var jsforce=require(_0x20f5('0xb'));var deskjs=require(_0x20f5('0xc'));var toCsv=require(_0x20f5('0xd'));var querystring=require(_0x20f5('0xe'));var Papa=require(_0x20f5('0xf'));var Redis=require(_0x20f5('0x10'));var authService=require(_0x20f5('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x20f5('0x12'));var utils=require('../../config/utils');var config=require(_0x20f5('0x13'));var licenseUtil=require(_0x20f5('0x14'));var db=require(_0x20f5('0x15'))['db'];function respondWithStatusCode(_0x53e352,_0x57c121){_0x57c121=_0x57c121||0xcc;return function(_0x140932){if(_0x140932){return _0x53e352[_0x20f5('0x16')](_0x57c121);}return _0x53e352['status'](_0x57c121)[_0x20f5('0x17')]();};}function respondWithResult(_0x24d619,_0x95ec01){_0x95ec01=_0x95ec01||0xc8;return function(_0x152d86){if(_0x152d86){return _0x24d619[_0x20f5('0x18')](_0x95ec01)[_0x20f5('0x19')](_0x152d86);}};}function respondWithFilteredResult(_0x529de6,_0x324579){return function(_0xf9f611){if(_0xf9f611){var _0xc22eff=_0xf9f611[_0x20f5('0x1a')],_0x13a907=_0x324579['offset'],_0x1df4cd=_0x324579['offset']+_0x324579[_0x20f5('0x1b')],_0x1cc2a4;if(_0x1df4cd>=_0xc22eff){_0x1df4cd=_0xc22eff;_0x1cc2a4=0xc8;}else{_0x1cc2a4=0xce;}_0x529de6[_0x20f5('0x18')](_0x1cc2a4);return _0x529de6['set'](_0x20f5('0x1c'),_0x13a907+'-'+_0x1df4cd+'/'+_0xc22eff)[_0x20f5('0x19')](_0xf9f611);}return null;};}function patchUpdates(_0x4e7d95){return function(_0x579f39){try{jsonpatch['apply'](_0x579f39,_0x4e7d95,!![]);}catch(_0x1a0d0d){return BPromise[_0x20f5('0x1d')](_0x1a0d0d);}return _0x579f39[_0x20f5('0x1e')]();};}function saveUpdates(_0x195240,_0x2096b2){return function(_0x52360f){if(_0x52360f){return _0x52360f['update'](_0x195240)['then'](function(_0x5920dc){return _0x5920dc;});}return null;};}function removeEntity(_0x301a98,_0x367af5){return function(_0x681a61){if(_0x681a61){return _0x681a61['destroy']()['then'](function(){_0x301a98[_0x20f5('0x18')](0xcc)[_0x20f5('0x17')]();});}};}function handleEntityNotFound(_0x3b161c,_0x482d83){return function(_0x2d99b1){if(!_0x2d99b1){_0x3b161c[_0x20f5('0x16')](0x194);}return _0x2d99b1;};}function handleError(_0x10fef7,_0xa3e33a){_0xa3e33a=_0xa3e33a||0x1f4;return function(_0x61ee3a){logger[_0x20f5('0x1f')](_0x61ee3a[_0x20f5('0x20')]);if(_0x61ee3a[_0x20f5('0x21')]){delete _0x61ee3a[_0x20f5('0x21')];}_0x10fef7[_0x20f5('0x18')](_0xa3e33a)[_0x20f5('0x22')](_0x61ee3a);};}exports[_0x20f5('0x23')]=function(_0x2cb91d,_0x3ec2a6){var _0x1be3e1={},_0x15effc={},_0x2168f5={'count':0x0,'rows':[]};var _0x56e255=_[_0x20f5('0x24')](db[_0x20f5('0x25')]['rawAttributes'],function(_0x32c5cd){return{'name':_0x32c5cd[_0x20f5('0x26')],'type':_0x32c5cd[_0x20f5('0x27')]['key']};});_0x15effc[_0x20f5('0x28')]=_[_0x20f5('0x24')](_0x56e255,_0x20f5('0x21'));_0x15effc[_0x20f5('0x29')]=_['keys'](_0x2cb91d[_0x20f5('0x29')]);_0x15effc['filters']=_[_0x20f5('0x2a')](_0x15effc[_0x20f5('0x28')],_0x15effc[_0x20f5('0x29')]);_0x1be3e1[_0x20f5('0x2b')]=_[_0x20f5('0x2a')](_0x15effc[_0x20f5('0x28')],qs[_0x20f5('0x2c')](_0x2cb91d[_0x20f5('0x29')][_0x20f5('0x2c')]));_0x1be3e1[_0x20f5('0x2b')]=_0x1be3e1[_0x20f5('0x2b')][_0x20f5('0x2d')]?_0x1be3e1[_0x20f5('0x2b')]:_0x15effc['model'];if(!_0x2cb91d[_0x20f5('0x29')][_0x20f5('0x2e')]('nolimit')){_0x1be3e1[_0x20f5('0x1b')]=qs[_0x20f5('0x1b')](_0x2cb91d[_0x20f5('0x29')][_0x20f5('0x1b')]);_0x1be3e1[_0x20f5('0x2f')]=qs[_0x20f5('0x2f')](_0x2cb91d[_0x20f5('0x29')]['offset']);}_0x1be3e1['order']=qs[_0x20f5('0x30')](_0x2cb91d[_0x20f5('0x29')][_0x20f5('0x30')]);_0x1be3e1[_0x20f5('0x31')]=qs['filters'](_[_0x20f5('0x32')](_0x2cb91d[_0x20f5('0x29')],_0x15effc['filters']),_0x56e255);if(_0x2cb91d[_0x20f5('0x29')]['filter']){_0x1be3e1[_0x20f5('0x31')]=_[_0x20f5('0x33')](_0x1be3e1[_0x20f5('0x31')],{'$or':_['map'](_0x56e255,function(_0x3f0b3a){if(_0x3f0b3a[_0x20f5('0x27')]!==_0x20f5('0x34')){var _0x996691={};_0x996691[_0x3f0b3a[_0x20f5('0x21')]]={'$like':'%'+_0x2cb91d[_0x20f5('0x29')][_0x20f5('0x35')]+'%'};return _0x996691;}})});}_0x1be3e1=_[_0x20f5('0x33')]({},_0x1be3e1,_0x2cb91d[_0x20f5('0x36')]);var _0x5738b5={'where':_0x1be3e1['where']};return db[_0x20f5('0x25')][_0x20f5('0x1a')](_0x5738b5)[_0x20f5('0x37')](function(_0x5d3408){_0x2168f5[_0x20f5('0x1a')]=_0x5d3408;if(_0x2cb91d[_0x20f5('0x29')][_0x20f5('0x38')]){_0x1be3e1[_0x20f5('0x39')]=[{'all':!![]}];}return db[_0x20f5('0x25')][_0x20f5('0x3a')](_0x1be3e1);})[_0x20f5('0x37')](function(_0x5ae936){_0x2168f5[_0x20f5('0x3b')]=_0x5ae936;return _0x2168f5;})[_0x20f5('0x37')](respondWithFilteredResult(_0x3ec2a6,_0x1be3e1))[_0x20f5('0x3c')](handleError(_0x3ec2a6,null));};exports[_0x20f5('0x3d')]=function(_0x5736c8,_0x5db231){var _0x1aada6={'raw':!![],'where':{'id':_0x5736c8['params']['id']}},_0x5957e1={};_0x5957e1['model']=_[_0x20f5('0x3e')](db[_0x20f5('0x25')]['rawAttributes']);_0x5957e1['query']=_[_0x20f5('0x3e')](_0x5736c8[_0x20f5('0x29')]);_0x5957e1[_0x20f5('0x3f')]=_[_0x20f5('0x2a')](_0x5957e1[_0x20f5('0x28')],_0x5957e1['query']);_0x1aada6[_0x20f5('0x2b')]=_[_0x20f5('0x2a')](_0x5957e1[_0x20f5('0x28')],qs['fields'](_0x5736c8[_0x20f5('0x29')]['fields']));_0x1aada6[_0x20f5('0x2b')]=_0x1aada6[_0x20f5('0x2b')][_0x20f5('0x2d')]?_0x1aada6['attributes']:_0x5957e1[_0x20f5('0x28')];if(_0x5736c8[_0x20f5('0x29')]['includeAll']){_0x1aada6[_0x20f5('0x39')]=[{'all':!![]}];}_0x1aada6=_[_0x20f5('0x33')]({},_0x1aada6,_0x5736c8['options']);return db[_0x20f5('0x25')]['find'](_0x1aada6)['then'](handleEntityNotFound(_0x5db231,null))[_0x20f5('0x37')](respondWithResult(_0x5db231,null))[_0x20f5('0x3c')](handleError(_0x5db231,null));};exports[_0x20f5('0x40')]=function(_0x582e48,_0x19bda5){return db[_0x20f5('0x25')][_0x20f5('0x40')](_0x582e48[_0x20f5('0x41')],{})['then'](respondWithResult(_0x19bda5,0xc9))[_0x20f5('0x3c')](handleError(_0x19bda5,null));};exports[_0x20f5('0x42')]=function(_0x256cd8,_0x33acc7){if(_0x256cd8['body']['id']){delete _0x256cd8[_0x20f5('0x41')]['id'];}return db['SmsTransferReport'][_0x20f5('0x43')]({'where':{'id':_0x256cd8[_0x20f5('0x44')]['id']}})[_0x20f5('0x37')](handleEntityNotFound(_0x33acc7,null))[_0x20f5('0x37')](saveUpdates(_0x256cd8[_0x20f5('0x41')],null))[_0x20f5('0x37')](respondWithResult(_0x33acc7,null))[_0x20f5('0x3c')](handleError(_0x33acc7,null));};exports['destroy']=function(_0x1c19fc,_0x184ffa){return db[_0x20f5('0x25')][_0x20f5('0x43')]({'where':{'id':_0x1c19fc['params']['id']}})[_0x20f5('0x37')](handleEntityNotFound(_0x184ffa,null))['then'](removeEntity(_0x184ffa,null))[_0x20f5('0x3c')](handleError(_0x184ffa,null));};exports['describe']=function(_0x222eab,_0x1b7f9e){return db[_0x20f5('0x25')][_0x20f5('0x45')]()[_0x20f5('0x37')](respondWithResult(_0x1b7f9e,null))[_0x20f5('0x3c')](handleError(_0x1b7f9e,null));};