f86460977fd41d91c2b63d7a69f3176610ff800d
[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 _0x9570=['../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','count','offset','set','apply','reject','save','destroy','then','error','stack','name','send','index','map','Dynamics365Field','rawAttributes','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','limit','sort','where','filters','pick','filter','type','VIRTUAL','merge','options','includeAll','findAll','rows','catch','params','include','find','create','update','body','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/logger','api'];(function(_0xfe56e3,_0x5bb3b9){var _0x5bdffa=function(_0x587674){while(--_0x587674){_0xfe56e3['push'](_0xfe56e3['shift']());}};_0x5bdffa(++_0x5bb3b9);}(_0x9570,0x7d));var _0x0957=function(_0x119e7a,_0x3949d3){_0x119e7a=_0x119e7a-0x0;var _0x1fb90a=_0x9570[_0x119e7a];return _0x1fb90a;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x0957('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0x0957('0x1'));var moment=require(_0x0957('0x2'));var BPromise=require(_0x0957('0x3'));var Mustache=require(_0x0957('0x4'));var util=require(_0x0957('0x5'));var path=require('path');var sox=require(_0x0957('0x6'));var csv=require(_0x0957('0x7'));var ejs=require(_0x0957('0x8'));var fs=require('fs');var fs_extra=require(_0x0957('0x9'));var _=require(_0x0957('0xa'));var squel=require('squel');var crypto=require(_0x0957('0xb'));var jsforce=require(_0x0957('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x0957('0xd'));var Papa=require(_0x0957('0xe'));var Redis=require(_0x0957('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x0957('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x0957('0x11'))(_0x0957('0x12'));var utils=require('../../config/utils');var config=require(_0x0957('0x13'));var licenseUtil=require(_0x0957('0x14'));var db=require(_0x0957('0x15'))['db'];function respondWithStatusCode(_0x1f2495,_0x5ccd50){_0x5ccd50=_0x5ccd50||0xcc;return function(_0x40504e){if(_0x40504e){return _0x1f2495[_0x0957('0x16')](_0x5ccd50);}return _0x1f2495[_0x0957('0x17')](_0x5ccd50)[_0x0957('0x18')]();};}function respondWithResult(_0x46fd3c,_0x3a71b3){_0x3a71b3=_0x3a71b3||0xc8;return function(_0x2f6414){if(_0x2f6414){return _0x46fd3c[_0x0957('0x17')](_0x3a71b3)[_0x0957('0x19')](_0x2f6414);}};}function respondWithFilteredResult(_0x2e371f,_0x52f501){return function(_0x280d43){if(_0x280d43){var _0x2622f0=typeof _0x52f501['offset']===_0x0957('0x1a')&&typeof _0x52f501['limit']===_0x0957('0x1a');var _0x57c8c6=_0x280d43[_0x0957('0x1b')];var _0x4feb54=_0x2622f0?0x0:_0x52f501[_0x0957('0x1c')];var _0x2e41fb=_0x2622f0?_0x280d43[_0x0957('0x1b')]:_0x52f501[_0x0957('0x1c')]+_0x52f501['limit'];var _0x165854;if(_0x2e41fb>=_0x57c8c6){_0x2e41fb=_0x57c8c6;_0x165854=0xc8;}else{_0x165854=0xce;}_0x2e371f['status'](_0x165854);return _0x2e371f[_0x0957('0x1d')]('Content-Range',_0x4feb54+'-'+_0x2e41fb+'/'+_0x57c8c6)[_0x0957('0x19')](_0x280d43);}return null;};}function patchUpdates(_0x1b455b){return function(_0x4bafd1){try{jsonpatch[_0x0957('0x1e')](_0x4bafd1,_0x1b455b,!![]);}catch(_0x8629c){return BPromise[_0x0957('0x1f')](_0x8629c);}return _0x4bafd1[_0x0957('0x20')]();};}function saveUpdates(_0x1a1ce0,_0x53eec7){return function(_0x41515c){if(_0x41515c){return _0x41515c['update'](_0x1a1ce0)['then'](function(_0x68565d){return _0x68565d;});}return null;};}function removeEntity(_0x116c9d,_0x160524){return function(_0x3fccc2){if(_0x3fccc2){return _0x3fccc2[_0x0957('0x21')]()[_0x0957('0x22')](function(){_0x116c9d[_0x0957('0x17')](0xcc)[_0x0957('0x18')]();});}};}function handleEntityNotFound(_0x19ca9c,_0x103584){return function(_0x1e616f){if(!_0x1e616f){_0x19ca9c['sendStatus'](0x194);}return _0x1e616f;};}function handleError(_0x2951a9,_0x1d1aa7){_0x1d1aa7=_0x1d1aa7||0x1f4;return function(_0x30ff6d){logger[_0x0957('0x23')](_0x30ff6d[_0x0957('0x24')]);if(_0x30ff6d['name']){delete _0x30ff6d[_0x0957('0x25')];}_0x2951a9['status'](_0x1d1aa7)[_0x0957('0x26')](_0x30ff6d);};}exports[_0x0957('0x27')]=function(_0x4c082b,_0x441f1d){var _0x27cd39={},_0x3b8a8f={},_0x5488fe={'count':0x0,'rows':[]};var _0x2d4fb3=_[_0x0957('0x28')](db[_0x0957('0x29')][_0x0957('0x2a')],function(_0x2c44cf){return{'name':_0x2c44cf['fieldName'],'type':_0x2c44cf['type'][_0x0957('0x2b')]};});_0x3b8a8f[_0x0957('0x2c')]=_[_0x0957('0x28')](_0x2d4fb3,_0x0957('0x25'));_0x3b8a8f[_0x0957('0x2d')]=_[_0x0957('0x2e')](_0x4c082b['query']);_0x3b8a8f['filters']=_[_0x0957('0x2f')](_0x3b8a8f[_0x0957('0x2c')],_0x3b8a8f['query']);_0x27cd39[_0x0957('0x30')]=_[_0x0957('0x2f')](_0x3b8a8f[_0x0957('0x2c')],qs['fields'](_0x4c082b['query'][_0x0957('0x31')]));_0x27cd39[_0x0957('0x30')]=_0x27cd39['attributes'][_0x0957('0x32')]?_0x27cd39[_0x0957('0x30')]:_0x3b8a8f[_0x0957('0x2c')];if(!_0x4c082b['query'][_0x0957('0x33')]('nolimit')){_0x27cd39[_0x0957('0x34')]=qs[_0x0957('0x34')](_0x4c082b[_0x0957('0x2d')]['limit']);_0x27cd39[_0x0957('0x1c')]=qs[_0x0957('0x1c')](_0x4c082b[_0x0957('0x2d')][_0x0957('0x1c')]);}_0x27cd39['order']=qs[_0x0957('0x35')](_0x4c082b[_0x0957('0x2d')][_0x0957('0x35')]);_0x27cd39[_0x0957('0x36')]=qs[_0x0957('0x37')](_[_0x0957('0x38')](_0x4c082b[_0x0957('0x2d')],_0x3b8a8f[_0x0957('0x37')]),_0x2d4fb3);if(_0x4c082b[_0x0957('0x2d')][_0x0957('0x39')]){_0x27cd39[_0x0957('0x36')]=_['merge'](_0x27cd39[_0x0957('0x36')],{'$or':_[_0x0957('0x28')](_0x2d4fb3,function(_0x3b9cf5){if(_0x3b9cf5[_0x0957('0x3a')]!==_0x0957('0x3b')){var _0x554caa={};_0x554caa[_0x3b9cf5[_0x0957('0x25')]]={'$like':'%'+_0x4c082b[_0x0957('0x2d')][_0x0957('0x39')]+'%'};return _0x554caa;}})});}_0x27cd39=_[_0x0957('0x3c')]({},_0x27cd39,_0x4c082b[_0x0957('0x3d')]);var _0x209218={'where':_0x27cd39[_0x0957('0x36')]};return db[_0x0957('0x29')][_0x0957('0x1b')](_0x209218)['then'](function(_0x136ee6){_0x5488fe[_0x0957('0x1b')]=_0x136ee6;if(_0x4c082b[_0x0957('0x2d')][_0x0957('0x3e')]){_0x27cd39['include']=[{'all':!![]}];}return db[_0x0957('0x29')][_0x0957('0x3f')](_0x27cd39);})[_0x0957('0x22')](function(_0x534659){_0x5488fe[_0x0957('0x40')]=_0x534659;return _0x5488fe;})['then'](respondWithFilteredResult(_0x441f1d,_0x27cd39))[_0x0957('0x41')](handleError(_0x441f1d,null));};exports['show']=function(_0x509bb6,_0x5a3ec8){var _0x402689={'raw':!![],'where':{'id':_0x509bb6[_0x0957('0x42')]['id']}},_0x9cde94={};_0x9cde94['model']=_['keys'](db['Dynamics365Field'][_0x0957('0x2a')]);_0x9cde94[_0x0957('0x2d')]=_[_0x0957('0x2e')](_0x509bb6[_0x0957('0x2d')]);_0x9cde94[_0x0957('0x37')]=_[_0x0957('0x2f')](_0x9cde94[_0x0957('0x2c')],_0x9cde94[_0x0957('0x2d')]);_0x402689[_0x0957('0x30')]=_[_0x0957('0x2f')](_0x9cde94[_0x0957('0x2c')],qs['fields'](_0x509bb6[_0x0957('0x2d')][_0x0957('0x31')]));_0x402689[_0x0957('0x30')]=_0x402689[_0x0957('0x30')][_0x0957('0x32')]?_0x402689[_0x0957('0x30')]:_0x9cde94[_0x0957('0x2c')];if(_0x509bb6[_0x0957('0x2d')]['includeAll']){_0x402689[_0x0957('0x43')]=[{'all':!![]}];}_0x402689=_['merge']({},_0x402689,_0x509bb6[_0x0957('0x3d')]);return db[_0x0957('0x29')][_0x0957('0x44')](_0x402689)['then'](handleEntityNotFound(_0x5a3ec8,null))[_0x0957('0x22')](respondWithResult(_0x5a3ec8,null))[_0x0957('0x41')](handleError(_0x5a3ec8,null));};exports[_0x0957('0x45')]=function(_0x594b3a,_0x1ccbbb){return db[_0x0957('0x29')][_0x0957('0x45')](_0x594b3a['body'],{})[_0x0957('0x22')](respondWithResult(_0x1ccbbb,0xc9))[_0x0957('0x41')](handleError(_0x1ccbbb,null));};exports[_0x0957('0x46')]=function(_0x5d5258,_0x4a6d5b){if(_0x5d5258[_0x0957('0x47')]['id']){delete _0x5d5258[_0x0957('0x47')]['id'];}return db[_0x0957('0x29')][_0x0957('0x44')]({'where':{'id':_0x5d5258['params']['id']}})[_0x0957('0x22')](handleEntityNotFound(_0x4a6d5b,null))['then'](saveUpdates(_0x5d5258[_0x0957('0x47')],null))[_0x0957('0x22')](respondWithResult(_0x4a6d5b,null))[_0x0957('0x41')](handleError(_0x4a6d5b,null));};exports['destroy']=function(_0x88dd63,_0x1e3b6d){return db[_0x0957('0x29')]['find']({'where':{'id':_0x88dd63[_0x0957('0x42')]['id']}})[_0x0957('0x22')](handleEntityNotFound(_0x1e3b6d,null))[_0x0957('0x22')](removeEntity(_0x1e3b6d,null))[_0x0957('0x41')](handleError(_0x1e3b6d,null));};