Built motion from commit (unavailable).|2.4.19
[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 _0xaf0e=['destroy','sendStatus','error','stack','name','send','index','SmsTransferReport','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','where','pick','filter','merge','map','type','options','count','includeAll','include','rows','catch','params','rawAttributes','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','sox','ejs','lodash','squel','crypto','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','offset','limit','apply','save','update','then'];(function(_0x5a477e,_0xaa566e){var _0x5cd6c7=function(_0x5cd6fb){while(--_0x5cd6fb){_0x5a477e['push'](_0x5a477e['shift']());}};_0x5cd6c7(++_0xaa566e);}(_0xaf0e,0x1d0));var _0xeaf0=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0xaf0e[_0x14add3];return _0x4a174f;};'use strict';var pdf=require(_0xeaf0('0x0'));var emlformat=require(_0xeaf0('0x1'));var rimraf=require(_0xeaf0('0x2'));var zipdir=require(_0xeaf0('0x3'));var jsonpatch=require(_0xeaf0('0x4'));var rp=require('request-promise');var moment=require(_0xeaf0('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xeaf0('0x6'));var util=require(_0xeaf0('0x7'));var path=require('path');var sox=require(_0xeaf0('0x8'));var csv=require('to-csv');var ejs=require(_0xeaf0('0x9'));var fs=require('fs');var _=require(_0xeaf0('0xa'));var squel=require(_0xeaf0('0xb'));var crypto=require(_0xeaf0('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xeaf0('0xd'));var toCsv=require(_0xeaf0('0xe'));var querystring=require('querystring');var Papa=require(_0xeaf0('0xf'));var Redis=require(_0xeaf0('0x10'));var authService=require(_0xeaf0('0x11'));var qs=require(_0xeaf0('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xeaf0('0x13'));var logger=require('../../config/logger')(_0xeaf0('0x14'));var utils=require(_0xeaf0('0x15'));var config=require(_0xeaf0('0x16'));var db=require(_0xeaf0('0x17'))['db'];function respondWithStatusCode(_0x23481e,_0x2a6ed1){_0x2a6ed1=_0x2a6ed1||0xcc;return function(_0x1e3daa){if(_0x1e3daa){return _0x23481e['sendStatus'](_0x2a6ed1);}return _0x23481e[_0xeaf0('0x18')](_0x2a6ed1)[_0xeaf0('0x19')]();};}function respondWithResult(_0x2df902,_0x1e46fe){_0x1e46fe=_0x1e46fe||0xc8;return function(_0xa791d5){if(_0xa791d5){return _0x2df902[_0xeaf0('0x18')](_0x1e46fe)[_0xeaf0('0x1a')](_0xa791d5);}};}function respondWithFilteredResult(_0x1d7b41,_0x48d5cc){return function(_0x68c99f){if(_0x68c99f){var _0x484d15=_0x68c99f['count'],_0x3d6151=_0x48d5cc[_0xeaf0('0x1b')],_0x30ddcb=_0x48d5cc[_0xeaf0('0x1b')]+_0x48d5cc[_0xeaf0('0x1c')],_0x3ce2ee;if(_0x30ddcb>=_0x484d15){_0x30ddcb=_0x484d15;_0x3ce2ee=0xc8;}else{_0x3ce2ee=0xce;}_0x1d7b41[_0xeaf0('0x18')](_0x3ce2ee);return _0x1d7b41['set']('Content-Range',_0x3d6151+'-'+_0x30ddcb+'/'+_0x484d15)[_0xeaf0('0x1a')](_0x68c99f);}return null;};}function patchUpdates(_0x5057de){return function(_0x1cdd45){try{jsonpatch[_0xeaf0('0x1d')](_0x1cdd45,_0x5057de,!![]);}catch(_0x10de80){return BPromise['reject'](_0x10de80);}return _0x1cdd45[_0xeaf0('0x1e')]();};}function saveUpdates(_0x3a3294,_0x1355ea){return function(_0x438ffc){if(_0x438ffc){return _0x438ffc[_0xeaf0('0x1f')](_0x3a3294)[_0xeaf0('0x20')](function(_0x4f8c15){return _0x4f8c15;});}return null;};}function removeEntity(_0x1ccbd3,_0x582375){return function(_0x5d766f){if(_0x5d766f){return _0x5d766f[_0xeaf0('0x21')]()[_0xeaf0('0x20')](function(){_0x1ccbd3['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x5a0fe9,_0x20fee5){return function(_0x4a4ede){if(!_0x4a4ede){_0x5a0fe9[_0xeaf0('0x22')](0x194);}return _0x4a4ede;};}function handleError(_0x2fd76e,_0x4946e4){_0x4946e4=_0x4946e4||0x1f4;return function(_0xe52578){logger[_0xeaf0('0x23')](_0xe52578[_0xeaf0('0x24')]);if(_0xe52578[_0xeaf0('0x25')]){delete _0xe52578['name'];}_0x2fd76e['status'](_0x4946e4)[_0xeaf0('0x26')](_0xe52578);};}exports[_0xeaf0('0x27')]=function(_0xe74b77,_0x195576){var _0x14822a={},_0x5eedc={},_0x57f2cd={'count':0x0,'rows':[]};var _0x4373b5=_['map'](db[_0xeaf0('0x28')]['rawAttributes'],function(_0x437ae1){return{'name':_0x437ae1[_0xeaf0('0x29')],'type':_0x437ae1['type'][_0xeaf0('0x2a')]};});_0x5eedc[_0xeaf0('0x2b')]=_['map'](_0x4373b5,_0xeaf0('0x25'));_0x5eedc[_0xeaf0('0x2c')]=_[_0xeaf0('0x2d')](_0xe74b77['query']);_0x5eedc[_0xeaf0('0x2e')]=_[_0xeaf0('0x2f')](_0x5eedc[_0xeaf0('0x2b')],_0x5eedc[_0xeaf0('0x2c')]);_0x14822a[_0xeaf0('0x30')]=_[_0xeaf0('0x2f')](_0x5eedc[_0xeaf0('0x2b')],qs[_0xeaf0('0x31')](_0xe74b77['query']['fields']));_0x14822a[_0xeaf0('0x30')]=_0x14822a['attributes'][_0xeaf0('0x32')]?_0x14822a[_0xeaf0('0x30')]:_0x5eedc[_0xeaf0('0x2b')];if(!_0xe74b77[_0xeaf0('0x2c')]['hasOwnProperty'](_0xeaf0('0x33'))){_0x14822a[_0xeaf0('0x1c')]=qs[_0xeaf0('0x1c')](_0xe74b77[_0xeaf0('0x2c')][_0xeaf0('0x1c')]);_0x14822a['offset']=qs['offset'](_0xe74b77[_0xeaf0('0x2c')]['offset']);}_0x14822a[_0xeaf0('0x34')]=qs['sort'](_0xe74b77[_0xeaf0('0x2c')]['sort']);_0x14822a[_0xeaf0('0x35')]=qs['filters'](_[_0xeaf0('0x36')](_0xe74b77['query'],_0x5eedc[_0xeaf0('0x2e')]));if(_0xe74b77['query'][_0xeaf0('0x37')]){_0x14822a[_0xeaf0('0x35')]=_[_0xeaf0('0x38')](_0x14822a[_0xeaf0('0x35')],{'$or':_[_0xeaf0('0x39')](_0x4373b5,function(_0x51f14c){if(_0x51f14c[_0xeaf0('0x3a')]!=='VIRTUAL'){var _0x42666a={};_0x42666a[_0x51f14c['name']]={'$like':'%'+_0xe74b77[_0xeaf0('0x2c')]['filter']+'%'};return _0x42666a;}})});}_0x14822a=_[_0xeaf0('0x38')]({},_0x14822a,_0xe74b77[_0xeaf0('0x3b')]);var _0x5b830d={'where':_0x14822a[_0xeaf0('0x35')]};return db[_0xeaf0('0x28')][_0xeaf0('0x3c')](_0x5b830d)[_0xeaf0('0x20')](function(_0xbb5d3c){_0x57f2cd['count']=_0xbb5d3c;if(_0xe74b77[_0xeaf0('0x2c')][_0xeaf0('0x3d')]){_0x14822a[_0xeaf0('0x3e')]=[{'all':!![]}];}return db[_0xeaf0('0x28')]['findAll'](_0x14822a);})[_0xeaf0('0x20')](function(_0x5e678a){_0x57f2cd[_0xeaf0('0x3f')]=_0x5e678a;return _0x57f2cd;})[_0xeaf0('0x20')](respondWithFilteredResult(_0x195576,_0x14822a))[_0xeaf0('0x40')](handleError(_0x195576,null));};exports['show']=function(_0x5648bc,_0x1699e8){var _0x2b95bb={'raw':!![],'where':{'id':_0x5648bc[_0xeaf0('0x41')]['id']}},_0x9666ae={};_0x9666ae[_0xeaf0('0x2b')]=_[_0xeaf0('0x2d')](db['SmsTransferReport'][_0xeaf0('0x42')]);_0x9666ae['query']=_[_0xeaf0('0x2d')](_0x5648bc[_0xeaf0('0x2c')]);_0x9666ae[_0xeaf0('0x2e')]=_[_0xeaf0('0x2f')](_0x9666ae['model'],_0x9666ae[_0xeaf0('0x2c')]);_0x2b95bb[_0xeaf0('0x30')]=_['intersection'](_0x9666ae[_0xeaf0('0x2b')],qs[_0xeaf0('0x31')](_0x5648bc['query'][_0xeaf0('0x31')]));_0x2b95bb[_0xeaf0('0x30')]=_0x2b95bb[_0xeaf0('0x30')][_0xeaf0('0x32')]?_0x2b95bb['attributes']:_0x9666ae['model'];if(_0x5648bc[_0xeaf0('0x2c')]['includeAll']){_0x2b95bb[_0xeaf0('0x3e')]=[{'all':!![]}];}_0x2b95bb=_['merge']({},_0x2b95bb,_0x5648bc[_0xeaf0('0x3b')]);return db[_0xeaf0('0x28')][_0xeaf0('0x43')](_0x2b95bb)[_0xeaf0('0x20')](handleEntityNotFound(_0x1699e8,null))[_0xeaf0('0x20')](respondWithResult(_0x1699e8,null))[_0xeaf0('0x40')](handleError(_0x1699e8,null));};exports[_0xeaf0('0x44')]=function(_0x28c331,_0x1e25dc){return db[_0xeaf0('0x28')][_0xeaf0('0x44')](_0x28c331['body'],{})['then'](respondWithResult(_0x1e25dc,0xc9))['catch'](handleError(_0x1e25dc,null));};exports[_0xeaf0('0x1f')]=function(_0x529a34,_0x312fcf){if(_0x529a34[_0xeaf0('0x45')]['id']){delete _0x529a34['body']['id'];}return db[_0xeaf0('0x28')]['find']({'where':{'id':_0x529a34['params']['id']}})[_0xeaf0('0x20')](handleEntityNotFound(_0x312fcf,null))['then'](saveUpdates(_0x529a34[_0xeaf0('0x45')],null))['then'](respondWithResult(_0x312fcf,null))[_0xeaf0('0x40')](handleError(_0x312fcf,null));};exports[_0xeaf0('0x21')]=function(_0x56552a,_0x56c2d6){return db[_0xeaf0('0x28')]['find']({'where':{'id':_0x56552a[_0xeaf0('0x41')]['id']}})[_0xeaf0('0x20')](handleEntityNotFound(_0x56c2d6,null))['then'](removeEntity(_0x56c2d6,null))['catch'](handleError(_0x56c2d6,null));};exports[_0xeaf0('0x46')]=function(_0x401cb6,_0x2b66c3){return db[_0xeaf0('0x28')]['describe']()[_0xeaf0('0x20')](respondWithResult(_0x2b66c3,null))[_0xeaf0('0x40')](handleError(_0x2b66c3,null));};