Built motion from commit efa66e19.|2.6.22
[motion2.git] / server / api / intDynamics365Field / intDynamics365Field.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 _0xf757=['options','includeAll','findAll','rows','catch','show','include','find','create','body','update','params','request-promise','moment','bluebird','mustache','sox','ejs','fs-extra','squel','jsforce','to-csv','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','count','limit','reject','save','then','destroy','error','name','send','index','map','Dynamics365Field','rawAttributes','type','key','model','query','keys','intersection','attributes','fields','length','nolimit','sort','pick','filters','filter','where','merge'];(function(_0x422e6d,_0x14a384){var _0xbf291c=function(_0xb67019){while(--_0xb67019){_0x422e6d['push'](_0x422e6d['shift']());}};_0xbf291c(++_0x14a384);}(_0xf757,0x160));var _0x7f75=function(_0x1857c6,_0x48840c){_0x1857c6=_0x1857c6-0x0;var _0x51011c=_0xf757[_0x1857c6];return _0x51011c;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x7f75('0x0'));var moment=require(_0x7f75('0x1'));var BPromise=require(_0x7f75('0x2'));var Mustache=require(_0x7f75('0x3'));var util=require('util');var path=require('path');var sox=require(_0x7f75('0x4'));var csv=require('to-csv');var ejs=require(_0x7f75('0x5'));var fs=require('fs');var fs_extra=require(_0x7f75('0x6'));var _=require('lodash');var squel=require(_0x7f75('0x7'));var crypto=require('crypto');var jsforce=require(_0x7f75('0x8'));var deskjs=require('desk.js');var toCsv=require(_0x7f75('0x9'));var querystring=require(_0x7f75('0xa'));var Papa=require(_0x7f75('0xb'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x7f75('0xc'));var as=require(_0x7f75('0xd'));var hardwareService=require(_0x7f75('0xe'));var logger=require(_0x7f75('0xf'))(_0x7f75('0x10'));var utils=require(_0x7f75('0x11'));var config=require(_0x7f75('0x12'));var licenseUtil=require(_0x7f75('0x13'));var db=require(_0x7f75('0x14'))['db'];function respondWithStatusCode(_0x359de0,_0x42fe72){_0x42fe72=_0x42fe72||0xcc;return function(_0x2a003f){if(_0x2a003f){return _0x359de0[_0x7f75('0x15')](_0x42fe72);}return _0x359de0['status'](_0x42fe72)[_0x7f75('0x16')]();};}function respondWithResult(_0x5f4ad8,_0x1e9768){_0x1e9768=_0x1e9768||0xc8;return function(_0x3850d0){if(_0x3850d0){return _0x5f4ad8[_0x7f75('0x17')](_0x1e9768)[_0x7f75('0x18')](_0x3850d0);}};}function respondWithFilteredResult(_0x5732b4,_0x136e03){return function(_0x4fac72){if(_0x4fac72){var _0x40d690=typeof _0x136e03[_0x7f75('0x19')]===_0x7f75('0x1a')&&typeof _0x136e03['limit']==='undefined';var _0x2bec76=_0x4fac72['count'];var _0x210875=_0x40d690?0x0:_0x136e03['offset'];var _0x564374=_0x40d690?_0x4fac72[_0x7f75('0x1b')]:_0x136e03['offset']+_0x136e03[_0x7f75('0x1c')];var _0x262cee;if(_0x564374>=_0x2bec76){_0x564374=_0x2bec76;_0x262cee=0xc8;}else{_0x262cee=0xce;}_0x5732b4[_0x7f75('0x17')](_0x262cee);return _0x5732b4['set']('Content-Range',_0x210875+'-'+_0x564374+'/'+_0x2bec76)[_0x7f75('0x18')](_0x4fac72);}return null;};}function patchUpdates(_0x5abf87){return function(_0x2c3fc7){try{jsonpatch['apply'](_0x2c3fc7,_0x5abf87,!![]);}catch(_0x5c9998){return BPromise[_0x7f75('0x1d')](_0x5c9998);}return _0x2c3fc7[_0x7f75('0x1e')]();};}function saveUpdates(_0x19a1bb,_0x1f1624){return function(_0x2a6c92){if(_0x2a6c92){return _0x2a6c92['update'](_0x19a1bb)[_0x7f75('0x1f')](function(_0x46ffda){return _0x46ffda;});}return null;};}function removeEntity(_0x177052,_0x4e9b38){return function(_0x4e5e34){if(_0x4e5e34){return _0x4e5e34[_0x7f75('0x20')]()[_0x7f75('0x1f')](function(){_0x177052[_0x7f75('0x17')](0xcc)[_0x7f75('0x16')]();});}};}function handleEntityNotFound(_0x1e6294,_0x265481){return function(_0x3ee825){if(!_0x3ee825){_0x1e6294[_0x7f75('0x15')](0x194);}return _0x3ee825;};}function handleError(_0x1c6063,_0xaa3a51){_0xaa3a51=_0xaa3a51||0x1f4;return function(_0x4289af){logger[_0x7f75('0x21')](_0x4289af['stack']);if(_0x4289af['name']){delete _0x4289af[_0x7f75('0x22')];}_0x1c6063[_0x7f75('0x17')](_0xaa3a51)[_0x7f75('0x23')](_0x4289af);};}exports[_0x7f75('0x24')]=function(_0x5b17a7,_0x3cded0){var _0x49c759={},_0x1318aa={},_0x25417f={'count':0x0,'rows':[]};var _0xd7fcbf=_[_0x7f75('0x25')](db[_0x7f75('0x26')][_0x7f75('0x27')],function(_0x19e7ac){return{'name':_0x19e7ac['fieldName'],'type':_0x19e7ac[_0x7f75('0x28')][_0x7f75('0x29')]};});_0x1318aa[_0x7f75('0x2a')]=_[_0x7f75('0x25')](_0xd7fcbf,_0x7f75('0x22'));_0x1318aa[_0x7f75('0x2b')]=_[_0x7f75('0x2c')](_0x5b17a7[_0x7f75('0x2b')]);_0x1318aa['filters']=_[_0x7f75('0x2d')](_0x1318aa[_0x7f75('0x2a')],_0x1318aa[_0x7f75('0x2b')]);_0x49c759[_0x7f75('0x2e')]=_['intersection'](_0x1318aa[_0x7f75('0x2a')],qs[_0x7f75('0x2f')](_0x5b17a7['query'][_0x7f75('0x2f')]));_0x49c759[_0x7f75('0x2e')]=_0x49c759['attributes'][_0x7f75('0x30')]?_0x49c759[_0x7f75('0x2e')]:_0x1318aa['model'];if(!_0x5b17a7[_0x7f75('0x2b')]['hasOwnProperty'](_0x7f75('0x31'))){_0x49c759[_0x7f75('0x1c')]=qs[_0x7f75('0x1c')](_0x5b17a7[_0x7f75('0x2b')][_0x7f75('0x1c')]);_0x49c759[_0x7f75('0x19')]=qs[_0x7f75('0x19')](_0x5b17a7[_0x7f75('0x2b')]['offset']);}_0x49c759['order']=qs[_0x7f75('0x32')](_0x5b17a7[_0x7f75('0x2b')][_0x7f75('0x32')]);_0x49c759['where']=qs['filters'](_[_0x7f75('0x33')](_0x5b17a7[_0x7f75('0x2b')],_0x1318aa[_0x7f75('0x34')]),_0xd7fcbf);if(_0x5b17a7[_0x7f75('0x2b')][_0x7f75('0x35')]){_0x49c759[_0x7f75('0x36')]=_[_0x7f75('0x37')](_0x49c759['where'],{'$or':_[_0x7f75('0x25')](_0xd7fcbf,function(_0x2dcf39){if(_0x2dcf39[_0x7f75('0x28')]!=='VIRTUAL'){var _0x446739={};_0x446739[_0x2dcf39[_0x7f75('0x22')]]={'$like':'%'+_0x5b17a7[_0x7f75('0x2b')][_0x7f75('0x35')]+'%'};return _0x446739;}})});}_0x49c759=_['merge']({},_0x49c759,_0x5b17a7[_0x7f75('0x38')]);var _0x5f5556={'where':_0x49c759['where']};return db[_0x7f75('0x26')][_0x7f75('0x1b')](_0x5f5556)[_0x7f75('0x1f')](function(_0x5b382b){_0x25417f[_0x7f75('0x1b')]=_0x5b382b;if(_0x5b17a7[_0x7f75('0x2b')][_0x7f75('0x39')]){_0x49c759['include']=[{'all':!![]}];}return db[_0x7f75('0x26')][_0x7f75('0x3a')](_0x49c759);})[_0x7f75('0x1f')](function(_0x57c4d1){_0x25417f[_0x7f75('0x3b')]=_0x57c4d1;return _0x25417f;})[_0x7f75('0x1f')](respondWithFilteredResult(_0x3cded0,_0x49c759))[_0x7f75('0x3c')](handleError(_0x3cded0,null));};exports[_0x7f75('0x3d')]=function(_0xc7fa3b,_0x3eddf2){var _0x263b07={'raw':!![],'where':{'id':_0xc7fa3b['params']['id']}},_0x2cc584={};_0x2cc584[_0x7f75('0x2a')]=_[_0x7f75('0x2c')](db[_0x7f75('0x26')][_0x7f75('0x27')]);_0x2cc584[_0x7f75('0x2b')]=_[_0x7f75('0x2c')](_0xc7fa3b[_0x7f75('0x2b')]);_0x2cc584[_0x7f75('0x34')]=_[_0x7f75('0x2d')](_0x2cc584[_0x7f75('0x2a')],_0x2cc584[_0x7f75('0x2b')]);_0x263b07[_0x7f75('0x2e')]=_[_0x7f75('0x2d')](_0x2cc584['model'],qs[_0x7f75('0x2f')](_0xc7fa3b[_0x7f75('0x2b')][_0x7f75('0x2f')]));_0x263b07[_0x7f75('0x2e')]=_0x263b07['attributes'][_0x7f75('0x30')]?_0x263b07['attributes']:_0x2cc584['model'];if(_0xc7fa3b[_0x7f75('0x2b')][_0x7f75('0x39')]){_0x263b07[_0x7f75('0x3e')]=[{'all':!![]}];}_0x263b07=_[_0x7f75('0x37')]({},_0x263b07,_0xc7fa3b[_0x7f75('0x38')]);return db[_0x7f75('0x26')][_0x7f75('0x3f')](_0x263b07)[_0x7f75('0x1f')](handleEntityNotFound(_0x3eddf2,null))['then'](respondWithResult(_0x3eddf2,null))[_0x7f75('0x3c')](handleError(_0x3eddf2,null));};exports[_0x7f75('0x40')]=function(_0x5916ab,_0x5eef1d){return db['Dynamics365Field'][_0x7f75('0x40')](_0x5916ab[_0x7f75('0x41')],{})[_0x7f75('0x1f')](respondWithResult(_0x5eef1d,0xc9))[_0x7f75('0x3c')](handleError(_0x5eef1d,null));};exports[_0x7f75('0x42')]=function(_0x5df5f6,_0x4a119b){if(_0x5df5f6['body']['id']){delete _0x5df5f6[_0x7f75('0x41')]['id'];}return db['Dynamics365Field'][_0x7f75('0x3f')]({'where':{'id':_0x5df5f6[_0x7f75('0x43')]['id']}})[_0x7f75('0x1f')](handleEntityNotFound(_0x4a119b,null))['then'](saveUpdates(_0x5df5f6['body'],null))[_0x7f75('0x1f')](respondWithResult(_0x4a119b,null))[_0x7f75('0x3c')](handleError(_0x4a119b,null));};exports[_0x7f75('0x20')]=function(_0x300e80,_0x1effbc){return db[_0x7f75('0x26')]['find']({'where':{'id':_0x300e80[_0x7f75('0x43')]['id']}})[_0x7f75('0x1f')](handleEntityNotFound(_0x1effbc,null))[_0x7f75('0x1f')](removeEntity(_0x1effbc,null))[_0x7f75('0x3c')](handleError(_0x1effbc,null));};