a095eb304634cdfff47beb489f95a019c95fa890
[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 _0xebfe=['fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','type','VIRTUAL','includeAll','include','findAll','rows','catch','params','find','create','body','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','fs-extra','squel','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','error','name','send','index','map','Dynamics365Field','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes'];(function(_0x3ab51d,_0x2fa01d){var _0x29a04e=function(_0x7807b0){while(--_0x7807b0){_0x3ab51d['push'](_0x3ab51d['shift']());}};_0x29a04e(++_0x2fa01d);}(_0xebfe,0x139));var _0xeebf=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xebfe[_0x321bb2];return _0x9c12ed;};'use strict';var emlformat=require(_0xeebf('0x0'));var rimraf=require(_0xeebf('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xeebf('0x2'));var rp=require(_0xeebf('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xeebf('0x4'));var util=require(_0xeebf('0x5'));var path=require(_0xeebf('0x6'));var sox=require(_0xeebf('0x7'));var csv=require(_0xeebf('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xeebf('0x9'));var _=require('lodash');var squel=require(_0xeebf('0xa'));var crypto=require(_0xeebf('0xb'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xeebf('0x8'));var querystring=require(_0xeebf('0xc'));var Papa=require(_0xeebf('0xd'));var Redis=require(_0xeebf('0xe'));var authService=require(_0xeebf('0xf'));var qs=require(_0xeebf('0x10'));var as=require(_0xeebf('0x11'));var hardwareService=require(_0xeebf('0x12'));var logger=require(_0xeebf('0x13'))(_0xeebf('0x14'));var utils=require('../../config/utils');var config=require(_0xeebf('0x15'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x26b27f,_0x1504fe){_0x1504fe=_0x1504fe||0xcc;return function(_0x3b7037){if(_0x3b7037){return _0x26b27f[_0xeebf('0x16')](_0x1504fe);}return _0x26b27f[_0xeebf('0x17')](_0x1504fe)[_0xeebf('0x18')]();};}function respondWithResult(_0x4ccbfc,_0x208f7c){_0x208f7c=_0x208f7c||0xc8;return function(_0x272e45){if(_0x272e45){return _0x4ccbfc[_0xeebf('0x17')](_0x208f7c)[_0xeebf('0x19')](_0x272e45);}};}function respondWithFilteredResult(_0x1f3d6c,_0x39b8b7){return function(_0x4340cb){if(_0x4340cb){var _0x41959d=typeof _0x39b8b7[_0xeebf('0x1a')]===_0xeebf('0x1b')&&typeof _0x39b8b7[_0xeebf('0x1c')]===_0xeebf('0x1b');var _0x8c1b83=_0x4340cb['count'];var _0x369673=_0x41959d?0x0:_0x39b8b7[_0xeebf('0x1a')];var _0x28f893=_0x41959d?_0x4340cb[_0xeebf('0x1d')]:_0x39b8b7['offset']+_0x39b8b7[_0xeebf('0x1c')];var _0x39b653;if(_0x28f893>=_0x8c1b83){_0x28f893=_0x8c1b83;_0x39b653=0xc8;}else{_0x39b653=0xce;}_0x1f3d6c[_0xeebf('0x17')](_0x39b653);return _0x1f3d6c[_0xeebf('0x1e')](_0xeebf('0x1f'),_0x369673+'-'+_0x28f893+'/'+_0x8c1b83)[_0xeebf('0x19')](_0x4340cb);}return null;};}function patchUpdates(_0x3c4125){return function(_0x5b2711){try{jsonpatch[_0xeebf('0x20')](_0x5b2711,_0x3c4125,!![]);}catch(_0x25a604){return BPromise[_0xeebf('0x21')](_0x25a604);}return _0x5b2711[_0xeebf('0x22')]();};}function saveUpdates(_0x64c2f9,_0x866a6c){return function(_0x57a744){if(_0x57a744){return _0x57a744[_0xeebf('0x23')](_0x64c2f9)[_0xeebf('0x24')](function(_0x1b8bc9){return _0x1b8bc9;});}return null;};}function removeEntity(_0x4e896d,_0x3c9b01){return function(_0x53e45e){if(_0x53e45e){return _0x53e45e['destroy']()['then'](function(){_0x4e896d['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4ea89c,_0x4bd622){return function(_0x464aa6){if(!_0x464aa6){_0x4ea89c[_0xeebf('0x16')](0x194);}return _0x464aa6;};}function handleError(_0x24285f,_0x26a7b6){_0x26a7b6=_0x26a7b6||0x1f4;return function(_0x4a312c){logger[_0xeebf('0x25')](_0x4a312c['stack']);if(_0x4a312c[_0xeebf('0x26')]){delete _0x4a312c[_0xeebf('0x26')];}_0x24285f['status'](_0x26a7b6)[_0xeebf('0x27')](_0x4a312c);};}exports[_0xeebf('0x28')]=function(_0x2a27cf,_0x5aa34b){var _0x5665e7={},_0x55d13d={},_0x3ff4cd={'count':0x0,'rows':[]};var _0x101359=_[_0xeebf('0x29')](db[_0xeebf('0x2a')][_0xeebf('0x2b')],function(_0x3215a4){return{'name':_0x3215a4[_0xeebf('0x2c')],'type':_0x3215a4['type'][_0xeebf('0x2d')]};});_0x55d13d[_0xeebf('0x2e')]=_['map'](_0x101359,_0xeebf('0x26'));_0x55d13d[_0xeebf('0x2f')]=_[_0xeebf('0x30')](_0x2a27cf['query']);_0x55d13d[_0xeebf('0x31')]=_[_0xeebf('0x32')](_0x55d13d[_0xeebf('0x2e')],_0x55d13d['query']);_0x5665e7[_0xeebf('0x33')]=_[_0xeebf('0x32')](_0x55d13d[_0xeebf('0x2e')],qs[_0xeebf('0x34')](_0x2a27cf[_0xeebf('0x2f')][_0xeebf('0x34')]));_0x5665e7['attributes']=_0x5665e7['attributes'][_0xeebf('0x35')]?_0x5665e7[_0xeebf('0x33')]:_0x55d13d[_0xeebf('0x2e')];if(!_0x2a27cf[_0xeebf('0x2f')][_0xeebf('0x36')](_0xeebf('0x37'))){_0x5665e7[_0xeebf('0x1c')]=qs[_0xeebf('0x1c')](_0x2a27cf[_0xeebf('0x2f')]['limit']);_0x5665e7[_0xeebf('0x1a')]=qs[_0xeebf('0x1a')](_0x2a27cf[_0xeebf('0x2f')][_0xeebf('0x1a')]);}_0x5665e7[_0xeebf('0x38')]=qs[_0xeebf('0x39')](_0x2a27cf[_0xeebf('0x2f')][_0xeebf('0x39')]);_0x5665e7['where']=qs[_0xeebf('0x31')](_[_0xeebf('0x3a')](_0x2a27cf['query'],_0x55d13d[_0xeebf('0x31')]),_0x101359);if(_0x2a27cf[_0xeebf('0x2f')][_0xeebf('0x3b')]){_0x5665e7[_0xeebf('0x3c')]=_[_0xeebf('0x3d')](_0x5665e7[_0xeebf('0x3c')],{'$or':_['map'](_0x101359,function(_0x520dfc){if(_0x520dfc[_0xeebf('0x3e')]!==_0xeebf('0x3f')){var _0x308cfc={};_0x308cfc[_0x520dfc['name']]={'$like':'%'+_0x2a27cf[_0xeebf('0x2f')][_0xeebf('0x3b')]+'%'};return _0x308cfc;}})});}_0x5665e7=_[_0xeebf('0x3d')]({},_0x5665e7,_0x2a27cf['options']);var _0x2203e5={'where':_0x5665e7[_0xeebf('0x3c')]};return db['Dynamics365Field'][_0xeebf('0x1d')](_0x2203e5)[_0xeebf('0x24')](function(_0x3eb286){_0x3ff4cd[_0xeebf('0x1d')]=_0x3eb286;if(_0x2a27cf['query'][_0xeebf('0x40')]){_0x5665e7[_0xeebf('0x41')]=[{'all':!![]}];}return db[_0xeebf('0x2a')][_0xeebf('0x42')](_0x5665e7);})[_0xeebf('0x24')](function(_0x36b818){_0x3ff4cd[_0xeebf('0x43')]=_0x36b818;return _0x3ff4cd;})[_0xeebf('0x24')](respondWithFilteredResult(_0x5aa34b,_0x5665e7))[_0xeebf('0x44')](handleError(_0x5aa34b,null));};exports['show']=function(_0x50acc2,_0x3f7e42){var _0x560fa6={'raw':!![],'where':{'id':_0x50acc2[_0xeebf('0x45')]['id']}},_0x3faf5c={};_0x3faf5c['model']=_[_0xeebf('0x30')](db[_0xeebf('0x2a')][_0xeebf('0x2b')]);_0x3faf5c[_0xeebf('0x2f')]=_[_0xeebf('0x30')](_0x50acc2[_0xeebf('0x2f')]);_0x3faf5c[_0xeebf('0x31')]=_[_0xeebf('0x32')](_0x3faf5c['model'],_0x3faf5c[_0xeebf('0x2f')]);_0x560fa6[_0xeebf('0x33')]=_['intersection'](_0x3faf5c['model'],qs['fields'](_0x50acc2[_0xeebf('0x2f')]['fields']));_0x560fa6[_0xeebf('0x33')]=_0x560fa6[_0xeebf('0x33')][_0xeebf('0x35')]?_0x560fa6[_0xeebf('0x33')]:_0x3faf5c['model'];if(_0x50acc2[_0xeebf('0x2f')][_0xeebf('0x40')]){_0x560fa6[_0xeebf('0x41')]=[{'all':!![]}];}_0x560fa6=_[_0xeebf('0x3d')]({},_0x560fa6,_0x50acc2['options']);return db[_0xeebf('0x2a')][_0xeebf('0x46')](_0x560fa6)[_0xeebf('0x24')](handleEntityNotFound(_0x3f7e42,null))['then'](respondWithResult(_0x3f7e42,null))[_0xeebf('0x44')](handleError(_0x3f7e42,null));};exports[_0xeebf('0x47')]=function(_0x8610aa,_0x4ec017){return db[_0xeebf('0x2a')][_0xeebf('0x47')](_0x8610aa[_0xeebf('0x48')],{})[_0xeebf('0x24')](respondWithResult(_0x4ec017,0xc9))[_0xeebf('0x44')](handleError(_0x4ec017,null));};exports[_0xeebf('0x23')]=function(_0x495530,_0x4e54c8){if(_0x495530[_0xeebf('0x48')]['id']){delete _0x495530[_0xeebf('0x48')]['id'];}return db[_0xeebf('0x2a')][_0xeebf('0x46')]({'where':{'id':_0x495530[_0xeebf('0x45')]['id']}})[_0xeebf('0x24')](handleEntityNotFound(_0x4e54c8,null))['then'](saveUpdates(_0x495530[_0xeebf('0x48')],null))[_0xeebf('0x24')](respondWithResult(_0x4e54c8,null))[_0xeebf('0x44')](handleError(_0x4e54c8,null));};exports['destroy']=function(_0x1e0f87,_0x52b98c){return db[_0xeebf('0x2a')][_0xeebf('0x46')]({'where':{'id':_0x1e0f87['params']['id']}})[_0xeebf('0x24')](handleEntityNotFound(_0x52b98c,null))[_0xeebf('0x24')](removeEntity(_0x52b98c,null))[_0xeebf('0x44')](handleError(_0x52b98c,null));};