Built motion from commit (unavailable).|2.5.17
[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 _0xea7d=['filters','pick','merge','filter','options','SquareOdbc','includeAll','include','rows','catch','show','params','find','create','body','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','test','dsn','openSync','closeSync','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','ODBC','UserProfileResource','error','stack','name','send','map','rawAttributes','fieldName','type','key','model','keys','query','intersection','fields','attributes','length','hasOwnProperty','order','sort','where'];(function(_0xe2d820,_0x5d7329){var _0x3698b3=function(_0x2858bb){while(--_0x2858bb){_0xe2d820['push'](_0xe2d820['shift']());}};_0x3698b3(++_0x5d7329);}(_0xea7d,0x12b));var _0xdea7=function(_0x237da8,_0x37b77a){_0x237da8=_0x237da8-0x0;var _0x558825=_0xea7d[_0x237da8];return _0x558825;};'use strict';var pdf=require(_0xdea7('0x0'));var emlformat=require(_0xdea7('0x1'));var rimraf=require(_0xdea7('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xdea7('0x3'));var moment=require(_0xdea7('0x4'));var BPromise=require(_0xdea7('0x5'));var Mustache=require(_0xdea7('0x6'));var util=require(_0xdea7('0x7'));var path=require(_0xdea7('0x8'));var sox=require('sox');var csv=require(_0xdea7('0x9'));var ejs=require(_0xdea7('0xa'));var fs=require('fs');var _=require(_0xdea7('0xb'));var squel=require(_0xdea7('0xc'));var crypto=require(_0xdea7('0xd'));var jsforce=require(_0xdea7('0xe'));var deskjs=require(_0xdea7('0xf'));var toCsv=require(_0xdea7('0x9'));var querystring=require(_0xdea7('0x10'));var Papa=require(_0xdea7('0x11'));var Redis=require(_0xdea7('0x12'));var authService=require(_0xdea7('0x13'));var qs=require(_0xdea7('0x14'));var as=require(_0xdea7('0x15'));var hardwareService=require(_0xdea7('0x16'));var logger=require(_0xdea7('0x17'))(_0xdea7('0x18'));var utils=require(_0xdea7('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0xdea7('0x1a'));var db=require(_0xdea7('0x1b'))['db'];function respondWithStatusCode(_0xf14ed9,_0x376813){_0x376813=_0x376813||0xcc;return function(_0x3bae0c){if(_0x3bae0c){return _0xf14ed9[_0xdea7('0x1c')](_0x376813);}return _0xf14ed9['status'](_0x376813)[_0xdea7('0x1d')]();};}function respondWithResult(_0x11a7d8,_0x33df80){_0x33df80=_0x33df80||0xc8;return function(_0x29fe97){if(_0x29fe97){return _0x11a7d8[_0xdea7('0x1e')](_0x33df80)[_0xdea7('0x1f')](_0x29fe97);}};}function respondWithFilteredResult(_0xc31f44,_0x2eb052){return function(_0x58b86d){if(_0x58b86d){var _0x3c2548=_0x58b86d[_0xdea7('0x20')],_0xc4004d=_0x2eb052[_0xdea7('0x21')],_0x580fc1=_0x2eb052[_0xdea7('0x21')]+_0x2eb052[_0xdea7('0x22')],_0x53384f;if(_0x580fc1>=_0x3c2548){_0x580fc1=_0x3c2548;_0x53384f=0xc8;}else{_0x53384f=0xce;}_0xc31f44[_0xdea7('0x1e')](_0x53384f);return _0xc31f44[_0xdea7('0x23')](_0xdea7('0x24'),_0xc4004d+'-'+_0x580fc1+'/'+_0x3c2548)['json'](_0x58b86d);}return null;};}function patchUpdates(_0x287fa5){return function(_0x1aa5e0){try{jsonpatch[_0xdea7('0x25')](_0x1aa5e0,_0x287fa5,!![]);}catch(_0x4d0e2d){return BPromise[_0xdea7('0x26')](_0x4d0e2d);}return _0x1aa5e0[_0xdea7('0x27')]();};}function saveUpdates(_0xd4579c,_0x5cce63){return function(_0x4385fd){if(_0x4385fd){return _0x4385fd[_0xdea7('0x28')](_0xd4579c)[_0xdea7('0x29')](function(_0x2fec39){return _0x2fec39;});}return null;};}function removeEntity(_0x19e73f,_0x5492ce){return function(_0x1104ec){if(_0x1104ec){return _0x1104ec[_0xdea7('0x2a')]()['then'](function(){var _0x6842be=_0x1104ec['get']({'plain':!![]});var _0x5e2cbb=_0xdea7('0x2b');return db[_0xdea7('0x2c')]['destroy']({'where':{'type':_0x5e2cbb,'resourceId':_0x6842be['id']}})['then'](function(){return _0x1104ec;});})[_0xdea7('0x29')](function(){_0x19e73f[_0xdea7('0x1e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x35da61,_0x5b61e1){return function(_0x8572d3){if(!_0x8572d3){_0x35da61['sendStatus'](0x194);}return _0x8572d3;};}function handleError(_0x1c1c35,_0x5e18af){_0x5e18af=_0x5e18af||0x1f4;return function(_0x577a17){logger[_0xdea7('0x2d')](_0x577a17[_0xdea7('0x2e')]);if(_0x577a17[_0xdea7('0x2f')]){delete _0x577a17[_0xdea7('0x2f')];}_0x1c1c35[_0xdea7('0x1e')](_0x5e18af)[_0xdea7('0x30')](_0x577a17);};}exports['index']=function(_0x282b9a,_0x3eb9bc){var _0x3e966b={},_0xb1b0d5={},_0x2ff79f={'count':0x0,'rows':[]};var _0x252c7b=_[_0xdea7('0x31')](db['SquareOdbc'][_0xdea7('0x32')],function(_0x1ce2fa){return{'name':_0x1ce2fa[_0xdea7('0x33')],'type':_0x1ce2fa[_0xdea7('0x34')][_0xdea7('0x35')]};});_0xb1b0d5[_0xdea7('0x36')]=_['map'](_0x252c7b,_0xdea7('0x2f'));_0xb1b0d5['query']=_[_0xdea7('0x37')](_0x282b9a[_0xdea7('0x38')]);_0xb1b0d5['filters']=_[_0xdea7('0x39')](_0xb1b0d5[_0xdea7('0x36')],_0xb1b0d5[_0xdea7('0x38')]);_0x3e966b['attributes']=_[_0xdea7('0x39')](_0xb1b0d5['model'],qs[_0xdea7('0x3a')](_0x282b9a[_0xdea7('0x38')][_0xdea7('0x3a')]));_0x3e966b[_0xdea7('0x3b')]=_0x3e966b[_0xdea7('0x3b')][_0xdea7('0x3c')]?_0x3e966b['attributes']:_0xb1b0d5[_0xdea7('0x36')];if(!_0x282b9a[_0xdea7('0x38')][_0xdea7('0x3d')]('nolimit')){_0x3e966b[_0xdea7('0x22')]=qs['limit'](_0x282b9a[_0xdea7('0x38')][_0xdea7('0x22')]);_0x3e966b[_0xdea7('0x21')]=qs[_0xdea7('0x21')](_0x282b9a['query'][_0xdea7('0x21')]);}_0x3e966b[_0xdea7('0x3e')]=qs[_0xdea7('0x3f')](_0x282b9a['query'][_0xdea7('0x3f')]);_0x3e966b[_0xdea7('0x40')]=qs[_0xdea7('0x41')](_[_0xdea7('0x42')](_0x282b9a['query'],_0xb1b0d5[_0xdea7('0x41')]),_0x252c7b);if(_0x282b9a['query']['filter']){_0x3e966b[_0xdea7('0x40')]=_[_0xdea7('0x43')](_0x3e966b['where'],{'$or':_['map'](_0x252c7b,function(_0xe372ce){if(_0xe372ce['type']!=='VIRTUAL'){var _0x3a8549={};_0x3a8549[_0xe372ce[_0xdea7('0x2f')]]={'$like':'%'+_0x282b9a[_0xdea7('0x38')][_0xdea7('0x44')]+'%'};return _0x3a8549;}})});}_0x3e966b=_[_0xdea7('0x43')]({},_0x3e966b,_0x282b9a[_0xdea7('0x45')]);var _0x266064={'where':_0x3e966b['where']};return db[_0xdea7('0x46')]['count'](_0x266064)['then'](function(_0xd1d2fe){_0x2ff79f[_0xdea7('0x20')]=_0xd1d2fe;if(_0x282b9a[_0xdea7('0x38')][_0xdea7('0x47')]){_0x3e966b[_0xdea7('0x48')]=[{'all':!![]}];}return db[_0xdea7('0x46')]['findAll'](_0x3e966b);})['then'](function(_0x40854c){_0x2ff79f[_0xdea7('0x49')]=_0x40854c;return _0x2ff79f;})['then'](respondWithFilteredResult(_0x3eb9bc,_0x3e966b))[_0xdea7('0x4a')](handleError(_0x3eb9bc,null));};exports[_0xdea7('0x4b')]=function(_0x34d891,_0x793dee){var _0x6181bc={'raw':!![],'where':{'id':_0x34d891[_0xdea7('0x4c')]['id']}},_0x55b38e={};_0x55b38e[_0xdea7('0x36')]=_[_0xdea7('0x37')](db['SquareOdbc'][_0xdea7('0x32')]);_0x55b38e[_0xdea7('0x38')]=_['keys'](_0x34d891[_0xdea7('0x38')]);_0x55b38e[_0xdea7('0x41')]=_[_0xdea7('0x39')](_0x55b38e[_0xdea7('0x36')],_0x55b38e['query']);_0x6181bc[_0xdea7('0x3b')]=_['intersection'](_0x55b38e[_0xdea7('0x36')],qs[_0xdea7('0x3a')](_0x34d891['query']['fields']));_0x6181bc['attributes']=_0x6181bc[_0xdea7('0x3b')][_0xdea7('0x3c')]?_0x6181bc['attributes']:_0x55b38e[_0xdea7('0x36')];if(_0x34d891[_0xdea7('0x38')]['includeAll']){_0x6181bc['include']=[{'all':!![]}];}_0x6181bc=_[_0xdea7('0x43')]({},_0x6181bc,_0x34d891[_0xdea7('0x45')]);return db['SquareOdbc'][_0xdea7('0x4d')](_0x6181bc)[_0xdea7('0x29')](handleEntityNotFound(_0x793dee,null))[_0xdea7('0x29')](respondWithResult(_0x793dee,null))[_0xdea7('0x4a')](handleError(_0x793dee,null));};exports[_0xdea7('0x4e')]=function(_0x1d3a91,_0x129129){return db[_0xdea7('0x46')][_0xdea7('0x4e')](_0x1d3a91[_0xdea7('0x4f')],{})[_0xdea7('0x29')](function(_0x29b077){var _0x18747f=_0x1d3a91['user'][_0xdea7('0x50')]({'plain':!![]});if(!_0x18747f)throw new Error(_0xdea7('0x51'));if(_0x18747f[_0xdea7('0x52')]===_0xdea7('0x53')){var _0x4e57d0=_0x29b077[_0xdea7('0x50')]({'plain':!![]});var _0x23ec4d=_0xdea7('0x2b');return db['UserProfileSection'][_0xdea7('0x4d')]({'where':{'name':_0x23ec4d,'userProfileId':_0x18747f[_0xdea7('0x54')]},'raw':!![]})[_0xdea7('0x29')](function(_0x47147f){if(_0x47147f&&_0x47147f[_0xdea7('0x55')]===0x0){return db[_0xdea7('0x2c')][_0xdea7('0x4e')]({'name':_0x4e57d0['name'],'resourceId':_0x4e57d0['id'],'type':_0x47147f['name'],'sectionId':_0x47147f['id']},{})[_0xdea7('0x29')](function(){return _0x29b077;});}else{return _0x29b077;}})[_0xdea7('0x4a')](function(_0x119194){logger['error'](_0xdea7('0x56'),_0x119194);throw _0x119194;});}return _0x29b077;})[_0xdea7('0x29')](respondWithResult(_0x129129,0xc9))[_0xdea7('0x4a')](handleError(_0x129129,null));};exports[_0xdea7('0x28')]=function(_0x275dfc,_0xe9ea1e){if(_0x275dfc[_0xdea7('0x4f')]['id']){delete _0x275dfc['body']['id'];}return db[_0xdea7('0x46')][_0xdea7('0x4d')]({'where':{'id':_0x275dfc[_0xdea7('0x4c')]['id']}})[_0xdea7('0x29')](handleEntityNotFound(_0xe9ea1e,null))[_0xdea7('0x29')](saveUpdates(_0x275dfc['body'],null))['then'](respondWithResult(_0xe9ea1e,null))[_0xdea7('0x4a')](handleError(_0xe9ea1e,null));};exports[_0xdea7('0x2a')]=function(_0x6f59cd,_0x243c70){return db[_0xdea7('0x46')][_0xdea7('0x4d')]({'where':{'id':_0x6f59cd[_0xdea7('0x4c')]['id']}})[_0xdea7('0x29')](handleEntityNotFound(_0x243c70,null))['then'](removeEntity(_0x243c70,null))[_0xdea7('0x4a')](handleError(_0x243c70,null));};exports[_0xdea7('0x57')]=function(_0x4ae2be,_0x3d4486,_0x23dd8c){var _0x11d036;return db[_0xdea7('0x46')][_0xdea7('0x4d')]({'where':{'id':_0x4ae2be[_0xdea7('0x4c')]['id']},'attributes':['id',_0xdea7('0x58')]})['then'](handleEntityNotFound(_0x3d4486,null))[_0xdea7('0x29')](function(_0x8331d3){if(_0x8331d3){var _0x3b5999=require('odbc')();_0x3b5999[_0xdea7('0x59')](_0x8331d3[_0xdea7('0x58')]);_0x3b5999[_0xdea7('0x5a')]();return _0x8331d3;}})[_0xdea7('0x29')](respondWithResult(_0x3d4486,null))['catch'](handleError(_0x3d4486,null));};