Built motion from commit 47436d59.|2.6.7
[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 _0x8f45=['querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','end','error','stack','name','send','index','rawAttributes','type','key','map','query','keys','intersection','model','attributes','fields','nolimit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','Dynamics365Field','includeAll','include','findAll','catch','show','params','length','create','body','find','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','to-csv','ejs','lodash','squel','jsforce'];(function(_0x4ef34e,_0x11ac32){var _0x3a6f82=function(_0x5e3df9){while(--_0x5e3df9){_0x4ef34e['push'](_0x4ef34e['shift']());}};_0x3a6f82(++_0x11ac32);}(_0x8f45,0x87));var _0x58f4=function(_0x2c91e9,_0x2fb965){_0x2c91e9=_0x2c91e9-0x0;var _0x13f0ff=_0x8f45[_0x2c91e9];return _0x13f0ff;};'use strict';var emlformat=require(_0x58f4('0x0'));var rimraf=require(_0x58f4('0x1'));var zipdir=require(_0x58f4('0x2'));var jsonpatch=require(_0x58f4('0x3'));var rp=require('request-promise');var moment=require(_0x58f4('0x4'));var BPromise=require(_0x58f4('0x5'));var Mustache=require(_0x58f4('0x6'));var util=require('util');var path=require(_0x58f4('0x7'));var sox=require('sox');var csv=require(_0x58f4('0x8'));var ejs=require(_0x58f4('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x58f4('0xa'));var squel=require(_0x58f4('0xb'));var crypto=require('crypto');var jsforce=require(_0x58f4('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x58f4('0xd'));var Papa=require(_0x58f4('0xe'));var Redis=require('ioredis');var authService=require(_0x58f4('0xf'));var qs=require(_0x58f4('0x10'));var as=require(_0x58f4('0x11'));var hardwareService=require(_0x58f4('0x12'));var logger=require(_0x58f4('0x13'))(_0x58f4('0x14'));var utils=require(_0x58f4('0x15'));var config=require(_0x58f4('0x16'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1e89a0,_0x210812){_0x210812=_0x210812||0xcc;return function(_0x420f33){if(_0x420f33){return _0x1e89a0[_0x58f4('0x17')](_0x210812);}return _0x1e89a0[_0x58f4('0x18')](_0x210812)['end']();};}function respondWithResult(_0x1512ee,_0x1592f9){_0x1592f9=_0x1592f9||0xc8;return function(_0x4da631){if(_0x4da631){return _0x1512ee[_0x58f4('0x18')](_0x1592f9)[_0x58f4('0x19')](_0x4da631);}};}function respondWithFilteredResult(_0x3e134a,_0x232b24){return function(_0x57592f){if(_0x57592f){var _0xcb4a3f=typeof _0x232b24[_0x58f4('0x1a')]===_0x58f4('0x1b')&&typeof _0x232b24[_0x58f4('0x1c')]===_0x58f4('0x1b');var _0x549de9=_0x57592f[_0x58f4('0x1d')];var _0x871b18=_0xcb4a3f?0x0:_0x232b24[_0x58f4('0x1a')];var _0x56ef54=_0xcb4a3f?_0x57592f[_0x58f4('0x1d')]:_0x232b24[_0x58f4('0x1a')]+_0x232b24['limit'];var _0x2d9ae4;if(_0x56ef54>=_0x549de9){_0x56ef54=_0x549de9;_0x2d9ae4=0xc8;}else{_0x2d9ae4=0xce;}_0x3e134a[_0x58f4('0x18')](_0x2d9ae4);return _0x3e134a[_0x58f4('0x1e')](_0x58f4('0x1f'),_0x871b18+'-'+_0x56ef54+'/'+_0x549de9)[_0x58f4('0x19')](_0x57592f);}return null;};}function patchUpdates(_0x3b7ad6){return function(_0x48554a){try{jsonpatch[_0x58f4('0x20')](_0x48554a,_0x3b7ad6,!![]);}catch(_0x1e9a45){return BPromise[_0x58f4('0x21')](_0x1e9a45);}return _0x48554a[_0x58f4('0x22')]();};}function saveUpdates(_0x4f75a8,_0x2e31c8){return function(_0x2f0471){if(_0x2f0471){return _0x2f0471[_0x58f4('0x23')](_0x4f75a8)[_0x58f4('0x24')](function(_0xc4f3f){return _0xc4f3f;});}return null;};}function removeEntity(_0x5ce124,_0x18a102){return function(_0x1b6ec4){if(_0x1b6ec4){return _0x1b6ec4['destroy']()['then'](function(){_0x5ce124[_0x58f4('0x18')](0xcc)[_0x58f4('0x25')]();});}};}function handleEntityNotFound(_0xa0a502,_0x3dd47f){return function(_0x1ad217){if(!_0x1ad217){_0xa0a502['sendStatus'](0x194);}return _0x1ad217;};}function handleError(_0x48824e,_0x4f5a6f){_0x4f5a6f=_0x4f5a6f||0x1f4;return function(_0x3062a8){logger[_0x58f4('0x26')](_0x3062a8[_0x58f4('0x27')]);if(_0x3062a8[_0x58f4('0x28')]){delete _0x3062a8[_0x58f4('0x28')];}_0x48824e[_0x58f4('0x18')](_0x4f5a6f)[_0x58f4('0x29')](_0x3062a8);};}exports[_0x58f4('0x2a')]=function(_0x1d23a3,_0x14b8a7){var _0x30d67c={},_0x52529c={},_0x30c33e={'count':0x0,'rows':[]};var _0x244a3b=_['map'](db['Dynamics365Field'][_0x58f4('0x2b')],function(_0x26b903){return{'name':_0x26b903['fieldName'],'type':_0x26b903[_0x58f4('0x2c')][_0x58f4('0x2d')]};});_0x52529c['model']=_[_0x58f4('0x2e')](_0x244a3b,_0x58f4('0x28'));_0x52529c[_0x58f4('0x2f')]=_[_0x58f4('0x30')](_0x1d23a3[_0x58f4('0x2f')]);_0x52529c['filters']=_[_0x58f4('0x31')](_0x52529c[_0x58f4('0x32')],_0x52529c['query']);_0x30d67c[_0x58f4('0x33')]=_[_0x58f4('0x31')](_0x52529c[_0x58f4('0x32')],qs[_0x58f4('0x34')](_0x1d23a3[_0x58f4('0x2f')][_0x58f4('0x34')]));_0x30d67c['attributes']=_0x30d67c[_0x58f4('0x33')]['length']?_0x30d67c['attributes']:_0x52529c['model'];if(!_0x1d23a3[_0x58f4('0x2f')]['hasOwnProperty'](_0x58f4('0x35'))){_0x30d67c['limit']=qs['limit'](_0x1d23a3[_0x58f4('0x2f')][_0x58f4('0x1c')]);_0x30d67c[_0x58f4('0x1a')]=qs[_0x58f4('0x1a')](_0x1d23a3['query'][_0x58f4('0x1a')]);}_0x30d67c[_0x58f4('0x36')]=qs[_0x58f4('0x37')](_0x1d23a3[_0x58f4('0x2f')][_0x58f4('0x37')]);_0x30d67c[_0x58f4('0x38')]=qs['filters'](_[_0x58f4('0x39')](_0x1d23a3[_0x58f4('0x2f')],_0x52529c[_0x58f4('0x3a')]),_0x244a3b);if(_0x1d23a3['query'][_0x58f4('0x3b')]){_0x30d67c[_0x58f4('0x38')]=_[_0x58f4('0x3c')](_0x30d67c[_0x58f4('0x38')],{'$or':_[_0x58f4('0x2e')](_0x244a3b,function(_0x8d3fe1){if(_0x8d3fe1['type']!==_0x58f4('0x3d')){var _0x190a4c={};_0x190a4c[_0x8d3fe1[_0x58f4('0x28')]]={'$like':'%'+_0x1d23a3[_0x58f4('0x2f')][_0x58f4('0x3b')]+'%'};return _0x190a4c;}})});}_0x30d67c=_['merge']({},_0x30d67c,_0x1d23a3[_0x58f4('0x3e')]);var _0x2ed95e={'where':_0x30d67c[_0x58f4('0x38')]};return db[_0x58f4('0x3f')]['count'](_0x2ed95e)[_0x58f4('0x24')](function(_0x49fcf8){_0x30c33e[_0x58f4('0x1d')]=_0x49fcf8;if(_0x1d23a3[_0x58f4('0x2f')][_0x58f4('0x40')]){_0x30d67c[_0x58f4('0x41')]=[{'all':!![]}];}return db[_0x58f4('0x3f')][_0x58f4('0x42')](_0x30d67c);})[_0x58f4('0x24')](function(_0x2d0372){_0x30c33e['rows']=_0x2d0372;return _0x30c33e;})['then'](respondWithFilteredResult(_0x14b8a7,_0x30d67c))[_0x58f4('0x43')](handleError(_0x14b8a7,null));};exports[_0x58f4('0x44')]=function(_0x5f5317,_0x12a516){var _0x233aaa={'raw':!![],'where':{'id':_0x5f5317[_0x58f4('0x45')]['id']}},_0x39cb3b={};_0x39cb3b[_0x58f4('0x32')]=_['keys'](db['Dynamics365Field'][_0x58f4('0x2b')]);_0x39cb3b[_0x58f4('0x2f')]=_['keys'](_0x5f5317['query']);_0x39cb3b[_0x58f4('0x3a')]=_[_0x58f4('0x31')](_0x39cb3b[_0x58f4('0x32')],_0x39cb3b[_0x58f4('0x2f')]);_0x233aaa['attributes']=_[_0x58f4('0x31')](_0x39cb3b[_0x58f4('0x32')],qs[_0x58f4('0x34')](_0x5f5317[_0x58f4('0x2f')][_0x58f4('0x34')]));_0x233aaa['attributes']=_0x233aaa[_0x58f4('0x33')][_0x58f4('0x46')]?_0x233aaa[_0x58f4('0x33')]:_0x39cb3b[_0x58f4('0x32')];if(_0x5f5317[_0x58f4('0x2f')][_0x58f4('0x40')]){_0x233aaa[_0x58f4('0x41')]=[{'all':!![]}];}_0x233aaa=_[_0x58f4('0x3c')]({},_0x233aaa,_0x5f5317[_0x58f4('0x3e')]);return db[_0x58f4('0x3f')]['find'](_0x233aaa)[_0x58f4('0x24')](handleEntityNotFound(_0x12a516,null))[_0x58f4('0x24')](respondWithResult(_0x12a516,null))[_0x58f4('0x43')](handleError(_0x12a516,null));};exports[_0x58f4('0x47')]=function(_0x6871a9,_0x3b4e00){return db[_0x58f4('0x3f')]['create'](_0x6871a9['body'],{})[_0x58f4('0x24')](respondWithResult(_0x3b4e00,0xc9))[_0x58f4('0x43')](handleError(_0x3b4e00,null));};exports[_0x58f4('0x23')]=function(_0x1d123a,_0x3297f7){if(_0x1d123a['body']['id']){delete _0x1d123a[_0x58f4('0x48')]['id'];}return db[_0x58f4('0x3f')][_0x58f4('0x49')]({'where':{'id':_0x1d123a[_0x58f4('0x45')]['id']}})[_0x58f4('0x24')](handleEntityNotFound(_0x3297f7,null))[_0x58f4('0x24')](saveUpdates(_0x1d123a[_0x58f4('0x48')],null))[_0x58f4('0x24')](respondWithResult(_0x3297f7,null))[_0x58f4('0x43')](handleError(_0x3297f7,null));};exports['destroy']=function(_0x5bfe62,_0x390b56){return db['Dynamics365Field'][_0x58f4('0x49')]({'where':{'id':_0x5bfe62[_0x58f4('0x45')]['id']}})[_0x58f4('0x24')](handleEntityNotFound(_0x390b56,null))[_0x58f4('0x24')](removeEntity(_0x390b56,null))[_0x58f4('0x43')](handleError(_0x390b56,null));};