Built motion from commit (unavailable).|2.5.2
[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 _0x61f0=['Content-Range','apply','reject','save','update','destroy','then','get','ODBC','UserProfileResource','error','stack','name','send','index','map','SquareOdbc','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','params','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','test','dsn','odbc','openSync','closeSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','status','end','json','offset'];(function(_0x38537f,_0x252124){var _0x141e23=function(_0x2809b5){while(--_0x2809b5){_0x38537f['push'](_0x38537f['shift']());}};_0x141e23(++_0x252124);}(_0x61f0,0x19b));var _0x061f=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0x61f0[_0x3b380d];return _0x54502b;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x061f('0x0'));var rimraf=require(_0x061f('0x1'));var zipdir=require(_0x061f('0x2'));var jsonpatch=require(_0x061f('0x3'));var rp=require(_0x061f('0x4'));var moment=require(_0x061f('0x5'));var BPromise=require(_0x061f('0x6'));var Mustache=require('mustache');var util=require(_0x061f('0x7'));var path=require(_0x061f('0x8'));var sox=require(_0x061f('0x9'));var csv=require(_0x061f('0xa'));var ejs=require(_0x061f('0xb'));var fs=require('fs');var _=require(_0x061f('0xc'));var squel=require(_0x061f('0xd'));var crypto=require(_0x061f('0xe'));var jsforce=require(_0x061f('0xf'));var deskjs=require(_0x061f('0x10'));var toCsv=require(_0x061f('0xa'));var querystring=require(_0x061f('0x11'));var Papa=require('papaparse');var Redis=require(_0x061f('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x061f('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x061f('0x14'));var logger=require(_0x061f('0x15'))(_0x061f('0x16'));var utils=require(_0x061f('0x17'));var config=require('../../config/environment');var db=require(_0x061f('0x18'))['db'];function respondWithStatusCode(_0x5ab34e,_0x521922){_0x521922=_0x521922||0xcc;return function(_0x26cf9b){if(_0x26cf9b){return _0x5ab34e['sendStatus'](_0x521922);}return _0x5ab34e[_0x061f('0x19')](_0x521922)[_0x061f('0x1a')]();};}function respondWithResult(_0x43db6b,_0x53fd03){_0x53fd03=_0x53fd03||0xc8;return function(_0x57ab57){if(_0x57ab57){return _0x43db6b['status'](_0x53fd03)[_0x061f('0x1b')](_0x57ab57);}};}function respondWithFilteredResult(_0x36174a,_0x1dc669){return function(_0x56a385){if(_0x56a385){var _0x2c60f6=_0x56a385['count'],_0x1876d7=_0x1dc669[_0x061f('0x1c')],_0x9beb26=_0x1dc669[_0x061f('0x1c')]+_0x1dc669['limit'],_0x49d7cb;if(_0x9beb26>=_0x2c60f6){_0x9beb26=_0x2c60f6;_0x49d7cb=0xc8;}else{_0x49d7cb=0xce;}_0x36174a[_0x061f('0x19')](_0x49d7cb);return _0x36174a['set'](_0x061f('0x1d'),_0x1876d7+'-'+_0x9beb26+'/'+_0x2c60f6)[_0x061f('0x1b')](_0x56a385);}return null;};}function patchUpdates(_0x76bfa0){return function(_0x5e9e41){try{jsonpatch[_0x061f('0x1e')](_0x5e9e41,_0x76bfa0,!![]);}catch(_0x5a2b09){return BPromise[_0x061f('0x1f')](_0x5a2b09);}return _0x5e9e41[_0x061f('0x20')]();};}function saveUpdates(_0x1e81ac,_0x1bb63f){return function(_0x416534){if(_0x416534){return _0x416534[_0x061f('0x21')](_0x1e81ac)['then'](function(_0x49cae3){return _0x49cae3;});}return null;};}function removeEntity(_0x470559,_0x171cd7){return function(_0x1c3190){if(_0x1c3190){return _0x1c3190[_0x061f('0x22')]()[_0x061f('0x23')](function(){var _0x1d9fba=_0x1c3190[_0x061f('0x24')]({'plain':!![]});var _0x7865cf=_0x061f('0x25');return db[_0x061f('0x26')][_0x061f('0x22')]({'where':{'type':_0x7865cf,'resourceId':_0x1d9fba['id']}})[_0x061f('0x23')](function(){return _0x1c3190;});})['then'](function(){_0x470559[_0x061f('0x19')](0xcc)[_0x061f('0x1a')]();});}};}function handleEntityNotFound(_0x305d61,_0x54e426){return function(_0x4ae9b5){if(!_0x4ae9b5){_0x305d61['sendStatus'](0x194);}return _0x4ae9b5;};}function handleError(_0x13ad55,_0x185367){_0x185367=_0x185367||0x1f4;return function(_0x436ead){logger[_0x061f('0x27')](_0x436ead[_0x061f('0x28')]);if(_0x436ead[_0x061f('0x29')]){delete _0x436ead[_0x061f('0x29')];}_0x13ad55[_0x061f('0x19')](_0x185367)[_0x061f('0x2a')](_0x436ead);};}exports[_0x061f('0x2b')]=function(_0x13b9d5,_0x36a889){var _0x1b25b2={},_0x29e6a7={},_0x3b3a82={'count':0x0,'rows':[]};var _0xa926d4=_[_0x061f('0x2c')](db[_0x061f('0x2d')][_0x061f('0x2e')],function(_0x509078){return{'name':_0x509078[_0x061f('0x2f')],'type':_0x509078[_0x061f('0x30')][_0x061f('0x31')]};});_0x29e6a7[_0x061f('0x32')]=_[_0x061f('0x2c')](_0xa926d4,_0x061f('0x29'));_0x29e6a7[_0x061f('0x33')]=_[_0x061f('0x34')](_0x13b9d5[_0x061f('0x33')]);_0x29e6a7[_0x061f('0x35')]=_[_0x061f('0x36')](_0x29e6a7[_0x061f('0x32')],_0x29e6a7[_0x061f('0x33')]);_0x1b25b2[_0x061f('0x37')]=_['intersection'](_0x29e6a7[_0x061f('0x32')],qs[_0x061f('0x38')](_0x13b9d5[_0x061f('0x33')][_0x061f('0x38')]));_0x1b25b2[_0x061f('0x37')]=_0x1b25b2[_0x061f('0x37')][_0x061f('0x39')]?_0x1b25b2[_0x061f('0x37')]:_0x29e6a7[_0x061f('0x32')];if(!_0x13b9d5[_0x061f('0x33')][_0x061f('0x3a')](_0x061f('0x3b'))){_0x1b25b2['limit']=qs['limit'](_0x13b9d5[_0x061f('0x33')][_0x061f('0x3c')]);_0x1b25b2[_0x061f('0x1c')]=qs['offset'](_0x13b9d5['query'][_0x061f('0x1c')]);}_0x1b25b2['order']=qs[_0x061f('0x3d')](_0x13b9d5[_0x061f('0x33')]['sort']);_0x1b25b2[_0x061f('0x3e')]=qs[_0x061f('0x35')](_['pick'](_0x13b9d5[_0x061f('0x33')],_0x29e6a7['filters']),_0xa926d4);if(_0x13b9d5['query'][_0x061f('0x3f')]){_0x1b25b2[_0x061f('0x3e')]=_[_0x061f('0x40')](_0x1b25b2['where'],{'$or':_[_0x061f('0x2c')](_0xa926d4,function(_0x569eac){if(_0x569eac[_0x061f('0x30')]!==_0x061f('0x41')){var _0x56d7d9={};_0x56d7d9[_0x569eac[_0x061f('0x29')]]={'$like':'%'+_0x13b9d5[_0x061f('0x33')]['filter']+'%'};return _0x56d7d9;}})});}_0x1b25b2=_[_0x061f('0x40')]({},_0x1b25b2,_0x13b9d5[_0x061f('0x42')]);var _0x37669e={'where':_0x1b25b2[_0x061f('0x3e')]};return db['SquareOdbc'][_0x061f('0x43')](_0x37669e)['then'](function(_0x1c0aab){_0x3b3a82[_0x061f('0x43')]=_0x1c0aab;if(_0x13b9d5['query'][_0x061f('0x44')]){_0x1b25b2[_0x061f('0x45')]=[{'all':!![]}];}return db[_0x061f('0x2d')][_0x061f('0x46')](_0x1b25b2);})[_0x061f('0x23')](function(_0x564b0a){_0x3b3a82[_0x061f('0x47')]=_0x564b0a;return _0x3b3a82;})[_0x061f('0x23')](respondWithFilteredResult(_0x36a889,_0x1b25b2))[_0x061f('0x48')](handleError(_0x36a889,null));};exports[_0x061f('0x49')]=function(_0x3197db,_0x408856){var _0x289fae={'raw':!![],'where':{'id':_0x3197db[_0x061f('0x4a')]['id']}},_0x3ad718={};_0x3ad718[_0x061f('0x32')]=_[_0x061f('0x34')](db[_0x061f('0x2d')][_0x061f('0x2e')]);_0x3ad718[_0x061f('0x33')]=_['keys'](_0x3197db[_0x061f('0x33')]);_0x3ad718['filters']=_[_0x061f('0x36')](_0x3ad718[_0x061f('0x32')],_0x3ad718['query']);_0x289fae[_0x061f('0x37')]=_[_0x061f('0x36')](_0x3ad718[_0x061f('0x32')],qs['fields'](_0x3197db['query']['fields']));_0x289fae[_0x061f('0x37')]=_0x289fae[_0x061f('0x37')][_0x061f('0x39')]?_0x289fae['attributes']:_0x3ad718['model'];if(_0x3197db[_0x061f('0x33')][_0x061f('0x44')]){_0x289fae[_0x061f('0x45')]=[{'all':!![]}];}_0x289fae=_[_0x061f('0x40')]({},_0x289fae,_0x3197db[_0x061f('0x42')]);return db[_0x061f('0x2d')][_0x061f('0x4b')](_0x289fae)['then'](handleEntityNotFound(_0x408856,null))[_0x061f('0x23')](respondWithResult(_0x408856,null))['catch'](handleError(_0x408856,null));};exports[_0x061f('0x4c')]=function(_0x488871,_0x1615f9){return db[_0x061f('0x2d')][_0x061f('0x4c')](_0x488871[_0x061f('0x4d')],{})[_0x061f('0x23')](function(_0x260c50){var _0x15ac6d=_0x488871[_0x061f('0x4e')]['get']({'plain':!![]});if(!_0x15ac6d)throw new Error(_0x061f('0x4f'));if(_0x15ac6d[_0x061f('0x50')]==='user'){var _0x31457f=_0x260c50[_0x061f('0x24')]({'plain':!![]});var _0xf0653a=_0x061f('0x25');return db[_0x061f('0x51')][_0x061f('0x4b')]({'where':{'name':_0xf0653a,'userProfileId':_0x15ac6d[_0x061f('0x52')]},'raw':!![]})['then'](function(_0x5593f5){if(_0x5593f5&&_0x5593f5['autoAssociation']===0x0){return db[_0x061f('0x26')][_0x061f('0x4c')]({'name':_0x31457f[_0x061f('0x29')],'resourceId':_0x31457f['id'],'type':_0x5593f5['name'],'sectionId':_0x5593f5['id']},{})[_0x061f('0x23')](function(){return _0x260c50;});}else{return _0x260c50;}})['catch'](function(_0x38c967){logger[_0x061f('0x27')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x38c967);throw _0x38c967;});}return _0x260c50;})[_0x061f('0x23')](respondWithResult(_0x1615f9,0xc9))[_0x061f('0x48')](handleError(_0x1615f9,null));};exports[_0x061f('0x21')]=function(_0x3c2f92,_0x37937a){if(_0x3c2f92[_0x061f('0x4d')]['id']){delete _0x3c2f92[_0x061f('0x4d')]['id'];}return db['SquareOdbc'][_0x061f('0x4b')]({'where':{'id':_0x3c2f92[_0x061f('0x4a')]['id']}})[_0x061f('0x23')](handleEntityNotFound(_0x37937a,null))[_0x061f('0x23')](saveUpdates(_0x3c2f92['body'],null))['then'](respondWithResult(_0x37937a,null))['catch'](handleError(_0x37937a,null));};exports['destroy']=function(_0x4297a8,_0x109dd2){return db['SquareOdbc'][_0x061f('0x4b')]({'where':{'id':_0x4297a8[_0x061f('0x4a')]['id']}})['then'](handleEntityNotFound(_0x109dd2,null))['then'](removeEntity(_0x109dd2,null))[_0x061f('0x48')](handleError(_0x109dd2,null));};exports[_0x061f('0x53')]=function(_0x2c4f0d,_0x54f91e,_0x562155){var _0xa11a5e;return db[_0x061f('0x2d')][_0x061f('0x4b')]({'where':{'id':_0x2c4f0d[_0x061f('0x4a')]['id']},'attributes':['id',_0x061f('0x54')]})['then'](handleEntityNotFound(_0x54f91e,null))[_0x061f('0x23')](function(_0x4a2c62){if(_0x4a2c62){var _0x3bf309=require(_0x061f('0x55'))();_0x3bf309[_0x061f('0x56')](_0x4a2c62[_0x061f('0x54')]);_0x3bf309[_0x061f('0x57')]();return _0x4a2c62;}})[_0x061f('0x23')](respondWithResult(_0x54f91e,null))['catch'](handleError(_0x54f91e,null));};