Built motion from commit f623a78c.|2.6.31
[motion2.git] / server / api / intDynamics365Configuration / intDynamics365Configuration.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 _0xcebf=['papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','offset','undefined','count','set','apply','reject','save','update','then','destroy','error','stack','send','index','map','rawAttributes','fieldName','type','name','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','limit','order','sort','pick','filter','where','merge','VIRTUAL','options','Dynamics365Configuration','includeAll','include','findAll','rows','catch','find','create','body','params','getFields','Dynamics365Field','nolimit','getSubjects','getDescriptions','findOne','eml-format','zip-dir','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js'];(function(_0x50c11b,_0x848d6f){var _0x46d2d0=function(_0x18061c){while(--_0x18061c){_0x50c11b['push'](_0x50c11b['shift']());}};_0x46d2d0(++_0x848d6f);}(_0xcebf,0x1d2));var _0xfceb=function(_0x1cfcbe,_0x52b5c9){_0x1cfcbe=_0x1cfcbe-0x0;var _0x20dd79=_0xcebf[_0x1cfcbe];return _0x20dd79;};'use strict';var emlformat=require(_0xfceb('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xfceb('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xfceb('0x2'));var Mustache=require(_0xfceb('0x3'));var util=require(_0xfceb('0x4'));var path=require(_0xfceb('0x5'));var sox=require(_0xfceb('0x6'));var csv=require(_0xfceb('0x7'));var ejs=require(_0xfceb('0x8'));var fs=require('fs');var fs_extra=require(_0xfceb('0x9'));var _=require(_0xfceb('0xa'));var squel=require('squel');var crypto=require(_0xfceb('0xb'));var jsforce=require(_0xfceb('0xc'));var deskjs=require(_0xfceb('0xd'));var toCsv=require(_0xfceb('0x7'));var querystring=require('querystring');var Papa=require(_0xfceb('0xe'));var Redis=require(_0xfceb('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xfceb('0x10'));var as=require(_0xfceb('0x11'));var hardwareService=require(_0xfceb('0x12'));var logger=require('../../config/logger')(_0xfceb('0x13'));var utils=require(_0xfceb('0x14'));var config=require(_0xfceb('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0xfceb('0x16'))['db'];function respondWithStatusCode(_0x52ab6c,_0x53cce3){_0x53cce3=_0x53cce3||0xcc;return function(_0x1e1270){if(_0x1e1270){return _0x52ab6c[_0xfceb('0x17')](_0x53cce3);}return _0x52ab6c['status'](_0x53cce3)[_0xfceb('0x18')]();};}function respondWithResult(_0x3ae06b,_0x29add5){_0x29add5=_0x29add5||0xc8;return function(_0x3f57d7){if(_0x3f57d7){return _0x3ae06b[_0xfceb('0x19')](_0x29add5)[_0xfceb('0x1a')](_0x3f57d7);}};}function respondWithFilteredResult(_0x55ddc7,_0x1f1b3e){return function(_0x48294c){if(_0x48294c){var _0xc2b993=typeof _0x1f1b3e[_0xfceb('0x1b')]===_0xfceb('0x1c')&&typeof _0x1f1b3e['limit']===_0xfceb('0x1c');var _0x2bde79=_0x48294c[_0xfceb('0x1d')];var _0x1b06f9=_0xc2b993?0x0:_0x1f1b3e[_0xfceb('0x1b')];var _0xd99374=_0xc2b993?_0x48294c[_0xfceb('0x1d')]:_0x1f1b3e[_0xfceb('0x1b')]+_0x1f1b3e['limit'];var _0xcaee2a;if(_0xd99374>=_0x2bde79){_0xd99374=_0x2bde79;_0xcaee2a=0xc8;}else{_0xcaee2a=0xce;}_0x55ddc7[_0xfceb('0x19')](_0xcaee2a);return _0x55ddc7[_0xfceb('0x1e')]('Content-Range',_0x1b06f9+'-'+_0xd99374+'/'+_0x2bde79)[_0xfceb('0x1a')](_0x48294c);}return null;};}function patchUpdates(_0x468fb5){return function(_0x36698f){try{jsonpatch[_0xfceb('0x1f')](_0x36698f,_0x468fb5,!![]);}catch(_0x596647){return BPromise[_0xfceb('0x20')](_0x596647);}return _0x36698f[_0xfceb('0x21')]();};}function saveUpdates(_0x207e48,_0x28b8f0){return function(_0x3128da){if(_0x3128da){return _0x3128da[_0xfceb('0x22')](_0x207e48)[_0xfceb('0x23')](function(_0x132ae9){return _0x132ae9;});}return null;};}function removeEntity(_0x297d2d,_0x3ba3d1){return function(_0x35e596){if(_0x35e596){return _0x35e596[_0xfceb('0x24')]()[_0xfceb('0x23')](function(){_0x297d2d[_0xfceb('0x19')](0xcc)[_0xfceb('0x18')]();});}};}function handleEntityNotFound(_0x385c8f,_0x445cf9){return function(_0x1d965a){if(!_0x1d965a){_0x385c8f[_0xfceb('0x17')](0x194);}return _0x1d965a;};}function handleError(_0x298cf3,_0x4c659e){_0x4c659e=_0x4c659e||0x1f4;return function(_0x3fa1ce){logger[_0xfceb('0x25')](_0x3fa1ce[_0xfceb('0x26')]);if(_0x3fa1ce['name']){delete _0x3fa1ce['name'];}_0x298cf3[_0xfceb('0x19')](_0x4c659e)[_0xfceb('0x27')](_0x3fa1ce);};}exports[_0xfceb('0x28')]=function(_0x42e65e,_0x312739){var _0x28af90={},_0x1c1e6c={},_0x31be20={'count':0x0,'rows':[]};var _0x2e3046=_[_0xfceb('0x29')](db['Dynamics365Configuration'][_0xfceb('0x2a')],function(_0x3de8f8){return{'name':_0x3de8f8[_0xfceb('0x2b')],'type':_0x3de8f8[_0xfceb('0x2c')]['key']};});_0x1c1e6c['model']=_['map'](_0x2e3046,_0xfceb('0x2d'));_0x1c1e6c[_0xfceb('0x2e')]=_[_0xfceb('0x2f')](_0x42e65e[_0xfceb('0x2e')]);_0x1c1e6c[_0xfceb('0x30')]=_[_0xfceb('0x31')](_0x1c1e6c[_0xfceb('0x32')],_0x1c1e6c[_0xfceb('0x2e')]);_0x28af90[_0xfceb('0x33')]=_[_0xfceb('0x31')](_0x1c1e6c[_0xfceb('0x32')],qs[_0xfceb('0x34')](_0x42e65e[_0xfceb('0x2e')][_0xfceb('0x34')]));_0x28af90['attributes']=_0x28af90[_0xfceb('0x33')][_0xfceb('0x35')]?_0x28af90[_0xfceb('0x33')]:_0x1c1e6c[_0xfceb('0x32')];if(!_0x42e65e[_0xfceb('0x2e')][_0xfceb('0x36')]('nolimit')){_0x28af90[_0xfceb('0x37')]=qs[_0xfceb('0x37')](_0x42e65e['query']['limit']);_0x28af90[_0xfceb('0x1b')]=qs[_0xfceb('0x1b')](_0x42e65e[_0xfceb('0x2e')]['offset']);}_0x28af90[_0xfceb('0x38')]=qs[_0xfceb('0x39')](_0x42e65e[_0xfceb('0x2e')][_0xfceb('0x39')]);_0x28af90['where']=qs[_0xfceb('0x30')](_[_0xfceb('0x3a')](_0x42e65e[_0xfceb('0x2e')],_0x1c1e6c['filters']),_0x2e3046);if(_0x42e65e[_0xfceb('0x2e')][_0xfceb('0x3b')]){_0x28af90[_0xfceb('0x3c')]=_[_0xfceb('0x3d')](_0x28af90['where'],{'$or':_[_0xfceb('0x29')](_0x2e3046,function(_0x517f56){if(_0x517f56['type']!==_0xfceb('0x3e')){var _0x99b403={};_0x99b403[_0x517f56[_0xfceb('0x2d')]]={'$like':'%'+_0x42e65e['query'][_0xfceb('0x3b')]+'%'};return _0x99b403;}})});}_0x28af90=_[_0xfceb('0x3d')]({},_0x28af90,_0x42e65e[_0xfceb('0x3f')]);var _0x2e4ed9={'where':_0x28af90['where']};return db[_0xfceb('0x40')][_0xfceb('0x1d')](_0x2e4ed9)[_0xfceb('0x23')](function(_0x414752){_0x31be20[_0xfceb('0x1d')]=_0x414752;if(_0x42e65e[_0xfceb('0x2e')][_0xfceb('0x41')]){_0x28af90[_0xfceb('0x42')]=[{'all':!![]}];}return db[_0xfceb('0x40')][_0xfceb('0x43')](_0x28af90);})[_0xfceb('0x23')](function(_0xb2a513){_0x31be20[_0xfceb('0x44')]=_0xb2a513;return _0x31be20;})[_0xfceb('0x23')](respondWithFilteredResult(_0x312739,_0x28af90))[_0xfceb('0x45')](handleError(_0x312739,null));};exports['show']=function(_0xdd4cd4,_0x1fcdb8){var _0x3f6f90={'raw':![],'where':{'id':_0xdd4cd4['params']['id']}},_0x1764bd={};_0x1764bd['model']=_['keys'](db[_0xfceb('0x40')]['rawAttributes']);_0x1764bd['query']=_[_0xfceb('0x2f')](_0xdd4cd4[_0xfceb('0x2e')]);_0x1764bd[_0xfceb('0x30')]=_[_0xfceb('0x31')](_0x1764bd['model'],_0x1764bd[_0xfceb('0x2e')]);_0x3f6f90[_0xfceb('0x33')]=_[_0xfceb('0x31')](_0x1764bd[_0xfceb('0x32')],qs['fields'](_0xdd4cd4['query']['fields']));_0x3f6f90[_0xfceb('0x33')]=_0x3f6f90[_0xfceb('0x33')][_0xfceb('0x35')]?_0x3f6f90[_0xfceb('0x33')]:_0x1764bd[_0xfceb('0x32')];if(_0xdd4cd4['query'][_0xfceb('0x41')]){_0x3f6f90['include']=[{'all':!![]}];}_0x3f6f90=_[_0xfceb('0x3d')]({},_0x3f6f90,_0xdd4cd4['options']);return db[_0xfceb('0x40')][_0xfceb('0x46')](_0x3f6f90)[_0xfceb('0x23')](handleEntityNotFound(_0x1fcdb8,null))[_0xfceb('0x23')](respondWithResult(_0x1fcdb8,null))[_0xfceb('0x45')](handleError(_0x1fcdb8,null));};exports[_0xfceb('0x47')]=function(_0x173e38,_0x30c7c9){return db[_0xfceb('0x40')][_0xfceb('0x47')](_0x173e38['body'],{})[_0xfceb('0x23')](respondWithResult(_0x30c7c9,0xc9))[_0xfceb('0x45')](handleError(_0x30c7c9,null));};exports[_0xfceb('0x22')]=function(_0x458c17,_0x50e0fd){if(_0x458c17[_0xfceb('0x48')]['id']){delete _0x458c17['body']['id'];}return db['Dynamics365Configuration'][_0xfceb('0x46')]({'where':{'id':_0x458c17['params']['id']}})['then'](handleEntityNotFound(_0x50e0fd,null))[_0xfceb('0x23')](saveUpdates(_0x458c17[_0xfceb('0x48')],null))[_0xfceb('0x23')](respondWithResult(_0x50e0fd,null))[_0xfceb('0x45')](handleError(_0x50e0fd,null));};exports[_0xfceb('0x24')]=function(_0x3b1982,_0x4568f8){return db['Dynamics365Configuration'][_0xfceb('0x46')]({'where':{'id':_0x3b1982[_0xfceb('0x49')]['id']}})['then'](handleEntityNotFound(_0x4568f8,null))[_0xfceb('0x23')](removeEntity(_0x4568f8,null))['catch'](handleError(_0x4568f8,null));};exports[_0xfceb('0x4a')]=function(_0x3e2cfe,_0x2bd5e1,_0x1f5a0b){var _0x50f54e={};var _0xcb15c0={};var _0x227c11;var _0x14f82d;return db[_0xfceb('0x40')]['findOne']({'where':{'id':_0x3e2cfe['params']['id']}})['then'](handleEntityNotFound(_0x2bd5e1,null))[_0xfceb('0x23')](function(_0xfa01c){if(_0xfa01c){_0x227c11=_0xfa01c;_0xcb15c0[_0xfceb('0x32')]=_[_0xfceb('0x2f')](db[_0xfceb('0x4b')]['rawAttributes']);_0xcb15c0[_0xfceb('0x2e')]=_[_0xfceb('0x2f')](_0x3e2cfe['query']);_0xcb15c0[_0xfceb('0x30')]=_['intersection'](_0xcb15c0[_0xfceb('0x32')],_0xcb15c0[_0xfceb('0x2e')]);_0x50f54e[_0xfceb('0x33')]=_[_0xfceb('0x31')](_0xcb15c0[_0xfceb('0x32')],qs[_0xfceb('0x34')](_0x3e2cfe['query'][_0xfceb('0x34')]));_0x50f54e[_0xfceb('0x33')]=_0x50f54e[_0xfceb('0x33')]['length']?_0x50f54e[_0xfceb('0x33')]:_0xcb15c0['model'];_0x50f54e[_0xfceb('0x38')]=qs[_0xfceb('0x39')](_0x3e2cfe['query'][_0xfceb('0x39')]);_0x50f54e[_0xfceb('0x3c')]=qs['filters'](_['pick'](_0x3e2cfe['query'],_0xcb15c0[_0xfceb('0x30')]));if(_0x3e2cfe[_0xfceb('0x2e')][_0xfceb('0x3b')]){_0x50f54e[_0xfceb('0x3c')]=_[_0xfceb('0x3d')](_0x50f54e[_0xfceb('0x3c')],{'$or':_['map'](_0x50f54e['attributes'],function(_0x1bfc0f){var _0x34d381={};_0x34d381[_0x1bfc0f]={'$like':'%'+_0x3e2cfe[_0xfceb('0x2e')][_0xfceb('0x3b')]+'%'};return _0x34d381;})});}_0x50f54e=_[_0xfceb('0x3d')]({},_0x50f54e,_0x3e2cfe[_0xfceb('0x3f')]);return _0x227c11[_0xfceb('0x4a')](_0x50f54e);}})['then'](function(_0x443e14){if(_0x443e14){_0x14f82d=_0x443e14[_0xfceb('0x35')];if(!_0x3e2cfe[_0xfceb('0x2e')][_0xfceb('0x36')](_0xfceb('0x4c'))){_0x50f54e[_0xfceb('0x37')]=qs[_0xfceb('0x37')](_0x3e2cfe[_0xfceb('0x2e')][_0xfceb('0x37')]);_0x50f54e[_0xfceb('0x1b')]=qs['offset'](_0x3e2cfe[_0xfceb('0x2e')][_0xfceb('0x1b')]);}return _0x227c11['getFields'](_0x50f54e);}})[_0xfceb('0x23')](function(_0x35c025){if(_0x35c025){return _0x35c025?{'count':_0x14f82d,'rows':_0x35c025}:null;}})[_0xfceb('0x23')](respondWithResult(_0x2bd5e1,null))[_0xfceb('0x45')](handleError(_0x2bd5e1,null));};exports[_0xfceb('0x4d')]=function(_0xdbd0a5,_0x483b6a,_0x133676){var _0x341ca1={};var _0x571673={};var _0x1e6ab2;var _0x4e9653;return db[_0xfceb('0x40')]['findOne']({'where':{'id':_0xdbd0a5[_0xfceb('0x49')]['id']}})[_0xfceb('0x23')](handleEntityNotFound(_0x483b6a,null))[_0xfceb('0x23')](function(_0x33afd6){if(_0x33afd6){_0x1e6ab2=_0x33afd6;_0x571673[_0xfceb('0x32')]=_[_0xfceb('0x2f')](db['Dynamics365Field'][_0xfceb('0x2a')]);_0x571673[_0xfceb('0x2e')]=_['keys'](_0xdbd0a5[_0xfceb('0x2e')]);_0x571673[_0xfceb('0x30')]=_[_0xfceb('0x31')](_0x571673[_0xfceb('0x32')],_0x571673['query']);_0x341ca1[_0xfceb('0x33')]=_['intersection'](_0x571673[_0xfceb('0x32')],qs[_0xfceb('0x34')](_0xdbd0a5[_0xfceb('0x2e')]['fields']));_0x341ca1[_0xfceb('0x33')]=_0x341ca1['attributes'][_0xfceb('0x35')]?_0x341ca1[_0xfceb('0x33')]:_0x571673[_0xfceb('0x32')];_0x341ca1[_0xfceb('0x38')]=qs[_0xfceb('0x39')](_0xdbd0a5[_0xfceb('0x2e')]['sort']);_0x341ca1[_0xfceb('0x3c')]=qs[_0xfceb('0x30')](_[_0xfceb('0x3a')](_0xdbd0a5[_0xfceb('0x2e')],_0x571673[_0xfceb('0x30')]));if(_0xdbd0a5[_0xfceb('0x2e')][_0xfceb('0x3b')]){_0x341ca1[_0xfceb('0x3c')]=_[_0xfceb('0x3d')](_0x341ca1[_0xfceb('0x3c')],{'$or':_[_0xfceb('0x29')](_0x341ca1[_0xfceb('0x33')],function(_0x5ac0c9){var _0x2f5a49={};_0x2f5a49[_0x5ac0c9]={'$like':'%'+_0xdbd0a5[_0xfceb('0x2e')]['filter']+'%'};return _0x2f5a49;})});}_0x341ca1=_[_0xfceb('0x3d')]({},_0x341ca1,_0xdbd0a5['options']);return _0x1e6ab2[_0xfceb('0x4d')](_0x341ca1);}})[_0xfceb('0x23')](function(_0x57e839){if(_0x57e839){_0x4e9653=_0x57e839[_0xfceb('0x35')];if(!_0xdbd0a5[_0xfceb('0x2e')]['hasOwnProperty'](_0xfceb('0x4c'))){_0x341ca1[_0xfceb('0x37')]=qs[_0xfceb('0x37')](_0xdbd0a5[_0xfceb('0x2e')]['limit']);_0x341ca1[_0xfceb('0x1b')]=qs[_0xfceb('0x1b')](_0xdbd0a5['query'][_0xfceb('0x1b')]);}return _0x1e6ab2[_0xfceb('0x4d')](_0x341ca1);}})['then'](function(_0xb10ea1){if(_0xb10ea1){return _0xb10ea1?{'count':_0x4e9653,'rows':_0xb10ea1}:null;}})['then'](respondWithResult(_0x483b6a,null))[_0xfceb('0x45')](handleError(_0x483b6a,null));};exports[_0xfceb('0x4e')]=function(_0x803634,_0x26db20,_0xe12732){var _0x412520={};var _0x56bbf7={};var _0x4cc00a;var _0xf3334a;return db[_0xfceb('0x40')][_0xfceb('0x4f')]({'where':{'id':_0x803634[_0xfceb('0x49')]['id']}})[_0xfceb('0x23')](handleEntityNotFound(_0x26db20,null))[_0xfceb('0x23')](function(_0x4cf7d1){if(_0x4cf7d1){_0x4cc00a=_0x4cf7d1;_0x56bbf7[_0xfceb('0x32')]=_[_0xfceb('0x2f')](db['Dynamics365Field'][_0xfceb('0x2a')]);_0x56bbf7['query']=_[_0xfceb('0x2f')](_0x803634[_0xfceb('0x2e')]);_0x56bbf7[_0xfceb('0x30')]=_[_0xfceb('0x31')](_0x56bbf7['model'],_0x56bbf7[_0xfceb('0x2e')]);_0x412520[_0xfceb('0x33')]=_[_0xfceb('0x31')](_0x56bbf7[_0xfceb('0x32')],qs['fields'](_0x803634[_0xfceb('0x2e')]['fields']));_0x412520[_0xfceb('0x33')]=_0x412520[_0xfceb('0x33')]['length']?_0x412520['attributes']:_0x56bbf7['model'];_0x412520[_0xfceb('0x38')]=qs[_0xfceb('0x39')](_0x803634['query'][_0xfceb('0x39')]);_0x412520[_0xfceb('0x3c')]=qs[_0xfceb('0x30')](_[_0xfceb('0x3a')](_0x803634[_0xfceb('0x2e')],_0x56bbf7[_0xfceb('0x30')]));if(_0x803634[_0xfceb('0x2e')][_0xfceb('0x3b')]){_0x412520[_0xfceb('0x3c')]=_[_0xfceb('0x3d')](_0x412520[_0xfceb('0x3c')],{'$or':_['map'](_0x412520[_0xfceb('0x33')],function(_0x53498f){var _0x329e7a={};_0x329e7a[_0x53498f]={'$like':'%'+_0x803634['query'][_0xfceb('0x3b')]+'%'};return _0x329e7a;})});}_0x412520=_[_0xfceb('0x3d')]({},_0x412520,_0x803634['options']);return _0x4cc00a[_0xfceb('0x4e')](_0x412520);}})[_0xfceb('0x23')](function(_0x599894){if(_0x599894){_0xf3334a=_0x599894[_0xfceb('0x35')];if(!_0x803634[_0xfceb('0x2e')][_0xfceb('0x36')](_0xfceb('0x4c'))){_0x412520[_0xfceb('0x37')]=qs['limit'](_0x803634[_0xfceb('0x2e')][_0xfceb('0x37')]);_0x412520[_0xfceb('0x1b')]=qs[_0xfceb('0x1b')](_0x803634[_0xfceb('0x2e')][_0xfceb('0x1b')]);}return _0x4cc00a[_0xfceb('0x4e')](_0x412520);}})[_0xfceb('0x23')](function(_0x37b12f){if(_0x37b12f){return _0x37b12f?{'count':_0xf3334a,'rows':_0x37b12f}:null;}})[_0xfceb('0x23')](respondWithResult(_0x26db20,null))[_0xfceb('0x45')](handleError(_0x26db20,null));};