Built motion from commit 953226e6.|2.6.32
[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 _0x990e=['offset','undefined','limit','count','set','apply','reject','save','update','then','sendStatus','stack','name','send','index','map','Dynamics365Field','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','merge','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','params','keys','length','find','create','body','destroy','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','status','end','json'];(function(_0x54ccd7,_0x3bc3ce){var _0x4e667b=function(_0xab8fea){while(--_0xab8fea){_0x54ccd7['push'](_0x54ccd7['shift']());}};_0x4e667b(++_0x3bc3ce);}(_0x990e,0x193));var _0xe990=function(_0xbaa2eb,_0x5b51cd){_0xbaa2eb=_0xbaa2eb-0x0;var _0x328ca0=_0x990e[_0xbaa2eb];return _0x328ca0;};'use strict';var emlformat=require(_0xe990('0x0'));var rimraf=require(_0xe990('0x1'));var zipdir=require(_0xe990('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe990('0x3'));var moment=require(_0xe990('0x4'));var BPromise=require(_0xe990('0x5'));var Mustache=require('mustache');var util=require(_0xe990('0x6'));var path=require(_0xe990('0x7'));var sox=require(_0xe990('0x8'));var csv=require(_0xe990('0x9'));var ejs=require(_0xe990('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xe990('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xe990('0xc'));var deskjs=require(_0xe990('0xd'));var toCsv=require('to-csv');var querystring=require(_0xe990('0xe'));var Papa=require('papaparse');var Redis=require(_0xe990('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xe990('0x10'));var as=require(_0xe990('0x11'));var hardwareService=require(_0xe990('0x12'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0xe990('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1558c0,_0x57afe1){_0x57afe1=_0x57afe1||0xcc;return function(_0x1101ec){if(_0x1101ec){return _0x1558c0['sendStatus'](_0x57afe1);}return _0x1558c0[_0xe990('0x14')](_0x57afe1)[_0xe990('0x15')]();};}function respondWithResult(_0x15b87d,_0x375c78){_0x375c78=_0x375c78||0xc8;return function(_0xfd3df5){if(_0xfd3df5){return _0x15b87d[_0xe990('0x14')](_0x375c78)[_0xe990('0x16')](_0xfd3df5);}};}function respondWithFilteredResult(_0x4388af,_0x5f7a72){return function(_0x336534){if(_0x336534){var _0x196353=typeof _0x5f7a72[_0xe990('0x17')]===_0xe990('0x18')&&typeof _0x5f7a72[_0xe990('0x19')]===_0xe990('0x18');var _0x3b5226=_0x336534['count'];var _0xd5093f=_0x196353?0x0:_0x5f7a72[_0xe990('0x17')];var _0xe9c4e8=_0x196353?_0x336534[_0xe990('0x1a')]:_0x5f7a72[_0xe990('0x17')]+_0x5f7a72['limit'];var _0x433384;if(_0xe9c4e8>=_0x3b5226){_0xe9c4e8=_0x3b5226;_0x433384=0xc8;}else{_0x433384=0xce;}_0x4388af[_0xe990('0x14')](_0x433384);return _0x4388af[_0xe990('0x1b')]('Content-Range',_0xd5093f+'-'+_0xe9c4e8+'/'+_0x3b5226)[_0xe990('0x16')](_0x336534);}return null;};}function patchUpdates(_0x55faad){return function(_0x5ac4d6){try{jsonpatch[_0xe990('0x1c')](_0x5ac4d6,_0x55faad,!![]);}catch(_0x5320db){return BPromise[_0xe990('0x1d')](_0x5320db);}return _0x5ac4d6[_0xe990('0x1e')]();};}function saveUpdates(_0xfa5e6b,_0x129231){return function(_0x350cf1){if(_0x350cf1){return _0x350cf1[_0xe990('0x1f')](_0xfa5e6b)[_0xe990('0x20')](function(_0x2e755e){return _0x2e755e;});}return null;};}function removeEntity(_0x488d26,_0x337ae8){return function(_0x2d3f22){if(_0x2d3f22){return _0x2d3f22['destroy']()[_0xe990('0x20')](function(){_0x488d26['status'](0xcc)[_0xe990('0x15')]();});}};}function handleEntityNotFound(_0x91521e,_0xd99802){return function(_0x4d2442){if(!_0x4d2442){_0x91521e[_0xe990('0x21')](0x194);}return _0x4d2442;};}function handleError(_0x290770,_0x1840be){_0x1840be=_0x1840be||0x1f4;return function(_0x134a1b){logger['error'](_0x134a1b[_0xe990('0x22')]);if(_0x134a1b[_0xe990('0x23')]){delete _0x134a1b[_0xe990('0x23')];}_0x290770[_0xe990('0x14')](_0x1840be)[_0xe990('0x24')](_0x134a1b);};}exports[_0xe990('0x25')]=function(_0x191fe0,_0x1901fe){var _0x31cc35={},_0x38b1be={},_0x2e58bb={'count':0x0,'rows':[]};var _0x457b44=_[_0xe990('0x26')](db[_0xe990('0x27')][_0xe990('0x28')],function(_0x419386){return{'name':_0x419386[_0xe990('0x29')],'type':_0x419386[_0xe990('0x2a')][_0xe990('0x2b')]};});_0x38b1be[_0xe990('0x2c')]=_[_0xe990('0x26')](_0x457b44,'name');_0x38b1be[_0xe990('0x2d')]=_['keys'](_0x191fe0[_0xe990('0x2d')]);_0x38b1be[_0xe990('0x2e')]=_[_0xe990('0x2f')](_0x38b1be[_0xe990('0x2c')],_0x38b1be[_0xe990('0x2d')]);_0x31cc35[_0xe990('0x30')]=_[_0xe990('0x2f')](_0x38b1be[_0xe990('0x2c')],qs['fields'](_0x191fe0[_0xe990('0x2d')][_0xe990('0x31')]));_0x31cc35[_0xe990('0x30')]=_0x31cc35['attributes']['length']?_0x31cc35[_0xe990('0x30')]:_0x38b1be[_0xe990('0x2c')];if(!_0x191fe0[_0xe990('0x2d')][_0xe990('0x32')]('nolimit')){_0x31cc35['limit']=qs['limit'](_0x191fe0['query'][_0xe990('0x19')]);_0x31cc35[_0xe990('0x17')]=qs['offset'](_0x191fe0[_0xe990('0x2d')][_0xe990('0x17')]);}_0x31cc35[_0xe990('0x33')]=qs[_0xe990('0x34')](_0x191fe0[_0xe990('0x2d')]['sort']);_0x31cc35[_0xe990('0x35')]=qs[_0xe990('0x2e')](_['pick'](_0x191fe0['query'],_0x38b1be[_0xe990('0x2e')]),_0x457b44);if(_0x191fe0['query']['filter']){_0x31cc35['where']=_[_0xe990('0x36')](_0x31cc35['where'],{'$or':_['map'](_0x457b44,function(_0x41bc89){if(_0x41bc89[_0xe990('0x2a')]!==_0xe990('0x37')){var _0x3196bc={};_0x3196bc[_0x41bc89['name']]={'$like':'%'+_0x191fe0[_0xe990('0x2d')][_0xe990('0x38')]+'%'};return _0x3196bc;}})});}_0x31cc35=_[_0xe990('0x36')]({},_0x31cc35,_0x191fe0[_0xe990('0x39')]);var _0x2379bd={'where':_0x31cc35['where']};return db[_0xe990('0x27')][_0xe990('0x1a')](_0x2379bd)[_0xe990('0x20')](function(_0x3ecfa5){_0x2e58bb[_0xe990('0x1a')]=_0x3ecfa5;if(_0x191fe0[_0xe990('0x2d')][_0xe990('0x3a')]){_0x31cc35[_0xe990('0x3b')]=[{'all':!![]}];}return db[_0xe990('0x27')][_0xe990('0x3c')](_0x31cc35);})[_0xe990('0x20')](function(_0x41ed27){_0x2e58bb[_0xe990('0x3d')]=_0x41ed27;return _0x2e58bb;})[_0xe990('0x20')](respondWithFilteredResult(_0x1901fe,_0x31cc35))[_0xe990('0x3e')](handleError(_0x1901fe,null));};exports[_0xe990('0x3f')]=function(_0xb4dfd6,_0x589d46){var _0x290df5={'raw':!![],'where':{'id':_0xb4dfd6[_0xe990('0x40')]['id']}},_0x496eb2={};_0x496eb2['model']=_[_0xe990('0x41')](db['Dynamics365Field'][_0xe990('0x28')]);_0x496eb2[_0xe990('0x2d')]=_['keys'](_0xb4dfd6[_0xe990('0x2d')]);_0x496eb2[_0xe990('0x2e')]=_[_0xe990('0x2f')](_0x496eb2['model'],_0x496eb2['query']);_0x290df5[_0xe990('0x30')]=_['intersection'](_0x496eb2[_0xe990('0x2c')],qs['fields'](_0xb4dfd6['query']['fields']));_0x290df5['attributes']=_0x290df5['attributes'][_0xe990('0x42')]?_0x290df5[_0xe990('0x30')]:_0x496eb2[_0xe990('0x2c')];if(_0xb4dfd6[_0xe990('0x2d')][_0xe990('0x3a')]){_0x290df5[_0xe990('0x3b')]=[{'all':!![]}];}_0x290df5=_[_0xe990('0x36')]({},_0x290df5,_0xb4dfd6[_0xe990('0x39')]);return db[_0xe990('0x27')][_0xe990('0x43')](_0x290df5)['then'](handleEntityNotFound(_0x589d46,null))[_0xe990('0x20')](respondWithResult(_0x589d46,null))[_0xe990('0x3e')](handleError(_0x589d46,null));};exports[_0xe990('0x44')]=function(_0x5283de,_0x28d8e7){return db[_0xe990('0x27')][_0xe990('0x44')](_0x5283de['body'],{})[_0xe990('0x20')](respondWithResult(_0x28d8e7,0xc9))[_0xe990('0x3e')](handleError(_0x28d8e7,null));};exports[_0xe990('0x1f')]=function(_0x2bf062,_0xc7dd4b){if(_0x2bf062['body']['id']){delete _0x2bf062['body']['id'];}return db[_0xe990('0x27')][_0xe990('0x43')]({'where':{'id':_0x2bf062[_0xe990('0x40')]['id']}})[_0xe990('0x20')](handleEntityNotFound(_0xc7dd4b,null))[_0xe990('0x20')](saveUpdates(_0x2bf062[_0xe990('0x45')],null))['then'](respondWithResult(_0xc7dd4b,null))[_0xe990('0x3e')](handleError(_0xc7dd4b,null));};exports[_0xe990('0x46')]=function(_0x354c0f,_0x39ca31){return db[_0xe990('0x27')][_0xe990('0x43')]({'where':{'id':_0x354c0f[_0xe990('0x40')]['id']}})['then'](handleEntityNotFound(_0x39ca31,null))[_0xe990('0x20')](removeEntity(_0x39ca31,null))[_0xe990('0x3e')](handleError(_0x39ca31,null));};