Built motion from commit 936e8062.|2.5.33
[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 _0x18f5=['find','create','body','update','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','sox','ejs','fs-extra','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','send','index','map','Dynamics365Field','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','attributes','fields','length','nolimit','order','where','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','params'];(function(_0x1573a7,_0x5d6992){var _0x36835d=function(_0x1f04aa){while(--_0x1f04aa){_0x1573a7['push'](_0x1573a7['shift']());}};_0x36835d(++_0x5d6992);}(_0x18f5,0x120));var _0x518f=function(_0x1f9f37,_0x18776e){_0x1f9f37=_0x1f9f37-0x0;var _0x21c080=_0x18f5[_0x1f9f37];return _0x21c080;};'use strict';var emlformat=require(_0x518f('0x0'));var rimraf=require(_0x518f('0x1'));var zipdir=require(_0x518f('0x2'));var jsonpatch=require(_0x518f('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x518f('0x4'));var Mustache=require(_0x518f('0x5'));var util=require(_0x518f('0x6'));var path=require('path');var sox=require(_0x518f('0x7'));var csv=require('to-csv');var ejs=require(_0x518f('0x8'));var fs=require('fs');var fs_extra=require(_0x518f('0x9'));var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x518f('0xa'));var toCsv=require(_0x518f('0xb'));var querystring=require(_0x518f('0xc'));var Papa=require(_0x518f('0xd'));var Redis=require(_0x518f('0xe'));var authService=require(_0x518f('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x518f('0x10'));var hardwareService=require(_0x518f('0x11'));var logger=require('../../config/logger')(_0x518f('0x12'));var utils=require(_0x518f('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x518f('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x475f9b,_0x1c5523){_0x1c5523=_0x1c5523||0xcc;return function(_0x168c37){if(_0x168c37){return _0x475f9b[_0x518f('0x15')](_0x1c5523);}return _0x475f9b['status'](_0x1c5523)[_0x518f('0x16')]();};}function respondWithResult(_0x233deb,_0x176aa2){_0x176aa2=_0x176aa2||0xc8;return function(_0x3ccc2c){if(_0x3ccc2c){return _0x233deb[_0x518f('0x17')](_0x176aa2)[_0x518f('0x18')](_0x3ccc2c);}};}function respondWithFilteredResult(_0x11e762,_0x376040){return function(_0x561136){if(_0x561136){var _0x199047=typeof _0x376040[_0x518f('0x19')]===_0x518f('0x1a')&&typeof _0x376040[_0x518f('0x1b')]===_0x518f('0x1a');var _0x49e222=_0x561136['count'];var _0x1fe8e9=_0x199047?0x0:_0x376040[_0x518f('0x19')];var _0x154f4b=_0x199047?_0x561136[_0x518f('0x1c')]:_0x376040[_0x518f('0x19')]+_0x376040['limit'];var _0x29c7a8;if(_0x154f4b>=_0x49e222){_0x154f4b=_0x49e222;_0x29c7a8=0xc8;}else{_0x29c7a8=0xce;}_0x11e762[_0x518f('0x17')](_0x29c7a8);return _0x11e762[_0x518f('0x1d')](_0x518f('0x1e'),_0x1fe8e9+'-'+_0x154f4b+'/'+_0x49e222)['json'](_0x561136);}return null;};}function patchUpdates(_0x43127e){return function(_0x4f1233){try{jsonpatch[_0x518f('0x1f')](_0x4f1233,_0x43127e,!![]);}catch(_0x33a59d){return BPromise[_0x518f('0x20')](_0x33a59d);}return _0x4f1233[_0x518f('0x21')]();};}function saveUpdates(_0x34860f,_0x5dff1f){return function(_0x4f7e59){if(_0x4f7e59){return _0x4f7e59['update'](_0x34860f)[_0x518f('0x22')](function(_0xa58b69){return _0xa58b69;});}return null;};}function removeEntity(_0x591162,_0x26ab5d){return function(_0x534839){if(_0x534839){return _0x534839[_0x518f('0x23')]()[_0x518f('0x22')](function(){_0x591162[_0x518f('0x17')](0xcc)[_0x518f('0x16')]();});}};}function handleEntityNotFound(_0x2ac1b9,_0x30671b){return function(_0x275974){if(!_0x275974){_0x2ac1b9[_0x518f('0x15')](0x194);}return _0x275974;};}function handleError(_0x4df7b6,_0x22724b){_0x22724b=_0x22724b||0x1f4;return function(_0x36cde8){logger[_0x518f('0x24')](_0x36cde8[_0x518f('0x25')]);if(_0x36cde8[_0x518f('0x26')]){delete _0x36cde8[_0x518f('0x26')];}_0x4df7b6[_0x518f('0x17')](_0x22724b)[_0x518f('0x27')](_0x36cde8);};}exports[_0x518f('0x28')]=function(_0x403ab3,_0x2113e1){var _0x3e20e0={},_0x324de1={},_0x2e8565={'count':0x0,'rows':[]};var _0x248f29=_[_0x518f('0x29')](db[_0x518f('0x2a')][_0x518f('0x2b')],function(_0x496bfd){return{'name':_0x496bfd[_0x518f('0x2c')],'type':_0x496bfd[_0x518f('0x2d')][_0x518f('0x2e')]};});_0x324de1['model']=_['map'](_0x248f29,_0x518f('0x26'));_0x324de1['query']=_[_0x518f('0x2f')](_0x403ab3[_0x518f('0x30')]);_0x324de1[_0x518f('0x31')]=_[_0x518f('0x32')](_0x324de1[_0x518f('0x33')],_0x324de1[_0x518f('0x30')]);_0x3e20e0[_0x518f('0x34')]=_[_0x518f('0x32')](_0x324de1[_0x518f('0x33')],qs[_0x518f('0x35')](_0x403ab3['query']['fields']));_0x3e20e0[_0x518f('0x34')]=_0x3e20e0[_0x518f('0x34')][_0x518f('0x36')]?_0x3e20e0[_0x518f('0x34')]:_0x324de1[_0x518f('0x33')];if(!_0x403ab3[_0x518f('0x30')]['hasOwnProperty'](_0x518f('0x37'))){_0x3e20e0[_0x518f('0x1b')]=qs[_0x518f('0x1b')](_0x403ab3[_0x518f('0x30')][_0x518f('0x1b')]);_0x3e20e0['offset']=qs[_0x518f('0x19')](_0x403ab3[_0x518f('0x30')][_0x518f('0x19')]);}_0x3e20e0[_0x518f('0x38')]=qs['sort'](_0x403ab3[_0x518f('0x30')]['sort']);_0x3e20e0[_0x518f('0x39')]=qs['filters'](_['pick'](_0x403ab3[_0x518f('0x30')],_0x324de1['filters']),_0x248f29);if(_0x403ab3[_0x518f('0x30')][_0x518f('0x3a')]){_0x3e20e0[_0x518f('0x39')]=_[_0x518f('0x3b')](_0x3e20e0[_0x518f('0x39')],{'$or':_['map'](_0x248f29,function(_0x228cda){if(_0x228cda['type']!==_0x518f('0x3c')){var _0xf9439d={};_0xf9439d[_0x228cda[_0x518f('0x26')]]={'$like':'%'+_0x403ab3[_0x518f('0x30')][_0x518f('0x3a')]+'%'};return _0xf9439d;}})});}_0x3e20e0=_[_0x518f('0x3b')]({},_0x3e20e0,_0x403ab3[_0x518f('0x3d')]);var _0x3b7099={'where':_0x3e20e0['where']};return db['Dynamics365Field'][_0x518f('0x1c')](_0x3b7099)['then'](function(_0xd07dcf){_0x2e8565['count']=_0xd07dcf;if(_0x403ab3[_0x518f('0x30')][_0x518f('0x3e')]){_0x3e20e0[_0x518f('0x3f')]=[{'all':!![]}];}return db[_0x518f('0x2a')]['findAll'](_0x3e20e0);})[_0x518f('0x22')](function(_0x35a04f){_0x2e8565[_0x518f('0x40')]=_0x35a04f;return _0x2e8565;})[_0x518f('0x22')](respondWithFilteredResult(_0x2113e1,_0x3e20e0))[_0x518f('0x41')](handleError(_0x2113e1,null));};exports['show']=function(_0x2abe80,_0x3228e8){var _0xbb4fb2={'raw':!![],'where':{'id':_0x2abe80[_0x518f('0x42')]['id']}},_0x5e3d9d={};_0x5e3d9d[_0x518f('0x33')]=_['keys'](db[_0x518f('0x2a')][_0x518f('0x2b')]);_0x5e3d9d['query']=_[_0x518f('0x2f')](_0x2abe80[_0x518f('0x30')]);_0x5e3d9d[_0x518f('0x31')]=_[_0x518f('0x32')](_0x5e3d9d['model'],_0x5e3d9d['query']);_0xbb4fb2[_0x518f('0x34')]=_[_0x518f('0x32')](_0x5e3d9d[_0x518f('0x33')],qs[_0x518f('0x35')](_0x2abe80[_0x518f('0x30')][_0x518f('0x35')]));_0xbb4fb2[_0x518f('0x34')]=_0xbb4fb2[_0x518f('0x34')]['length']?_0xbb4fb2[_0x518f('0x34')]:_0x5e3d9d['model'];if(_0x2abe80[_0x518f('0x30')]['includeAll']){_0xbb4fb2[_0x518f('0x3f')]=[{'all':!![]}];}_0xbb4fb2=_[_0x518f('0x3b')]({},_0xbb4fb2,_0x2abe80[_0x518f('0x3d')]);return db[_0x518f('0x2a')][_0x518f('0x43')](_0xbb4fb2)['then'](handleEntityNotFound(_0x3228e8,null))[_0x518f('0x22')](respondWithResult(_0x3228e8,null))[_0x518f('0x41')](handleError(_0x3228e8,null));};exports[_0x518f('0x44')]=function(_0x12066d,_0x2f880f){return db[_0x518f('0x2a')]['create'](_0x12066d[_0x518f('0x45')],{})['then'](respondWithResult(_0x2f880f,0xc9))[_0x518f('0x41')](handleError(_0x2f880f,null));};exports[_0x518f('0x46')]=function(_0x47dfc8,_0x2ca677){if(_0x47dfc8['body']['id']){delete _0x47dfc8['body']['id'];}return db[_0x518f('0x2a')][_0x518f('0x43')]({'where':{'id':_0x47dfc8[_0x518f('0x42')]['id']}})[_0x518f('0x22')](handleEntityNotFound(_0x2ca677,null))['then'](saveUpdates(_0x47dfc8[_0x518f('0x45')],null))[_0x518f('0x22')](respondWithResult(_0x2ca677,null))[_0x518f('0x41')](handleError(_0x2ca677,null));};exports[_0x518f('0x23')]=function(_0x53c9f1,_0x1f627c){return db[_0x518f('0x2a')][_0x518f('0x43')]({'where':{'id':_0x53c9f1[_0x518f('0x42')]['id']}})[_0x518f('0x22')](handleEntityNotFound(_0x1f627c,null))[_0x518f('0x22')](removeEntity(_0x1f627c,null))['catch'](handleError(_0x1f627c,null));};