Built motion from commit (unavailable).|2.5.6
[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 _0xcc4c=['crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','status','end','json','count','offset','set','Content-Range','reject','destroy','then','get','ODBC','UserProfileResource','error','stack','name','send','index','map','SquareOdbc','rawAttributes','type','key','query','filters','model','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','catch','keys','intersection','includeAll','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','params','test','odbc','openSync','dsn','closeSync','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xcc4c,0xa1));var _0xccc4=function(_0x3275ae,_0x5e7d28){_0x3275ae=_0x3275ae-0x0;var _0x434c35=_0xcc4c[_0x3275ae];return _0x434c35;};'use strict';var pdf=require(_0xccc4('0x0'));var emlformat=require(_0xccc4('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xccc4('0x2'));var jsonpatch=require(_0xccc4('0x3'));var rp=require(_0xccc4('0x4'));var moment=require('moment');var BPromise=require(_0xccc4('0x5'));var Mustache=require(_0xccc4('0x6'));var util=require(_0xccc4('0x7'));var path=require(_0xccc4('0x8'));var sox=require(_0xccc4('0x9'));var csv=require(_0xccc4('0xa'));var ejs=require(_0xccc4('0xb'));var fs=require('fs');var _=require(_0xccc4('0xc'));var squel=require('squel');var crypto=require(_0xccc4('0xd'));var jsforce=require(_0xccc4('0xe'));var deskjs=require(_0xccc4('0xf'));var toCsv=require(_0xccc4('0xa'));var querystring=require(_0xccc4('0x10'));var Papa=require(_0xccc4('0x11'));var Redis=require(_0xccc4('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xccc4('0x13'));var logger=require(_0xccc4('0x14'))(_0xccc4('0x15'));var utils=require(_0xccc4('0x16'));var config=require(_0xccc4('0x17'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x501757,_0xa4b629){_0xa4b629=_0xa4b629||0xcc;return function(_0x2a8f91){if(_0x2a8f91){return _0x501757['sendStatus'](_0xa4b629);}return _0x501757[_0xccc4('0x18')](_0xa4b629)[_0xccc4('0x19')]();};}function respondWithResult(_0x39fdab,_0x55c750){_0x55c750=_0x55c750||0xc8;return function(_0x26e8ad){if(_0x26e8ad){return _0x39fdab[_0xccc4('0x18')](_0x55c750)[_0xccc4('0x1a')](_0x26e8ad);}};}function respondWithFilteredResult(_0x3b3271,_0x472309){return function(_0x21fbf5){if(_0x21fbf5){var _0x1026da=_0x21fbf5[_0xccc4('0x1b')],_0x37a52b=_0x472309[_0xccc4('0x1c')],_0xe73cf8=_0x472309[_0xccc4('0x1c')]+_0x472309['limit'],_0x4d59bf;if(_0xe73cf8>=_0x1026da){_0xe73cf8=_0x1026da;_0x4d59bf=0xc8;}else{_0x4d59bf=0xce;}_0x3b3271['status'](_0x4d59bf);return _0x3b3271[_0xccc4('0x1d')](_0xccc4('0x1e'),_0x37a52b+'-'+_0xe73cf8+'/'+_0x1026da)[_0xccc4('0x1a')](_0x21fbf5);}return null;};}function patchUpdates(_0x301cd2){return function(_0x1e14fd){try{jsonpatch['apply'](_0x1e14fd,_0x301cd2,!![]);}catch(_0x13c444){return BPromise[_0xccc4('0x1f')](_0x13c444);}return _0x1e14fd['save']();};}function saveUpdates(_0x375d58,_0x5c311e){return function(_0x1794ac){if(_0x1794ac){return _0x1794ac['update'](_0x375d58)['then'](function(_0x253f9f){return _0x253f9f;});}return null;};}function removeEntity(_0x4d2241,_0x7dab29){return function(_0x3da0b8){if(_0x3da0b8){return _0x3da0b8[_0xccc4('0x20')]()[_0xccc4('0x21')](function(){var _0x516aaa=_0x3da0b8[_0xccc4('0x22')]({'plain':!![]});var _0xd5ebb9=_0xccc4('0x23');return db[_0xccc4('0x24')]['destroy']({'where':{'type':_0xd5ebb9,'resourceId':_0x516aaa['id']}})[_0xccc4('0x21')](function(){return _0x3da0b8;});})[_0xccc4('0x21')](function(){_0x4d2241[_0xccc4('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x26d024,_0x39a0f4){return function(_0x2fcef5){if(!_0x2fcef5){_0x26d024['sendStatus'](0x194);}return _0x2fcef5;};}function handleError(_0x96c0a6,_0x200a22){_0x200a22=_0x200a22||0x1f4;return function(_0x2dfead){logger[_0xccc4('0x25')](_0x2dfead[_0xccc4('0x26')]);if(_0x2dfead[_0xccc4('0x27')]){delete _0x2dfead[_0xccc4('0x27')];}_0x96c0a6[_0xccc4('0x18')](_0x200a22)[_0xccc4('0x28')](_0x2dfead);};}exports[_0xccc4('0x29')]=function(_0x5dbad6,_0x222b7c){var _0x37c86f={},_0x139295={},_0x1efe9a={'count':0x0,'rows':[]};var _0x166ee0=_[_0xccc4('0x2a')](db[_0xccc4('0x2b')][_0xccc4('0x2c')],function(_0x3f5f6c){return{'name':_0x3f5f6c['fieldName'],'type':_0x3f5f6c[_0xccc4('0x2d')][_0xccc4('0x2e')]};});_0x139295['model']=_[_0xccc4('0x2a')](_0x166ee0,_0xccc4('0x27'));_0x139295[_0xccc4('0x2f')]=_['keys'](_0x5dbad6[_0xccc4('0x2f')]);_0x139295[_0xccc4('0x30')]=_['intersection'](_0x139295[_0xccc4('0x31')],_0x139295['query']);_0x37c86f[_0xccc4('0x32')]=_['intersection'](_0x139295[_0xccc4('0x31')],qs[_0xccc4('0x33')](_0x5dbad6[_0xccc4('0x2f')][_0xccc4('0x33')]));_0x37c86f[_0xccc4('0x32')]=_0x37c86f[_0xccc4('0x32')][_0xccc4('0x34')]?_0x37c86f[_0xccc4('0x32')]:_0x139295['model'];if(!_0x5dbad6['query'][_0xccc4('0x35')](_0xccc4('0x36'))){_0x37c86f[_0xccc4('0x37')]=qs[_0xccc4('0x37')](_0x5dbad6[_0xccc4('0x2f')][_0xccc4('0x37')]);_0x37c86f[_0xccc4('0x1c')]=qs[_0xccc4('0x1c')](_0x5dbad6[_0xccc4('0x2f')][_0xccc4('0x1c')]);}_0x37c86f[_0xccc4('0x38')]=qs[_0xccc4('0x39')](_0x5dbad6[_0xccc4('0x2f')]['sort']);_0x37c86f[_0xccc4('0x3a')]=qs[_0xccc4('0x30')](_[_0xccc4('0x3b')](_0x5dbad6['query'],_0x139295[_0xccc4('0x30')]),_0x166ee0);if(_0x5dbad6[_0xccc4('0x2f')][_0xccc4('0x3c')]){_0x37c86f[_0xccc4('0x3a')]=_[_0xccc4('0x3d')](_0x37c86f[_0xccc4('0x3a')],{'$or':_['map'](_0x166ee0,function(_0x5c33fe){if(_0x5c33fe[_0xccc4('0x2d')]!==_0xccc4('0x3e')){var _0x3e4425={};_0x3e4425[_0x5c33fe['name']]={'$like':'%'+_0x5dbad6[_0xccc4('0x2f')][_0xccc4('0x3c')]+'%'};return _0x3e4425;}})});}_0x37c86f=_['merge']({},_0x37c86f,_0x5dbad6[_0xccc4('0x3f')]);var _0x5c516d={'where':_0x37c86f['where']};return db[_0xccc4('0x2b')][_0xccc4('0x1b')](_0x5c516d)['then'](function(_0x39c4c6){_0x1efe9a['count']=_0x39c4c6;if(_0x5dbad6[_0xccc4('0x2f')]['includeAll']){_0x37c86f[_0xccc4('0x40')]=[{'all':!![]}];}return db[_0xccc4('0x2b')][_0xccc4('0x41')](_0x37c86f);})[_0xccc4('0x21')](function(_0xbb6447){_0x1efe9a['rows']=_0xbb6447;return _0x1efe9a;})['then'](respondWithFilteredResult(_0x222b7c,_0x37c86f))[_0xccc4('0x42')](handleError(_0x222b7c,null));};exports['show']=function(_0x292a84,_0x1664f7){var _0x146076={'raw':!![],'where':{'id':_0x292a84['params']['id']}},_0x56d904={};_0x56d904[_0xccc4('0x31')]=_[_0xccc4('0x43')](db[_0xccc4('0x2b')][_0xccc4('0x2c')]);_0x56d904[_0xccc4('0x2f')]=_[_0xccc4('0x43')](_0x292a84[_0xccc4('0x2f')]);_0x56d904[_0xccc4('0x30')]=_[_0xccc4('0x44')](_0x56d904['model'],_0x56d904[_0xccc4('0x2f')]);_0x146076['attributes']=_[_0xccc4('0x44')](_0x56d904[_0xccc4('0x31')],qs[_0xccc4('0x33')](_0x292a84['query'][_0xccc4('0x33')]));_0x146076[_0xccc4('0x32')]=_0x146076['attributes'][_0xccc4('0x34')]?_0x146076[_0xccc4('0x32')]:_0x56d904[_0xccc4('0x31')];if(_0x292a84[_0xccc4('0x2f')][_0xccc4('0x45')]){_0x146076['include']=[{'all':!![]}];}_0x146076=_[_0xccc4('0x3d')]({},_0x146076,_0x292a84[_0xccc4('0x3f')]);return db['SquareOdbc'][_0xccc4('0x46')](_0x146076)[_0xccc4('0x21')](handleEntityNotFound(_0x1664f7,null))[_0xccc4('0x21')](respondWithResult(_0x1664f7,null))[_0xccc4('0x42')](handleError(_0x1664f7,null));};exports[_0xccc4('0x47')]=function(_0x57fa53,_0x4d8251){return db[_0xccc4('0x2b')][_0xccc4('0x47')](_0x57fa53[_0xccc4('0x48')],{})[_0xccc4('0x21')](function(_0x2355e2){var _0x22c619=_0x57fa53[_0xccc4('0x49')][_0xccc4('0x22')]({'plain':!![]});if(!_0x22c619)throw new Error(_0xccc4('0x4a'));if(_0x22c619[_0xccc4('0x4b')]===_0xccc4('0x49')){var _0x2b2401=_0x2355e2[_0xccc4('0x22')]({'plain':!![]});var _0x42352d=_0xccc4('0x23');return db[_0xccc4('0x4c')]['find']({'where':{'name':_0x42352d,'userProfileId':_0x22c619[_0xccc4('0x4d')]},'raw':!![]})['then'](function(_0x2614d7){if(_0x2614d7&&_0x2614d7[_0xccc4('0x4e')]===0x0){return db[_0xccc4('0x24')]['create']({'name':_0x2b2401[_0xccc4('0x27')],'resourceId':_0x2b2401['id'],'type':_0x2614d7[_0xccc4('0x27')],'sectionId':_0x2614d7['id']},{})['then'](function(){return _0x2355e2;});}else{return _0x2355e2;}})['catch'](function(_0x3faf87){logger[_0xccc4('0x25')](_0xccc4('0x4f'),_0x3faf87);throw _0x3faf87;});}return _0x2355e2;})[_0xccc4('0x21')](respondWithResult(_0x4d8251,0xc9))[_0xccc4('0x42')](handleError(_0x4d8251,null));};exports[_0xccc4('0x50')]=function(_0x53a08b,_0x11d901){if(_0x53a08b[_0xccc4('0x48')]['id']){delete _0x53a08b[_0xccc4('0x48')]['id'];}return db[_0xccc4('0x2b')]['find']({'where':{'id':_0x53a08b[_0xccc4('0x51')]['id']}})[_0xccc4('0x21')](handleEntityNotFound(_0x11d901,null))[_0xccc4('0x21')](saveUpdates(_0x53a08b[_0xccc4('0x48')],null))[_0xccc4('0x21')](respondWithResult(_0x11d901,null))[_0xccc4('0x42')](handleError(_0x11d901,null));};exports['destroy']=function(_0x552513,_0x7ec51a){return db[_0xccc4('0x2b')][_0xccc4('0x46')]({'where':{'id':_0x552513[_0xccc4('0x51')]['id']}})[_0xccc4('0x21')](handleEntityNotFound(_0x7ec51a,null))[_0xccc4('0x21')](removeEntity(_0x7ec51a,null))['catch'](handleError(_0x7ec51a,null));};exports[_0xccc4('0x52')]=function(_0x2ec80c,_0x4ef2a0,_0x4d0960){var _0x25a7a9;return db['SquareOdbc'][_0xccc4('0x46')]({'where':{'id':_0x2ec80c[_0xccc4('0x51')]['id']},'attributes':['id','dsn']})[_0xccc4('0x21')](handleEntityNotFound(_0x4ef2a0,null))[_0xccc4('0x21')](function(_0x6c7a86){if(_0x6c7a86){var _0x38a2ed=require(_0xccc4('0x53'))();_0x38a2ed[_0xccc4('0x54')](_0x6c7a86[_0xccc4('0x55')]);_0x38a2ed[_0xccc4('0x56')]();return _0x6c7a86;}})[_0xccc4('0x21')](respondWithResult(_0x4ef2a0,null))[_0xccc4('0x42')](handleError(_0x4ef2a0,null));};