Built motion from commit 06eb8eb0.|2.6.31
[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 _0x1c2f=['sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','reject','save','update','then','get','ODBC','UserProfileResource','error','stack','send','index','map','SquareOdbc','rawAttributes','type','model','query','keys','filters','attributes','intersection','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','name','options','includeAll','include','findAll','catch','show','params','find','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','destroy','test','dsn','odbc','closeSync','eml-format','rimraf','fast-json-patch','request-promise','moment','util','path','to-csv','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb'];(function(_0x475767,_0x2ed5da){var _0x4f192e=function(_0x1e6e24){while(--_0x1e6e24){_0x475767['push'](_0x475767['shift']());}};_0x4f192e(++_0x2ed5da);}(_0x1c2f,0x1e3));var _0xf1c2=function(_0x19ee96,_0x48b7d5){_0x19ee96=_0x19ee96-0x0;var _0x57aaf0=_0x1c2f[_0x19ee96];return _0x57aaf0;};'use strict';var emlformat=require(_0xf1c2('0x0'));var rimraf=require(_0xf1c2('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf1c2('0x2'));var rp=require(_0xf1c2('0x3'));var moment=require(_0xf1c2('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf1c2('0x5'));var path=require(_0xf1c2('0x6'));var sox=require('sox');var csv=require(_0xf1c2('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf1c2('0x8'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xf1c2('0x9'));var deskjs=require(_0xf1c2('0xa'));var toCsv=require(_0xf1c2('0x7'));var querystring=require(_0xf1c2('0xb'));var Papa=require(_0xf1c2('0xc'));var Redis=require(_0xf1c2('0xd'));var authService=require(_0xf1c2('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0xf1c2('0xf'));var hardwareService=require(_0xf1c2('0x10'));var logger=require('../../config/logger')(_0xf1c2('0x11'));var utils=require(_0xf1c2('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0xf1c2('0x13'));var db=require(_0xf1c2('0x14'))['db'];function respondWithStatusCode(_0x346dac,_0xcceb1){_0xcceb1=_0xcceb1||0xcc;return function(_0x4c8a24){if(_0x4c8a24){return _0x346dac[_0xf1c2('0x15')](_0xcceb1);}return _0x346dac[_0xf1c2('0x16')](_0xcceb1)[_0xf1c2('0x17')]();};}function respondWithResult(_0x35433e,_0x53b941){_0x53b941=_0x53b941||0xc8;return function(_0x3438d0){if(_0x3438d0){return _0x35433e[_0xf1c2('0x16')](_0x53b941)[_0xf1c2('0x18')](_0x3438d0);}};}function respondWithFilteredResult(_0x519d41,_0x55426c){return function(_0x3d4706){if(_0x3d4706){var _0x227ba0=typeof _0x55426c[_0xf1c2('0x19')]===_0xf1c2('0x1a')&&typeof _0x55426c['limit']===_0xf1c2('0x1a');var _0x15a3bd=_0x3d4706['count'];var _0xc44629=_0x227ba0?0x0:_0x55426c['offset'];var _0x4542fe=_0x227ba0?_0x3d4706[_0xf1c2('0x1b')]:_0x55426c[_0xf1c2('0x19')]+_0x55426c[_0xf1c2('0x1c')];var _0x1e2484;if(_0x4542fe>=_0x15a3bd){_0x4542fe=_0x15a3bd;_0x1e2484=0xc8;}else{_0x1e2484=0xce;}_0x519d41[_0xf1c2('0x16')](_0x1e2484);return _0x519d41[_0xf1c2('0x1d')](_0xf1c2('0x1e'),_0xc44629+'-'+_0x4542fe+'/'+_0x15a3bd)[_0xf1c2('0x18')](_0x3d4706);}return null;};}function patchUpdates(_0x47530e){return function(_0x3d5cbe){try{jsonpatch['apply'](_0x3d5cbe,_0x47530e,!![]);}catch(_0x6f58d2){return BPromise[_0xf1c2('0x1f')](_0x6f58d2);}return _0x3d5cbe[_0xf1c2('0x20')]();};}function saveUpdates(_0x1beae3,_0x37dafa){return function(_0x2b2b95){if(_0x2b2b95){return _0x2b2b95[_0xf1c2('0x21')](_0x1beae3)[_0xf1c2('0x22')](function(_0x3b3222){return _0x3b3222;});}return null;};}function removeEntity(_0x4ba87a,_0x20fdea){return function(_0x25f03a){if(_0x25f03a){return _0x25f03a['destroy']()[_0xf1c2('0x22')](function(){var _0x5c0136=_0x25f03a[_0xf1c2('0x23')]({'plain':!![]});var _0x2a79eb=_0xf1c2('0x24');return db[_0xf1c2('0x25')]['destroy']({'where':{'type':_0x2a79eb,'resourceId':_0x5c0136['id']}})[_0xf1c2('0x22')](function(){return _0x25f03a;});})[_0xf1c2('0x22')](function(){_0x4ba87a[_0xf1c2('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5999b2,_0x202631){return function(_0x277df7){if(!_0x277df7){_0x5999b2['sendStatus'](0x194);}return _0x277df7;};}function handleError(_0x333808,_0x493cc0){_0x493cc0=_0x493cc0||0x1f4;return function(_0x4d7309){logger[_0xf1c2('0x26')](_0x4d7309[_0xf1c2('0x27')]);if(_0x4d7309['name']){delete _0x4d7309['name'];}_0x333808['status'](_0x493cc0)[_0xf1c2('0x28')](_0x4d7309);};}exports[_0xf1c2('0x29')]=function(_0x365a61,_0x2f86a3){var _0x73941d={},_0x13429d={},_0x157b25={'count':0x0,'rows':[]};var _0x1db2d5=_[_0xf1c2('0x2a')](db[_0xf1c2('0x2b')][_0xf1c2('0x2c')],function(_0x3c339e){return{'name':_0x3c339e['fieldName'],'type':_0x3c339e[_0xf1c2('0x2d')]['key']};});_0x13429d[_0xf1c2('0x2e')]=_[_0xf1c2('0x2a')](_0x1db2d5,'name');_0x13429d[_0xf1c2('0x2f')]=_[_0xf1c2('0x30')](_0x365a61[_0xf1c2('0x2f')]);_0x13429d[_0xf1c2('0x31')]=_['intersection'](_0x13429d[_0xf1c2('0x2e')],_0x13429d[_0xf1c2('0x2f')]);_0x73941d[_0xf1c2('0x32')]=_[_0xf1c2('0x33')](_0x13429d[_0xf1c2('0x2e')],qs[_0xf1c2('0x34')](_0x365a61['query'][_0xf1c2('0x34')]));_0x73941d['attributes']=_0x73941d['attributes'][_0xf1c2('0x35')]?_0x73941d[_0xf1c2('0x32')]:_0x13429d[_0xf1c2('0x2e')];if(!_0x365a61[_0xf1c2('0x2f')]['hasOwnProperty'](_0xf1c2('0x36'))){_0x73941d[_0xf1c2('0x1c')]=qs[_0xf1c2('0x1c')](_0x365a61['query'][_0xf1c2('0x1c')]);_0x73941d[_0xf1c2('0x19')]=qs['offset'](_0x365a61[_0xf1c2('0x2f')]['offset']);}_0x73941d[_0xf1c2('0x37')]=qs['sort'](_0x365a61[_0xf1c2('0x2f')][_0xf1c2('0x38')]);_0x73941d[_0xf1c2('0x39')]=qs[_0xf1c2('0x31')](_[_0xf1c2('0x3a')](_0x365a61[_0xf1c2('0x2f')],_0x13429d[_0xf1c2('0x31')]),_0x1db2d5);if(_0x365a61[_0xf1c2('0x2f')][_0xf1c2('0x3b')]){_0x73941d[_0xf1c2('0x39')]=_[_0xf1c2('0x3c')](_0x73941d[_0xf1c2('0x39')],{'$or':_[_0xf1c2('0x2a')](_0x1db2d5,function(_0x5c7d07){if(_0x5c7d07[_0xf1c2('0x2d')]!==_0xf1c2('0x3d')){var _0x2f2a15={};_0x2f2a15[_0x5c7d07[_0xf1c2('0x3e')]]={'$like':'%'+_0x365a61[_0xf1c2('0x2f')]['filter']+'%'};return _0x2f2a15;}})});}_0x73941d=_['merge']({},_0x73941d,_0x365a61[_0xf1c2('0x3f')]);var _0x2e12bb={'where':_0x73941d[_0xf1c2('0x39')]};return db[_0xf1c2('0x2b')][_0xf1c2('0x1b')](_0x2e12bb)[_0xf1c2('0x22')](function(_0x211ff8){_0x157b25[_0xf1c2('0x1b')]=_0x211ff8;if(_0x365a61[_0xf1c2('0x2f')][_0xf1c2('0x40')]){_0x73941d[_0xf1c2('0x41')]=[{'all':!![]}];}return db[_0xf1c2('0x2b')][_0xf1c2('0x42')](_0x73941d);})[_0xf1c2('0x22')](function(_0x4d3d1c){_0x157b25['rows']=_0x4d3d1c;return _0x157b25;})[_0xf1c2('0x22')](respondWithFilteredResult(_0x2f86a3,_0x73941d))[_0xf1c2('0x43')](handleError(_0x2f86a3,null));};exports[_0xf1c2('0x44')]=function(_0x336db7,_0x45c7a5){var _0x1429be={'raw':!![],'where':{'id':_0x336db7[_0xf1c2('0x45')]['id']}},_0x1d949e={};_0x1d949e[_0xf1c2('0x2e')]=_[_0xf1c2('0x30')](db[_0xf1c2('0x2b')][_0xf1c2('0x2c')]);_0x1d949e['query']=_[_0xf1c2('0x30')](_0x336db7[_0xf1c2('0x2f')]);_0x1d949e['filters']=_[_0xf1c2('0x33')](_0x1d949e['model'],_0x1d949e[_0xf1c2('0x2f')]);_0x1429be[_0xf1c2('0x32')]=_[_0xf1c2('0x33')](_0x1d949e[_0xf1c2('0x2e')],qs[_0xf1c2('0x34')](_0x336db7[_0xf1c2('0x2f')]['fields']));_0x1429be['attributes']=_0x1429be[_0xf1c2('0x32')][_0xf1c2('0x35')]?_0x1429be['attributes']:_0x1d949e['model'];if(_0x336db7[_0xf1c2('0x2f')]['includeAll']){_0x1429be[_0xf1c2('0x41')]=[{'all':!![]}];}_0x1429be=_['merge']({},_0x1429be,_0x336db7[_0xf1c2('0x3f')]);return db['SquareOdbc'][_0xf1c2('0x46')](_0x1429be)[_0xf1c2('0x22')](handleEntityNotFound(_0x45c7a5,null))[_0xf1c2('0x22')](respondWithResult(_0x45c7a5,null))[_0xf1c2('0x43')](handleError(_0x45c7a5,null));};exports[_0xf1c2('0x47')]=function(_0x1b3547,_0x5af434){return db['SquareOdbc'][_0xf1c2('0x47')](_0x1b3547['body'],{})[_0xf1c2('0x22')](function(_0x4b864b){var _0x248a0e=_0x1b3547['user'][_0xf1c2('0x23')]({'plain':!![]});if(!_0x248a0e)throw new Error(_0xf1c2('0x48'));if(_0x248a0e[_0xf1c2('0x49')]===_0xf1c2('0x4a')){var _0x2d4370=_0x4b864b[_0xf1c2('0x23')]({'plain':!![]});var _0x367a43=_0xf1c2('0x24');return db[_0xf1c2('0x4b')]['find']({'where':{'name':_0x367a43,'userProfileId':_0x248a0e[_0xf1c2('0x4c')]},'raw':!![]})[_0xf1c2('0x22')](function(_0x4d61a0){if(_0x4d61a0&&_0x4d61a0['autoAssociation']===0x0){return db[_0xf1c2('0x25')][_0xf1c2('0x47')]({'name':_0x2d4370['name'],'resourceId':_0x2d4370['id'],'type':_0x4d61a0[_0xf1c2('0x3e')],'sectionId':_0x4d61a0['id']},{})['then'](function(){return _0x4b864b;});}else{return _0x4b864b;}})[_0xf1c2('0x43')](function(_0x236bac){logger['error'](_0xf1c2('0x4d'),_0x236bac);throw _0x236bac;});}return _0x4b864b;})['then'](respondWithResult(_0x5af434,0xc9))['catch'](handleError(_0x5af434,null));};exports[_0xf1c2('0x21')]=function(_0x1890cc,_0x104819){if(_0x1890cc[_0xf1c2('0x4e')]['id']){delete _0x1890cc[_0xf1c2('0x4e')]['id'];}return db['SquareOdbc']['find']({'where':{'id':_0x1890cc[_0xf1c2('0x45')]['id']}})['then'](handleEntityNotFound(_0x104819,null))[_0xf1c2('0x22')](saveUpdates(_0x1890cc['body'],null))[_0xf1c2('0x22')](respondWithResult(_0x104819,null))['catch'](handleError(_0x104819,null));};exports[_0xf1c2('0x4f')]=function(_0x506a01,_0x30ccfb){return db[_0xf1c2('0x2b')]['find']({'where':{'id':_0x506a01[_0xf1c2('0x45')]['id']}})['then'](handleEntityNotFound(_0x30ccfb,null))[_0xf1c2('0x22')](removeEntity(_0x30ccfb,null))[_0xf1c2('0x43')](handleError(_0x30ccfb,null));};exports[_0xf1c2('0x50')]=function(_0x386b5f,_0x12c302,_0x5e5f8b){var _0x2378f9;return db[_0xf1c2('0x2b')][_0xf1c2('0x46')]({'where':{'id':_0x386b5f[_0xf1c2('0x45')]['id']},'attributes':['id',_0xf1c2('0x51')]})['then'](handleEntityNotFound(_0x12c302,null))[_0xf1c2('0x22')](function(_0x439b17){if(_0x439b17){var _0x1621ce=require(_0xf1c2('0x52'))();_0x1621ce['openSync'](_0x439b17[_0xf1c2('0x51')]);_0x1621ce[_0xf1c2('0x53')]();return _0x439b17;}})[_0xf1c2('0x22')](respondWithResult(_0x12c302,null))[_0xf1c2('0x43')](handleError(_0x12c302,null));};