Built motion from commit 97153652.|2.6.26
[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 _0x2f77=['fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','end','status','json','undefined','limit','count','offset','set','apply','reject','then','sendStatus','stack','name','index','map','SmsTransferReport','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','options','include','findAll','catch','show','params','includeAll','create','update','body','destroy','find','describe','eml-format','rimraf','zip-dir'];(function(_0x10249f,_0x3af1bc){var _0x4fe5b2=function(_0x5094a9){while(--_0x5094a9){_0x10249f['push'](_0x10249f['shift']());}};_0x4fe5b2(++_0x3af1bc);}(_0x2f77,0x16a));var _0x72f7=function(_0x535c80,_0x4a4e71){_0x535c80=_0x535c80-0x0;var _0x57a4d9=_0x2f77[_0x535c80];return _0x57a4d9;};'use strict';var emlformat=require(_0x72f7('0x0'));var rimraf=require(_0x72f7('0x1'));var zipdir=require(_0x72f7('0x2'));var jsonpatch=require(_0x72f7('0x3'));var rp=require(_0x72f7('0x4'));var moment=require(_0x72f7('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x72f7('0x6'));var util=require(_0x72f7('0x7'));var path=require(_0x72f7('0x8'));var sox=require(_0x72f7('0x9'));var csv=require(_0x72f7('0xa'));var ejs=require(_0x72f7('0xb'));var fs=require('fs');var fs_extra=require(_0x72f7('0xc'));var _=require(_0x72f7('0xd'));var squel=require('squel');var crypto=require(_0x72f7('0xe'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x72f7('0xa'));var querystring=require(_0x72f7('0xf'));var Papa=require('papaparse');var Redis=require(_0x72f7('0x10'));var authService=require(_0x72f7('0x11'));var qs=require(_0x72f7('0x12'));var as=require(_0x72f7('0x13'));var hardwareService=require(_0x72f7('0x14'));var logger=require('../../config/logger')(_0x72f7('0x15'));var utils=require('../../config/utils');var config=require(_0x72f7('0x16'));var licenseUtil=require(_0x72f7('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x587d6f,_0x402b6f){_0x402b6f=_0x402b6f||0xcc;return function(_0x3b98b1){if(_0x3b98b1){return _0x587d6f['sendStatus'](_0x402b6f);}return _0x587d6f['status'](_0x402b6f)[_0x72f7('0x18')]();};}function respondWithResult(_0x1e6116,_0x22b91f){_0x22b91f=_0x22b91f||0xc8;return function(_0x5b2002){if(_0x5b2002){return _0x1e6116[_0x72f7('0x19')](_0x22b91f)[_0x72f7('0x1a')](_0x5b2002);}};}function respondWithFilteredResult(_0x17d6ba,_0xe662cc){return function(_0x34e6b8){if(_0x34e6b8){var _0x4dcaec=typeof _0xe662cc['offset']===_0x72f7('0x1b')&&typeof _0xe662cc[_0x72f7('0x1c')]===_0x72f7('0x1b');var _0x654400=_0x34e6b8[_0x72f7('0x1d')];var _0xca1775=_0x4dcaec?0x0:_0xe662cc['offset'];var _0x67aebe=_0x4dcaec?_0x34e6b8[_0x72f7('0x1d')]:_0xe662cc[_0x72f7('0x1e')]+_0xe662cc[_0x72f7('0x1c')];var _0x5b9e1f;if(_0x67aebe>=_0x654400){_0x67aebe=_0x654400;_0x5b9e1f=0xc8;}else{_0x5b9e1f=0xce;}_0x17d6ba[_0x72f7('0x19')](_0x5b9e1f);return _0x17d6ba[_0x72f7('0x1f')]('Content-Range',_0xca1775+'-'+_0x67aebe+'/'+_0x654400)['json'](_0x34e6b8);}return null;};}function patchUpdates(_0x100f82){return function(_0x2b781c){try{jsonpatch[_0x72f7('0x20')](_0x2b781c,_0x100f82,!![]);}catch(_0x536abd){return BPromise[_0x72f7('0x21')](_0x536abd);}return _0x2b781c['save']();};}function saveUpdates(_0x1b95dd,_0x52dff8){return function(_0x3c11cf){if(_0x3c11cf){return _0x3c11cf['update'](_0x1b95dd)[_0x72f7('0x22')](function(_0xc6ef1f){return _0xc6ef1f;});}return null;};}function removeEntity(_0x40e416,_0xe84b88){return function(_0x4256c3){if(_0x4256c3){return _0x4256c3['destroy']()[_0x72f7('0x22')](function(){_0x40e416['status'](0xcc)[_0x72f7('0x18')]();});}};}function handleEntityNotFound(_0x1e736a,_0x353fab){return function(_0xdea1b9){if(!_0xdea1b9){_0x1e736a[_0x72f7('0x23')](0x194);}return _0xdea1b9;};}function handleError(_0x37dc6f,_0x183e54){_0x183e54=_0x183e54||0x1f4;return function(_0x32fd8b){logger['error'](_0x32fd8b[_0x72f7('0x24')]);if(_0x32fd8b[_0x72f7('0x25')]){delete _0x32fd8b['name'];}_0x37dc6f[_0x72f7('0x19')](_0x183e54)['send'](_0x32fd8b);};}exports[_0x72f7('0x26')]=function(_0x32f24d,_0x10439d){var _0xbf705e={},_0x9d409c={},_0x29d320={'count':0x0,'rows':[]};var _0x320281=_[_0x72f7('0x27')](db[_0x72f7('0x28')][_0x72f7('0x29')],function(_0x545e04){return{'name':_0x545e04[_0x72f7('0x2a')],'type':_0x545e04[_0x72f7('0x2b')][_0x72f7('0x2c')]};});_0x9d409c['model']=_['map'](_0x320281,_0x72f7('0x25'));_0x9d409c['query']=_[_0x72f7('0x2d')](_0x32f24d[_0x72f7('0x2e')]);_0x9d409c[_0x72f7('0x2f')]=_[_0x72f7('0x30')](_0x9d409c[_0x72f7('0x31')],_0x9d409c['query']);_0xbf705e[_0x72f7('0x32')]=_[_0x72f7('0x30')](_0x9d409c[_0x72f7('0x31')],qs[_0x72f7('0x33')](_0x32f24d['query']['fields']));_0xbf705e['attributes']=_0xbf705e['attributes'][_0x72f7('0x34')]?_0xbf705e[_0x72f7('0x32')]:_0x9d409c[_0x72f7('0x31')];if(!_0x32f24d[_0x72f7('0x2e')]['hasOwnProperty'](_0x72f7('0x35'))){_0xbf705e['limit']=qs[_0x72f7('0x1c')](_0x32f24d[_0x72f7('0x2e')][_0x72f7('0x1c')]);_0xbf705e[_0x72f7('0x1e')]=qs['offset'](_0x32f24d[_0x72f7('0x2e')][_0x72f7('0x1e')]);}_0xbf705e[_0x72f7('0x36')]=qs[_0x72f7('0x37')](_0x32f24d[_0x72f7('0x2e')]['sort']);_0xbf705e[_0x72f7('0x38')]=qs[_0x72f7('0x2f')](_[_0x72f7('0x39')](_0x32f24d['query'],_0x9d409c['filters']),_0x320281);if(_0x32f24d[_0x72f7('0x2e')][_0x72f7('0x3a')]){_0xbf705e[_0x72f7('0x38')]=_[_0x72f7('0x3b')](_0xbf705e[_0x72f7('0x38')],{'$or':_[_0x72f7('0x27')](_0x320281,function(_0x4ab9bb){if(_0x4ab9bb[_0x72f7('0x2b')]!=='VIRTUAL'){var _0x19712e={};_0x19712e[_0x4ab9bb['name']]={'$like':'%'+_0x32f24d[_0x72f7('0x2e')][_0x72f7('0x3a')]+'%'};return _0x19712e;}})});}_0xbf705e=_[_0x72f7('0x3b')]({},_0xbf705e,_0x32f24d[_0x72f7('0x3c')]);var _0x5ac217={'where':_0xbf705e['where']};return db[_0x72f7('0x28')]['count'](_0x5ac217)['then'](function(_0x213db3){_0x29d320[_0x72f7('0x1d')]=_0x213db3;if(_0x32f24d[_0x72f7('0x2e')]['includeAll']){_0xbf705e[_0x72f7('0x3d')]=[{'all':!![]}];}return db['SmsTransferReport'][_0x72f7('0x3e')](_0xbf705e);})['then'](function(_0x357a97){_0x29d320['rows']=_0x357a97;return _0x29d320;})['then'](respondWithFilteredResult(_0x10439d,_0xbf705e))[_0x72f7('0x3f')](handleError(_0x10439d,null));};exports[_0x72f7('0x40')]=function(_0x4f4d8f,_0x389ac4){var _0x597224={'raw':!![],'where':{'id':_0x4f4d8f[_0x72f7('0x41')]['id']}},_0x1bf75a={};_0x1bf75a[_0x72f7('0x31')]=_[_0x72f7('0x2d')](db['SmsTransferReport']['rawAttributes']);_0x1bf75a[_0x72f7('0x2e')]=_[_0x72f7('0x2d')](_0x4f4d8f['query']);_0x1bf75a[_0x72f7('0x2f')]=_['intersection'](_0x1bf75a[_0x72f7('0x31')],_0x1bf75a['query']);_0x597224[_0x72f7('0x32')]=_[_0x72f7('0x30')](_0x1bf75a[_0x72f7('0x31')],qs['fields'](_0x4f4d8f[_0x72f7('0x2e')][_0x72f7('0x33')]));_0x597224['attributes']=_0x597224[_0x72f7('0x32')][_0x72f7('0x34')]?_0x597224[_0x72f7('0x32')]:_0x1bf75a[_0x72f7('0x31')];if(_0x4f4d8f[_0x72f7('0x2e')][_0x72f7('0x42')]){_0x597224[_0x72f7('0x3d')]=[{'all':!![]}];}_0x597224=_[_0x72f7('0x3b')]({},_0x597224,_0x4f4d8f[_0x72f7('0x3c')]);return db[_0x72f7('0x28')]['find'](_0x597224)[_0x72f7('0x22')](handleEntityNotFound(_0x389ac4,null))[_0x72f7('0x22')](respondWithResult(_0x389ac4,null))[_0x72f7('0x3f')](handleError(_0x389ac4,null));};exports[_0x72f7('0x43')]=function(_0x21744b,_0xb1127a){return db['SmsTransferReport'][_0x72f7('0x43')](_0x21744b['body'],{})[_0x72f7('0x22')](respondWithResult(_0xb1127a,0xc9))['catch'](handleError(_0xb1127a,null));};exports[_0x72f7('0x44')]=function(_0x13b20a,_0xfa845c){if(_0x13b20a[_0x72f7('0x45')]['id']){delete _0x13b20a[_0x72f7('0x45')]['id'];}return db[_0x72f7('0x28')]['find']({'where':{'id':_0x13b20a['params']['id']}})[_0x72f7('0x22')](handleEntityNotFound(_0xfa845c,null))[_0x72f7('0x22')](saveUpdates(_0x13b20a[_0x72f7('0x45')],null))[_0x72f7('0x22')](respondWithResult(_0xfa845c,null))[_0x72f7('0x3f')](handleError(_0xfa845c,null));};exports[_0x72f7('0x46')]=function(_0x5b4852,_0x3b3461){return db[_0x72f7('0x28')][_0x72f7('0x47')]({'where':{'id':_0x5b4852[_0x72f7('0x41')]['id']}})[_0x72f7('0x22')](handleEntityNotFound(_0x3b3461,null))['then'](removeEntity(_0x3b3461,null))[_0x72f7('0x3f')](handleError(_0x3b3461,null));};exports[_0x72f7('0x48')]=function(_0x239c39,_0x4686b9){return db['SmsTransferReport']['describe']()[_0x72f7('0x22')](respondWithResult(_0x4686b9,null))[_0x72f7('0x3f')](handleError(_0x4686b9,null));};