7c6160f02b6aa7c403dd290b929fa1c6e3a8d632
[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 _0xb4f7=['bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','offset','undefined','limit','count','status','set','Content-Range','reject','update','then','destroy','error','stack','name','send','index','map','rawAttributes','model','keys','query','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','filters','type','VIRTUAL','filter','options','includeAll','include','Dynamics365Field','findAll','rows','show','params','length','merge','find','catch','create','body','eml-format','rimraf','fast-json-patch','request-promise','moment'];(function(_0x13fe42,_0x439472){var _0x486df1=function(_0x1b0a49){while(--_0x1b0a49){_0x13fe42['push'](_0x13fe42['shift']());}};_0x486df1(++_0x439472);}(_0xb4f7,0xd3));var _0x7b4f=function(_0x3e380a,_0x5a2e11){_0x3e380a=_0x3e380a-0x0;var _0x2e8b05=_0xb4f7[_0x3e380a];return _0x2e8b05;};'use strict';var emlformat=require(_0x7b4f('0x0'));var rimraf=require(_0x7b4f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7b4f('0x2'));var rp=require(_0x7b4f('0x3'));var moment=require(_0x7b4f('0x4'));var BPromise=require(_0x7b4f('0x5'));var Mustache=require(_0x7b4f('0x6'));var util=require('util');var path=require('path');var sox=require(_0x7b4f('0x7'));var csv=require(_0x7b4f('0x8'));var ejs=require(_0x7b4f('0x9'));var fs=require('fs');var fs_extra=require(_0x7b4f('0xa'));var _=require(_0x7b4f('0xb'));var squel=require('squel');var crypto=require(_0x7b4f('0xc'));var jsforce=require(_0x7b4f('0xd'));var deskjs=require(_0x7b4f('0xe'));var toCsv=require(_0x7b4f('0x8'));var querystring=require(_0x7b4f('0xf'));var Papa=require(_0x7b4f('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x7b4f('0x11'));var as=require(_0x7b4f('0x12'));var hardwareService=require(_0x7b4f('0x13'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x7b4f('0x14'));var licenseUtil=require(_0x7b4f('0x15'));var db=require(_0x7b4f('0x16'))['db'];function respondWithStatusCode(_0x478720,_0x57bf93){_0x57bf93=_0x57bf93||0xcc;return function(_0x24123d){if(_0x24123d){return _0x478720[_0x7b4f('0x17')](_0x57bf93);}return _0x478720['status'](_0x57bf93)[_0x7b4f('0x18')]();};}function respondWithResult(_0x51ac4d,_0x5a4ccf){_0x5a4ccf=_0x5a4ccf||0xc8;return function(_0x3e26fd){if(_0x3e26fd){return _0x51ac4d['status'](_0x5a4ccf)['json'](_0x3e26fd);}};}function respondWithFilteredResult(_0x1039cd,_0x3c9fc3){return function(_0x53170f){if(_0x53170f){var _0x53c388=typeof _0x3c9fc3[_0x7b4f('0x19')]===_0x7b4f('0x1a')&&typeof _0x3c9fc3[_0x7b4f('0x1b')]===_0x7b4f('0x1a');var _0x3b7f10=_0x53170f[_0x7b4f('0x1c')];var _0x143205=_0x53c388?0x0:_0x3c9fc3[_0x7b4f('0x19')];var _0x5ec0c0=_0x53c388?_0x53170f[_0x7b4f('0x1c')]:_0x3c9fc3[_0x7b4f('0x19')]+_0x3c9fc3[_0x7b4f('0x1b')];var _0x1e8610;if(_0x5ec0c0>=_0x3b7f10){_0x5ec0c0=_0x3b7f10;_0x1e8610=0xc8;}else{_0x1e8610=0xce;}_0x1039cd[_0x7b4f('0x1d')](_0x1e8610);return _0x1039cd[_0x7b4f('0x1e')](_0x7b4f('0x1f'),_0x143205+'-'+_0x5ec0c0+'/'+_0x3b7f10)['json'](_0x53170f);}return null;};}function patchUpdates(_0x32b2c1){return function(_0x4c3f44){try{jsonpatch['apply'](_0x4c3f44,_0x32b2c1,!![]);}catch(_0x912b13){return BPromise[_0x7b4f('0x20')](_0x912b13);}return _0x4c3f44['save']();};}function saveUpdates(_0x5ed1b2,_0x3884e4){return function(_0x2fa51e){if(_0x2fa51e){return _0x2fa51e[_0x7b4f('0x21')](_0x5ed1b2)[_0x7b4f('0x22')](function(_0x54dbf8){return _0x54dbf8;});}return null;};}function removeEntity(_0x23705d,_0x21f8c3){return function(_0x48c774){if(_0x48c774){return _0x48c774[_0x7b4f('0x23')]()['then'](function(){_0x23705d[_0x7b4f('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x186873,_0x879b0c){return function(_0x4e2d5a){if(!_0x4e2d5a){_0x186873[_0x7b4f('0x17')](0x194);}return _0x4e2d5a;};}function handleError(_0x20d213,_0x3f7a8c){_0x3f7a8c=_0x3f7a8c||0x1f4;return function(_0x3d398e){logger[_0x7b4f('0x24')](_0x3d398e[_0x7b4f('0x25')]);if(_0x3d398e['name']){delete _0x3d398e[_0x7b4f('0x26')];}_0x20d213[_0x7b4f('0x1d')](_0x3f7a8c)[_0x7b4f('0x27')](_0x3d398e);};}exports[_0x7b4f('0x28')]=function(_0x352ea2,_0x3040c0){var _0xc0e8c2={},_0x430648={},_0x484466={'count':0x0,'rows':[]};var _0x1b2aff=_[_0x7b4f('0x29')](db['Dynamics365Field'][_0x7b4f('0x2a')],function(_0x3f4eee){return{'name':_0x3f4eee['fieldName'],'type':_0x3f4eee['type']['key']};});_0x430648[_0x7b4f('0x2b')]=_[_0x7b4f('0x29')](_0x1b2aff,'name');_0x430648['query']=_[_0x7b4f('0x2c')](_0x352ea2[_0x7b4f('0x2d')]);_0x430648['filters']=_[_0x7b4f('0x2e')](_0x430648[_0x7b4f('0x2b')],_0x430648[_0x7b4f('0x2d')]);_0xc0e8c2['attributes']=_[_0x7b4f('0x2e')](_0x430648[_0x7b4f('0x2b')],qs[_0x7b4f('0x2f')](_0x352ea2[_0x7b4f('0x2d')][_0x7b4f('0x2f')]));_0xc0e8c2[_0x7b4f('0x30')]=_0xc0e8c2[_0x7b4f('0x30')]['length']?_0xc0e8c2[_0x7b4f('0x30')]:_0x430648[_0x7b4f('0x2b')];if(!_0x352ea2[_0x7b4f('0x2d')][_0x7b4f('0x31')](_0x7b4f('0x32'))){_0xc0e8c2[_0x7b4f('0x1b')]=qs[_0x7b4f('0x1b')](_0x352ea2[_0x7b4f('0x2d')][_0x7b4f('0x1b')]);_0xc0e8c2[_0x7b4f('0x19')]=qs[_0x7b4f('0x19')](_0x352ea2['query'][_0x7b4f('0x19')]);}_0xc0e8c2[_0x7b4f('0x33')]=qs[_0x7b4f('0x34')](_0x352ea2[_0x7b4f('0x2d')]['sort']);_0xc0e8c2[_0x7b4f('0x35')]=qs[_0x7b4f('0x36')](_['pick'](_0x352ea2[_0x7b4f('0x2d')],_0x430648[_0x7b4f('0x36')]),_0x1b2aff);if(_0x352ea2[_0x7b4f('0x2d')]['filter']){_0xc0e8c2[_0x7b4f('0x35')]=_['merge'](_0xc0e8c2[_0x7b4f('0x35')],{'$or':_[_0x7b4f('0x29')](_0x1b2aff,function(_0x3454ea){if(_0x3454ea[_0x7b4f('0x37')]!==_0x7b4f('0x38')){var _0x49af0b={};_0x49af0b[_0x3454ea[_0x7b4f('0x26')]]={'$like':'%'+_0x352ea2['query'][_0x7b4f('0x39')]+'%'};return _0x49af0b;}})});}_0xc0e8c2=_['merge']({},_0xc0e8c2,_0x352ea2[_0x7b4f('0x3a')]);var _0x421585={'where':_0xc0e8c2[_0x7b4f('0x35')]};return db['Dynamics365Field'][_0x7b4f('0x1c')](_0x421585)[_0x7b4f('0x22')](function(_0x53f2cc){_0x484466['count']=_0x53f2cc;if(_0x352ea2[_0x7b4f('0x2d')][_0x7b4f('0x3b')]){_0xc0e8c2[_0x7b4f('0x3c')]=[{'all':!![]}];}return db[_0x7b4f('0x3d')][_0x7b4f('0x3e')](_0xc0e8c2);})[_0x7b4f('0x22')](function(_0x4446c1){_0x484466[_0x7b4f('0x3f')]=_0x4446c1;return _0x484466;})[_0x7b4f('0x22')](respondWithFilteredResult(_0x3040c0,_0xc0e8c2))['catch'](handleError(_0x3040c0,null));};exports[_0x7b4f('0x40')]=function(_0x456e94,_0x54aeb1){var _0x25823c={'raw':!![],'where':{'id':_0x456e94[_0x7b4f('0x41')]['id']}},_0x2ff34c={};_0x2ff34c[_0x7b4f('0x2b')]=_[_0x7b4f('0x2c')](db[_0x7b4f('0x3d')][_0x7b4f('0x2a')]);_0x2ff34c['query']=_[_0x7b4f('0x2c')](_0x456e94['query']);_0x2ff34c[_0x7b4f('0x36')]=_[_0x7b4f('0x2e')](_0x2ff34c[_0x7b4f('0x2b')],_0x2ff34c[_0x7b4f('0x2d')]);_0x25823c[_0x7b4f('0x30')]=_['intersection'](_0x2ff34c['model'],qs[_0x7b4f('0x2f')](_0x456e94[_0x7b4f('0x2d')][_0x7b4f('0x2f')]));_0x25823c['attributes']=_0x25823c[_0x7b4f('0x30')][_0x7b4f('0x42')]?_0x25823c['attributes']:_0x2ff34c['model'];if(_0x456e94['query']['includeAll']){_0x25823c['include']=[{'all':!![]}];}_0x25823c=_[_0x7b4f('0x43')]({},_0x25823c,_0x456e94[_0x7b4f('0x3a')]);return db['Dynamics365Field'][_0x7b4f('0x44')](_0x25823c)[_0x7b4f('0x22')](handleEntityNotFound(_0x54aeb1,null))['then'](respondWithResult(_0x54aeb1,null))[_0x7b4f('0x45')](handleError(_0x54aeb1,null));};exports['create']=function(_0x4e919,_0x5a3577){return db[_0x7b4f('0x3d')][_0x7b4f('0x46')](_0x4e919['body'],{})[_0x7b4f('0x22')](respondWithResult(_0x5a3577,0xc9))['catch'](handleError(_0x5a3577,null));};exports[_0x7b4f('0x21')]=function(_0x5ba7cd,_0x5cd10d){if(_0x5ba7cd[_0x7b4f('0x47')]['id']){delete _0x5ba7cd[_0x7b4f('0x47')]['id'];}return db[_0x7b4f('0x3d')][_0x7b4f('0x44')]({'where':{'id':_0x5ba7cd[_0x7b4f('0x41')]['id']}})[_0x7b4f('0x22')](handleEntityNotFound(_0x5cd10d,null))['then'](saveUpdates(_0x5ba7cd[_0x7b4f('0x47')],null))[_0x7b4f('0x22')](respondWithResult(_0x5cd10d,null))[_0x7b4f('0x45')](handleError(_0x5cd10d,null));};exports['destroy']=function(_0x56e7ea,_0xee4983){return db[_0x7b4f('0x3d')][_0x7b4f('0x44')]({'where':{'id':_0x56e7ea[_0x7b4f('0x41')]['id']}})[_0x7b4f('0x22')](handleEntityNotFound(_0xee4983,null))[_0x7b4f('0x22')](removeEntity(_0xee4983,null))[_0x7b4f('0x45')](handleError(_0xee4983,null));};