Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / api / squareOdbc / squareOdbc.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 _0xa6fe=['get','ODBC','UserProfileResource','end','error','stack','name','send','index','map','SquareOdbc','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','test','dsn','odbc','openSync','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','undefined','limit','offset','set','Content-Range','save','update','then','destroy'];(function(_0x5e745e,_0xde2931){var _0x122dab=function(_0xe396a5){while(--_0xe396a5){_0x5e745e['push'](_0x5e745e['shift']());}};_0x122dab(++_0xde2931);}(_0xa6fe,0x90));var _0xea6f=function(_0x428547,_0x56e2af){_0x428547=_0x428547-0x0;var _0x4c350b=_0xa6fe[_0x428547];return _0x4c350b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xea6f('0x0'));var zipdir=require(_0xea6f('0x1'));var jsonpatch=require(_0xea6f('0x2'));var rp=require(_0xea6f('0x3'));var moment=require(_0xea6f('0x4'));var BPromise=require(_0xea6f('0x5'));var Mustache=require(_0xea6f('0x6'));var util=require('util');var path=require(_0xea6f('0x7'));var sox=require('sox');var csv=require(_0xea6f('0x8'));var ejs=require(_0xea6f('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xea6f('0xa'));var squel=require(_0xea6f('0xb'));var crypto=require(_0xea6f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xea6f('0xd'));var toCsv=require(_0xea6f('0x8'));var querystring=require(_0xea6f('0xe'));var Papa=require(_0xea6f('0xf'));var Redis=require(_0xea6f('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xea6f('0x11'));var as=require(_0xea6f('0x12'));var hardwareService=require(_0xea6f('0x13'));var logger=require(_0xea6f('0x14'))('api');var utils=require(_0xea6f('0x15'));var config=require(_0xea6f('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xea6f('0x17'))['db'];function respondWithStatusCode(_0x3e4f3c,_0x3b1acc){_0x3b1acc=_0x3b1acc||0xcc;return function(_0x3b6806){if(_0x3b6806){return _0x3e4f3c[_0xea6f('0x18')](_0x3b1acc);}return _0x3e4f3c['status'](_0x3b1acc)['end']();};}function respondWithResult(_0x1cc951,_0x26d4d1){_0x26d4d1=_0x26d4d1||0xc8;return function(_0x171f30){if(_0x171f30){return _0x1cc951[_0xea6f('0x19')](_0x26d4d1)[_0xea6f('0x1a')](_0x171f30);}};}function respondWithFilteredResult(_0xd62a6f,_0x5d673c){return function(_0x59f854){if(_0x59f854){var _0x16d0ae=typeof _0x5d673c['offset']===_0xea6f('0x1b')&&typeof _0x5d673c[_0xea6f('0x1c')]===_0xea6f('0x1b');var _0x320071=_0x59f854['count'];var _0x28b205=_0x16d0ae?0x0:_0x5d673c[_0xea6f('0x1d')];var _0x3a6008=_0x16d0ae?_0x59f854['count']:_0x5d673c['offset']+_0x5d673c[_0xea6f('0x1c')];var _0x284298;if(_0x3a6008>=_0x320071){_0x3a6008=_0x320071;_0x284298=0xc8;}else{_0x284298=0xce;}_0xd62a6f[_0xea6f('0x19')](_0x284298);return _0xd62a6f[_0xea6f('0x1e')](_0xea6f('0x1f'),_0x28b205+'-'+_0x3a6008+'/'+_0x320071)[_0xea6f('0x1a')](_0x59f854);}return null;};}function patchUpdates(_0x6e66d8){return function(_0x1aeec2){try{jsonpatch['apply'](_0x1aeec2,_0x6e66d8,!![]);}catch(_0x435646){return BPromise['reject'](_0x435646);}return _0x1aeec2[_0xea6f('0x20')]();};}function saveUpdates(_0xd8afe4,_0x2d0901){return function(_0x609941){if(_0x609941){return _0x609941[_0xea6f('0x21')](_0xd8afe4)[_0xea6f('0x22')](function(_0x15e1b3){return _0x15e1b3;});}return null;};}function removeEntity(_0x19830f,_0x11e7a8){return function(_0x500c98){if(_0x500c98){return _0x500c98[_0xea6f('0x23')]()[_0xea6f('0x22')](function(){var _0x8ed09f=_0x500c98[_0xea6f('0x24')]({'plain':!![]});var _0x49ec49=_0xea6f('0x25');return db[_0xea6f('0x26')][_0xea6f('0x23')]({'where':{'type':_0x49ec49,'resourceId':_0x8ed09f['id']}})['then'](function(){return _0x500c98;});})[_0xea6f('0x22')](function(){_0x19830f['status'](0xcc)[_0xea6f('0x27')]();});}};}function handleEntityNotFound(_0x5e5e76,_0xec9576){return function(_0x7c78f6){if(!_0x7c78f6){_0x5e5e76['sendStatus'](0x194);}return _0x7c78f6;};}function handleError(_0x4a2ecf,_0x19c5a8){_0x19c5a8=_0x19c5a8||0x1f4;return function(_0x2ca820){logger[_0xea6f('0x28')](_0x2ca820[_0xea6f('0x29')]);if(_0x2ca820[_0xea6f('0x2a')]){delete _0x2ca820[_0xea6f('0x2a')];}_0x4a2ecf[_0xea6f('0x19')](_0x19c5a8)[_0xea6f('0x2b')](_0x2ca820);};}exports[_0xea6f('0x2c')]=function(_0x1f0b8f,_0x23141b){var _0xc4486f={},_0x402dc1={},_0x29a2e5={'count':0x0,'rows':[]};var _0x206802=_[_0xea6f('0x2d')](db[_0xea6f('0x2e')][_0xea6f('0x2f')],function(_0x573244){return{'name':_0x573244[_0xea6f('0x30')],'type':_0x573244[_0xea6f('0x31')][_0xea6f('0x32')]};});_0x402dc1['model']=_[_0xea6f('0x2d')](_0x206802,'name');_0x402dc1['query']=_[_0xea6f('0x33')](_0x1f0b8f[_0xea6f('0x34')]);_0x402dc1[_0xea6f('0x35')]=_[_0xea6f('0x36')](_0x402dc1['model'],_0x402dc1[_0xea6f('0x34')]);_0xc4486f['attributes']=_['intersection'](_0x402dc1[_0xea6f('0x37')],qs[_0xea6f('0x38')](_0x1f0b8f[_0xea6f('0x34')][_0xea6f('0x38')]));_0xc4486f[_0xea6f('0x39')]=_0xc4486f[_0xea6f('0x39')][_0xea6f('0x3a')]?_0xc4486f['attributes']:_0x402dc1[_0xea6f('0x37')];if(!_0x1f0b8f[_0xea6f('0x34')][_0xea6f('0x3b')](_0xea6f('0x3c'))){_0xc4486f[_0xea6f('0x1c')]=qs[_0xea6f('0x1c')](_0x1f0b8f['query'][_0xea6f('0x1c')]);_0xc4486f[_0xea6f('0x1d')]=qs[_0xea6f('0x1d')](_0x1f0b8f[_0xea6f('0x34')][_0xea6f('0x1d')]);}_0xc4486f['order']=qs[_0xea6f('0x3d')](_0x1f0b8f[_0xea6f('0x34')][_0xea6f('0x3d')]);_0xc4486f[_0xea6f('0x3e')]=qs[_0xea6f('0x35')](_[_0xea6f('0x3f')](_0x1f0b8f['query'],_0x402dc1[_0xea6f('0x35')]),_0x206802);if(_0x1f0b8f[_0xea6f('0x34')][_0xea6f('0x40')]){_0xc4486f[_0xea6f('0x3e')]=_[_0xea6f('0x41')](_0xc4486f[_0xea6f('0x3e')],{'$or':_['map'](_0x206802,function(_0x36219e){if(_0x36219e[_0xea6f('0x31')]!==_0xea6f('0x42')){var _0x1b4146={};_0x1b4146[_0x36219e[_0xea6f('0x2a')]]={'$like':'%'+_0x1f0b8f['query']['filter']+'%'};return _0x1b4146;}})});}_0xc4486f=_[_0xea6f('0x41')]({},_0xc4486f,_0x1f0b8f[_0xea6f('0x43')]);var _0x5a5b54={'where':_0xc4486f['where']};return db[_0xea6f('0x2e')][_0xea6f('0x44')](_0x5a5b54)[_0xea6f('0x22')](function(_0x29e5a7){_0x29a2e5[_0xea6f('0x44')]=_0x29e5a7;if(_0x1f0b8f[_0xea6f('0x34')][_0xea6f('0x45')]){_0xc4486f[_0xea6f('0x46')]=[{'all':!![]}];}return db[_0xea6f('0x2e')][_0xea6f('0x47')](_0xc4486f);})[_0xea6f('0x22')](function(_0x35fdaf){_0x29a2e5[_0xea6f('0x48')]=_0x35fdaf;return _0x29a2e5;})[_0xea6f('0x22')](respondWithFilteredResult(_0x23141b,_0xc4486f))[_0xea6f('0x49')](handleError(_0x23141b,null));};exports[_0xea6f('0x4a')]=function(_0x64732b,_0x595251){var _0x145d63={'raw':!![],'where':{'id':_0x64732b['params']['id']}},_0xc13dd6={};_0xc13dd6[_0xea6f('0x37')]=_['keys'](db[_0xea6f('0x2e')][_0xea6f('0x2f')]);_0xc13dd6['query']=_['keys'](_0x64732b[_0xea6f('0x34')]);_0xc13dd6[_0xea6f('0x35')]=_[_0xea6f('0x36')](_0xc13dd6[_0xea6f('0x37')],_0xc13dd6['query']);_0x145d63[_0xea6f('0x39')]=_[_0xea6f('0x36')](_0xc13dd6[_0xea6f('0x37')],qs[_0xea6f('0x38')](_0x64732b[_0xea6f('0x34')][_0xea6f('0x38')]));_0x145d63[_0xea6f('0x39')]=_0x145d63[_0xea6f('0x39')][_0xea6f('0x3a')]?_0x145d63['attributes']:_0xc13dd6['model'];if(_0x64732b[_0xea6f('0x34')]['includeAll']){_0x145d63['include']=[{'all':!![]}];}_0x145d63=_[_0xea6f('0x41')]({},_0x145d63,_0x64732b['options']);return db[_0xea6f('0x2e')][_0xea6f('0x4b')](_0x145d63)[_0xea6f('0x22')](handleEntityNotFound(_0x595251,null))[_0xea6f('0x22')](respondWithResult(_0x595251,null))[_0xea6f('0x49')](handleError(_0x595251,null));};exports[_0xea6f('0x4c')]=function(_0x21713f,_0xcc1e0a){return db[_0xea6f('0x2e')][_0xea6f('0x4c')](_0x21713f[_0xea6f('0x4d')],{})['then'](function(_0x3cb5d9){var _0x32118d=_0x21713f['user'][_0xea6f('0x24')]({'plain':!![]});if(!_0x32118d)throw new Error(_0xea6f('0x4e'));if(_0x32118d[_0xea6f('0x4f')]===_0xea6f('0x50')){var _0x14c6e0=_0x3cb5d9[_0xea6f('0x24')]({'plain':!![]});var _0x6b93c7=_0xea6f('0x25');return db[_0xea6f('0x51')][_0xea6f('0x4b')]({'where':{'name':_0x6b93c7,'userProfileId':_0x32118d[_0xea6f('0x52')]},'raw':!![]})[_0xea6f('0x22')](function(_0x2a8eb1){if(_0x2a8eb1&&_0x2a8eb1[_0xea6f('0x53')]===0x0){return db[_0xea6f('0x26')][_0xea6f('0x4c')]({'name':_0x14c6e0[_0xea6f('0x2a')],'resourceId':_0x14c6e0['id'],'type':_0x2a8eb1[_0xea6f('0x2a')],'sectionId':_0x2a8eb1['id']},{})[_0xea6f('0x22')](function(){return _0x3cb5d9;});}else{return _0x3cb5d9;}})[_0xea6f('0x49')](function(_0x404ea5){logger[_0xea6f('0x28')](_0xea6f('0x54'),_0x404ea5);throw _0x404ea5;});}return _0x3cb5d9;})[_0xea6f('0x22')](respondWithResult(_0xcc1e0a,0xc9))[_0xea6f('0x49')](handleError(_0xcc1e0a,null));};exports['update']=function(_0x12bdc7,_0x41c960){if(_0x12bdc7['body']['id']){delete _0x12bdc7[_0xea6f('0x4d')]['id'];}return db['SquareOdbc'][_0xea6f('0x4b')]({'where':{'id':_0x12bdc7[_0xea6f('0x55')]['id']}})['then'](handleEntityNotFound(_0x41c960,null))['then'](saveUpdates(_0x12bdc7[_0xea6f('0x4d')],null))[_0xea6f('0x22')](respondWithResult(_0x41c960,null))[_0xea6f('0x49')](handleError(_0x41c960,null));};exports[_0xea6f('0x23')]=function(_0x2d8dfb,_0x2800ea){return db['SquareOdbc'][_0xea6f('0x4b')]({'where':{'id':_0x2d8dfb[_0xea6f('0x55')]['id']}})['then'](handleEntityNotFound(_0x2800ea,null))[_0xea6f('0x22')](removeEntity(_0x2800ea,null))[_0xea6f('0x49')](handleError(_0x2800ea,null));};exports[_0xea6f('0x56')]=function(_0x313ead,_0x5be336,_0x2cf4ea){var _0xd5d334;return db[_0xea6f('0x2e')]['find']({'where':{'id':_0x313ead[_0xea6f('0x55')]['id']},'attributes':['id',_0xea6f('0x57')]})[_0xea6f('0x22')](handleEntityNotFound(_0x5be336,null))[_0xea6f('0x22')](function(_0x13004d){if(_0x13004d){var _0x524617=require(_0xea6f('0x58'))();_0x524617[_0xea6f('0x59')](_0x13004d['dsn']);_0x524617['closeSync']();return _0x13004d;}})['then'](respondWithResult(_0x5be336,null))['catch'](handleError(_0x5be336,null));};