Built motion from commit (unavailable).|2.4.18
[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 _0xf446=['apply','reject','then','destroy','error','name','index','map','rawAttributes','fieldName','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','type','Dynamics365Field','includeAll','findAll','rows','show','include','options','create','catch','update','body','find','params','html-pdf','rimraf','zip-dir','request-promise','bluebird','mustache','path','lodash','crypto','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','end','count','offset','limit','Content-Range','json'];(function(_0x1cbcf1,_0x3f9fd9){var _0x3a06f0=function(_0x5425d4){while(--_0x5425d4){_0x1cbcf1['push'](_0x1cbcf1['shift']());}};_0x3a06f0(++_0x3f9fd9);}(_0xf446,0x1c0));var _0x6f44=function(_0xb992ce,_0x2c09c7){_0xb992ce=_0xb992ce-0x0;var _0x18a182=_0xf446[_0xb992ce];return _0x18a182;};'use strict';var pdf=require(_0x6f44('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x6f44('0x1'));var zipdir=require(_0x6f44('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x6f44('0x3'));var moment=require('moment');var BPromise=require(_0x6f44('0x4'));var Mustache=require(_0x6f44('0x5'));var util=require('util');var path=require(_0x6f44('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x6f44('0x7'));var squel=require('squel');var crypto=require(_0x6f44('0x8'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x6f44('0x9'));var querystring=require('querystring');var Papa=require(_0x6f44('0xa'));var Redis=require(_0x6f44('0xb'));var authService=require(_0x6f44('0xc'));var qs=require(_0x6f44('0xd'));var as=require(_0x6f44('0xe'));var hardwareService=require(_0x6f44('0xf'));var logger=require(_0x6f44('0x10'))(_0x6f44('0x11'));var utils=require('../../config/utils');var config=require(_0x6f44('0x12'));var db=require(_0x6f44('0x13'))['db'];function respondWithStatusCode(_0x28ec05,_0x4bacc0){_0x4bacc0=_0x4bacc0||0xcc;return function(_0x305757){if(_0x305757){return _0x28ec05[_0x6f44('0x14')](_0x4bacc0);}return _0x28ec05[_0x6f44('0x15')](_0x4bacc0)[_0x6f44('0x16')]();};}function respondWithResult(_0x5bd6da,_0x82c009){_0x82c009=_0x82c009||0xc8;return function(_0x4f1b19){if(_0x4f1b19){return _0x5bd6da[_0x6f44('0x15')](_0x82c009)['json'](_0x4f1b19);}};}function respondWithFilteredResult(_0x5ee20e,_0x33e088){return function(_0xe5c968){if(_0xe5c968){var _0x33a130=_0xe5c968[_0x6f44('0x17')],_0x22200e=_0x33e088[_0x6f44('0x18')],_0x43b6cd=_0x33e088[_0x6f44('0x18')]+_0x33e088[_0x6f44('0x19')],_0x34a64d;if(_0x43b6cd>=_0x33a130){_0x43b6cd=_0x33a130;_0x34a64d=0xc8;}else{_0x34a64d=0xce;}_0x5ee20e[_0x6f44('0x15')](_0x34a64d);return _0x5ee20e['set'](_0x6f44('0x1a'),_0x22200e+'-'+_0x43b6cd+'/'+_0x33a130)[_0x6f44('0x1b')](_0xe5c968);}return null;};}function patchUpdates(_0x40f74c){return function(_0x39bc07){try{jsonpatch[_0x6f44('0x1c')](_0x39bc07,_0x40f74c,!![]);}catch(_0x57af2a){return BPromise[_0x6f44('0x1d')](_0x57af2a);}return _0x39bc07['save']();};}function saveUpdates(_0x43ca38,_0x57d6a2){return function(_0x3c1265){if(_0x3c1265){return _0x3c1265['update'](_0x43ca38)[_0x6f44('0x1e')](function(_0x2a1cff){return _0x2a1cff;});}return null;};}function removeEntity(_0x25b798,_0xf1a57c){return function(_0x1137db){if(_0x1137db){return _0x1137db[_0x6f44('0x1f')]()[_0x6f44('0x1e')](function(){_0x25b798[_0x6f44('0x15')](0xcc)[_0x6f44('0x16')]();});}};}function handleEntityNotFound(_0x50bbad,_0x56cbea){return function(_0x3583c7){if(!_0x3583c7){_0x50bbad[_0x6f44('0x14')](0x194);}return _0x3583c7;};}function handleError(_0x43faec,_0x3cdc68){_0x3cdc68=_0x3cdc68||0x1f4;return function(_0x3771d8){logger[_0x6f44('0x20')](_0x3771d8['stack']);if(_0x3771d8[_0x6f44('0x21')]){delete _0x3771d8[_0x6f44('0x21')];}_0x43faec['status'](_0x3cdc68)['send'](_0x3771d8);};}exports[_0x6f44('0x22')]=function(_0x38ebb4,_0x2a8d41){var _0x3773dd={},_0xe22f1e={},_0x16c879={'count':0x0,'rows':[]};var _0x4c994b=_[_0x6f44('0x23')](db['Dynamics365Field'][_0x6f44('0x24')],function(_0x6784ce){return{'name':_0x6784ce[_0x6f44('0x25')],'type':_0x6784ce['type'][_0x6f44('0x26')]};});_0xe22f1e[_0x6f44('0x27')]=_[_0x6f44('0x23')](_0x4c994b,'name');_0xe22f1e['query']=_[_0x6f44('0x28')](_0x38ebb4[_0x6f44('0x29')]);_0xe22f1e[_0x6f44('0x2a')]=_['intersection'](_0xe22f1e[_0x6f44('0x27')],_0xe22f1e[_0x6f44('0x29')]);_0x3773dd[_0x6f44('0x2b')]=_[_0x6f44('0x2c')](_0xe22f1e[_0x6f44('0x27')],qs[_0x6f44('0x2d')](_0x38ebb4[_0x6f44('0x29')][_0x6f44('0x2d')]));_0x3773dd[_0x6f44('0x2b')]=_0x3773dd[_0x6f44('0x2b')][_0x6f44('0x2e')]?_0x3773dd[_0x6f44('0x2b')]:_0xe22f1e['model'];if(!_0x38ebb4['query'][_0x6f44('0x2f')](_0x6f44('0x30'))){_0x3773dd[_0x6f44('0x19')]=qs['limit'](_0x38ebb4[_0x6f44('0x29')][_0x6f44('0x19')]);_0x3773dd[_0x6f44('0x18')]=qs[_0x6f44('0x18')](_0x38ebb4[_0x6f44('0x29')][_0x6f44('0x18')]);}_0x3773dd[_0x6f44('0x31')]=qs[_0x6f44('0x32')](_0x38ebb4[_0x6f44('0x29')]['sort']);_0x3773dd[_0x6f44('0x33')]=qs['filters'](_['pick'](_0x38ebb4['query'],_0xe22f1e[_0x6f44('0x2a')]));if(_0x38ebb4[_0x6f44('0x29')][_0x6f44('0x34')]){_0x3773dd[_0x6f44('0x33')]=_[_0x6f44('0x35')](_0x3773dd['where'],{'$or':_[_0x6f44('0x23')](_0x4c994b,function(_0x30f3a6){if(_0x30f3a6[_0x6f44('0x36')]!=='VIRTUAL'){var _0x38ba8d={};_0x38ba8d[_0x30f3a6[_0x6f44('0x21')]]={'$like':'%'+_0x38ebb4[_0x6f44('0x29')][_0x6f44('0x34')]+'%'};return _0x38ba8d;}})});}_0x3773dd=_[_0x6f44('0x35')]({},_0x3773dd,_0x38ebb4['options']);var _0x179985={'where':_0x3773dd[_0x6f44('0x33')]};return db[_0x6f44('0x37')]['count'](_0x179985)['then'](function(_0x4d8af2){_0x16c879[_0x6f44('0x17')]=_0x4d8af2;if(_0x38ebb4['query'][_0x6f44('0x38')]){_0x3773dd['include']=[{'all':!![]}];}return db[_0x6f44('0x37')][_0x6f44('0x39')](_0x3773dd);})[_0x6f44('0x1e')](function(_0x313f80){_0x16c879[_0x6f44('0x3a')]=_0x313f80;return _0x16c879;})[_0x6f44('0x1e')](respondWithFilteredResult(_0x2a8d41,_0x3773dd))['catch'](handleError(_0x2a8d41,null));};exports[_0x6f44('0x3b')]=function(_0x449096,_0x1536ca){var _0x297999={'raw':!![],'where':{'id':_0x449096['params']['id']}},_0x16b94e={};_0x16b94e[_0x6f44('0x27')]=_[_0x6f44('0x28')](db[_0x6f44('0x37')][_0x6f44('0x24')]);_0x16b94e[_0x6f44('0x29')]=_[_0x6f44('0x28')](_0x449096[_0x6f44('0x29')]);_0x16b94e[_0x6f44('0x2a')]=_[_0x6f44('0x2c')](_0x16b94e['model'],_0x16b94e[_0x6f44('0x29')]);_0x297999['attributes']=_[_0x6f44('0x2c')](_0x16b94e[_0x6f44('0x27')],qs[_0x6f44('0x2d')](_0x449096[_0x6f44('0x29')]['fields']));_0x297999[_0x6f44('0x2b')]=_0x297999[_0x6f44('0x2b')]['length']?_0x297999[_0x6f44('0x2b')]:_0x16b94e[_0x6f44('0x27')];if(_0x449096[_0x6f44('0x29')][_0x6f44('0x38')]){_0x297999[_0x6f44('0x3c')]=[{'all':!![]}];}_0x297999=_[_0x6f44('0x35')]({},_0x297999,_0x449096[_0x6f44('0x3d')]);return db[_0x6f44('0x37')]['find'](_0x297999)[_0x6f44('0x1e')](handleEntityNotFound(_0x1536ca,null))[_0x6f44('0x1e')](respondWithResult(_0x1536ca,null))['catch'](handleError(_0x1536ca,null));};exports[_0x6f44('0x3e')]=function(_0x4e8f9e,_0x4f4c55){return db['Dynamics365Field'][_0x6f44('0x3e')](_0x4e8f9e['body'],{})['then'](respondWithResult(_0x4f4c55,0xc9))[_0x6f44('0x3f')](handleError(_0x4f4c55,null));};exports[_0x6f44('0x40')]=function(_0x3e1a61,_0x416ee2){if(_0x3e1a61[_0x6f44('0x41')]['id']){delete _0x3e1a61['body']['id'];}return db[_0x6f44('0x37')][_0x6f44('0x42')]({'where':{'id':_0x3e1a61[_0x6f44('0x43')]['id']}})[_0x6f44('0x1e')](handleEntityNotFound(_0x416ee2,null))[_0x6f44('0x1e')](saveUpdates(_0x3e1a61['body'],null))[_0x6f44('0x1e')](respondWithResult(_0x416ee2,null))[_0x6f44('0x3f')](handleError(_0x416ee2,null));};exports[_0x6f44('0x1f')]=function(_0x2087f7,_0x45c6df){return db['Dynamics365Field']['find']({'where':{'id':_0x2087f7[_0x6f44('0x43')]['id']}})['then'](handleEntityNotFound(_0x45c6df,null))[_0x6f44('0x1e')](removeEntity(_0x45c6df,null))['catch'](handleError(_0x45c6df,null));};