Built motion from commit (unavailable).|2.5.20
[motion2.git] / server / api / intServicenowField / intServicenowField.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 _0xaf6e=['ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','map','ServicenowField','rawAttributes','fieldName','type','key','query','model','attributes','fields','hasOwnProperty','order','sort','where','filters','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','keys','intersection','length','create','body','find','params','destroy','html-pdf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','crypto','desk.js','querystring','papaparse'];(function(_0x1bb812,_0x23eacc){var _0x372adb=function(_0x5ad456){while(--_0x5ad456){_0x1bb812['push'](_0x1bb812['shift']());}};_0x372adb(++_0x23eacc);}(_0xaf6e,0x16e));var _0xeaf6=function(_0x5a68b7,_0x53b4c2){_0x5a68b7=_0x5a68b7-0x0;var _0x4ec30d=_0xaf6e[_0x5a68b7];return _0x4ec30d;};'use strict';var pdf=require(_0xeaf6('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xeaf6('0x1'));var jsonpatch=require(_0xeaf6('0x2'));var rp=require(_0xeaf6('0x3'));var moment=require(_0xeaf6('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xeaf6('0x5'));var util=require(_0xeaf6('0x6'));var path=require(_0xeaf6('0x7'));var sox=require(_0xeaf6('0x8'));var csv=require(_0xeaf6('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xeaf6('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xeaf6('0xb'));var toCsv=require('to-csv');var querystring=require(_0xeaf6('0xc'));var Papa=require(_0xeaf6('0xd'));var Redis=require(_0xeaf6('0xe'));var authService=require(_0xeaf6('0xf'));var qs=require(_0xeaf6('0x10'));var as=require(_0xeaf6('0x11'));var hardwareService=require(_0xeaf6('0x12'));var logger=require(_0xeaf6('0x13'))(_0xeaf6('0x14'));var utils=require(_0xeaf6('0x15'));var config=require(_0xeaf6('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xeaf6('0x17'))['db'];function respondWithStatusCode(_0x4116f9,_0x1ba525){_0x1ba525=_0x1ba525||0xcc;return function(_0x1c550b){if(_0x1c550b){return _0x4116f9[_0xeaf6('0x18')](_0x1ba525);}return _0x4116f9[_0xeaf6('0x19')](_0x1ba525)[_0xeaf6('0x1a')]();};}function respondWithResult(_0x182394,_0x5ed8ce){_0x5ed8ce=_0x5ed8ce||0xc8;return function(_0x4a7e50){if(_0x4a7e50){return _0x182394[_0xeaf6('0x19')](_0x5ed8ce)[_0xeaf6('0x1b')](_0x4a7e50);}};}function respondWithFilteredResult(_0x23a6d6,_0x46418d){return function(_0xd862fb){if(_0xd862fb){var _0x49c1c5=_0xd862fb[_0xeaf6('0x1c')],_0x1437f9=_0x46418d[_0xeaf6('0x1d')],_0x112920=_0x46418d[_0xeaf6('0x1d')]+_0x46418d[_0xeaf6('0x1e')],_0x382059;if(_0x112920>=_0x49c1c5){_0x112920=_0x49c1c5;_0x382059=0xc8;}else{_0x382059=0xce;}_0x23a6d6['status'](_0x382059);return _0x23a6d6[_0xeaf6('0x1f')](_0xeaf6('0x20'),_0x1437f9+'-'+_0x112920+'/'+_0x49c1c5)[_0xeaf6('0x1b')](_0xd862fb);}return null;};}function patchUpdates(_0x4eb58c){return function(_0x54d4f5){try{jsonpatch[_0xeaf6('0x21')](_0x54d4f5,_0x4eb58c,!![]);}catch(_0x459304){return BPromise[_0xeaf6('0x22')](_0x459304);}return _0x54d4f5[_0xeaf6('0x23')]();};}function saveUpdates(_0x3f9b76,_0x28bfde){return function(_0x2258f3){if(_0x2258f3){return _0x2258f3[_0xeaf6('0x24')](_0x3f9b76)[_0xeaf6('0x25')](function(_0x3b6fe5){return _0x3b6fe5;});}return null;};}function removeEntity(_0x22c4a5,_0x39fb66){return function(_0x4756ee){if(_0x4756ee){return _0x4756ee['destroy']()['then'](function(){_0x22c4a5['status'](0xcc)[_0xeaf6('0x1a')]();});}};}function handleEntityNotFound(_0x114f45,_0x14b82d){return function(_0x38ba28){if(!_0x38ba28){_0x114f45[_0xeaf6('0x18')](0x194);}return _0x38ba28;};}function handleError(_0x5763a7,_0x48ec65){_0x48ec65=_0x48ec65||0x1f4;return function(_0x2983b1){logger[_0xeaf6('0x26')](_0x2983b1[_0xeaf6('0x27')]);if(_0x2983b1[_0xeaf6('0x28')]){delete _0x2983b1['name'];}_0x5763a7[_0xeaf6('0x19')](_0x48ec65)[_0xeaf6('0x29')](_0x2983b1);};}exports['index']=function(_0xa202a2,_0x42c63a){var _0x313ba3={},_0x1d55d1={},_0x237878={'count':0x0,'rows':[]};var _0x18a52b=_[_0xeaf6('0x2a')](db[_0xeaf6('0x2b')][_0xeaf6('0x2c')],function(_0x1cc040){return{'name':_0x1cc040[_0xeaf6('0x2d')],'type':_0x1cc040[_0xeaf6('0x2e')][_0xeaf6('0x2f')]};});_0x1d55d1['model']=_[_0xeaf6('0x2a')](_0x18a52b,'name');_0x1d55d1[_0xeaf6('0x30')]=_['keys'](_0xa202a2[_0xeaf6('0x30')]);_0x1d55d1['filters']=_['intersection'](_0x1d55d1[_0xeaf6('0x31')],_0x1d55d1[_0xeaf6('0x30')]);_0x313ba3[_0xeaf6('0x32')]=_['intersection'](_0x1d55d1['model'],qs['fields'](_0xa202a2[_0xeaf6('0x30')][_0xeaf6('0x33')]));_0x313ba3[_0xeaf6('0x32')]=_0x313ba3[_0xeaf6('0x32')]['length']?_0x313ba3[_0xeaf6('0x32')]:_0x1d55d1[_0xeaf6('0x31')];if(!_0xa202a2[_0xeaf6('0x30')][_0xeaf6('0x34')]('nolimit')){_0x313ba3['limit']=qs['limit'](_0xa202a2[_0xeaf6('0x30')][_0xeaf6('0x1e')]);_0x313ba3[_0xeaf6('0x1d')]=qs[_0xeaf6('0x1d')](_0xa202a2['query'][_0xeaf6('0x1d')]);}_0x313ba3[_0xeaf6('0x35')]=qs[_0xeaf6('0x36')](_0xa202a2['query'][_0xeaf6('0x36')]);_0x313ba3[_0xeaf6('0x37')]=qs[_0xeaf6('0x38')](_[_0xeaf6('0x39')](_0xa202a2[_0xeaf6('0x30')],_0x1d55d1[_0xeaf6('0x38')]),_0x18a52b);if(_0xa202a2[_0xeaf6('0x30')][_0xeaf6('0x3a')]){_0x313ba3[_0xeaf6('0x37')]=_['merge'](_0x313ba3[_0xeaf6('0x37')],{'$or':_['map'](_0x18a52b,function(_0x17ffbc){if(_0x17ffbc['type']!==_0xeaf6('0x3b')){var _0x2d3f2f={};_0x2d3f2f[_0x17ffbc[_0xeaf6('0x28')]]={'$like':'%'+_0xa202a2['query'][_0xeaf6('0x3a')]+'%'};return _0x2d3f2f;}})});}_0x313ba3=_[_0xeaf6('0x3c')]({},_0x313ba3,_0xa202a2[_0xeaf6('0x3d')]);var _0x1a31ea={'where':_0x313ba3[_0xeaf6('0x37')]};return db[_0xeaf6('0x2b')][_0xeaf6('0x1c')](_0x1a31ea)[_0xeaf6('0x25')](function(_0x89a713){_0x237878[_0xeaf6('0x1c')]=_0x89a713;if(_0xa202a2['query'][_0xeaf6('0x3e')]){_0x313ba3[_0xeaf6('0x3f')]=[{'all':!![]}];}return db[_0xeaf6('0x2b')][_0xeaf6('0x40')](_0x313ba3);})[_0xeaf6('0x25')](function(_0x5a5eb3){_0x237878[_0xeaf6('0x41')]=_0x5a5eb3;return _0x237878;})['then'](respondWithFilteredResult(_0x42c63a,_0x313ba3))[_0xeaf6('0x42')](handleError(_0x42c63a,null));};exports[_0xeaf6('0x43')]=function(_0x5905e8,_0x21a618){var _0x416818={'raw':!![],'where':{'id':_0x5905e8['params']['id']}},_0x4d7050={};_0x4d7050[_0xeaf6('0x31')]=_[_0xeaf6('0x44')](db[_0xeaf6('0x2b')][_0xeaf6('0x2c')]);_0x4d7050[_0xeaf6('0x30')]=_[_0xeaf6('0x44')](_0x5905e8['query']);_0x4d7050['filters']=_[_0xeaf6('0x45')](_0x4d7050['model'],_0x4d7050['query']);_0x416818[_0xeaf6('0x32')]=_['intersection'](_0x4d7050[_0xeaf6('0x31')],qs[_0xeaf6('0x33')](_0x5905e8[_0xeaf6('0x30')][_0xeaf6('0x33')]));_0x416818[_0xeaf6('0x32')]=_0x416818[_0xeaf6('0x32')][_0xeaf6('0x46')]?_0x416818['attributes']:_0x4d7050[_0xeaf6('0x31')];if(_0x5905e8[_0xeaf6('0x30')][_0xeaf6('0x3e')]){_0x416818[_0xeaf6('0x3f')]=[{'all':!![]}];}_0x416818=_[_0xeaf6('0x3c')]({},_0x416818,_0x5905e8[_0xeaf6('0x3d')]);return db[_0xeaf6('0x2b')]['find'](_0x416818)[_0xeaf6('0x25')](handleEntityNotFound(_0x21a618,null))[_0xeaf6('0x25')](respondWithResult(_0x21a618,null))[_0xeaf6('0x42')](handleError(_0x21a618,null));};exports[_0xeaf6('0x47')]=function(_0x17c1b1,_0x1466af){return db[_0xeaf6('0x2b')]['create'](_0x17c1b1[_0xeaf6('0x48')],{})[_0xeaf6('0x25')](respondWithResult(_0x1466af,0xc9))[_0xeaf6('0x42')](handleError(_0x1466af,null));};exports[_0xeaf6('0x24')]=function(_0x278dee,_0x378cbc){if(_0x278dee[_0xeaf6('0x48')]['id']){delete _0x278dee[_0xeaf6('0x48')]['id'];}return db[_0xeaf6('0x2b')][_0xeaf6('0x49')]({'where':{'id':_0x278dee[_0xeaf6('0x4a')]['id']}})['then'](handleEntityNotFound(_0x378cbc,null))['then'](saveUpdates(_0x278dee[_0xeaf6('0x48')],null))[_0xeaf6('0x25')](respondWithResult(_0x378cbc,null))[_0xeaf6('0x42')](handleError(_0x378cbc,null));};exports[_0xeaf6('0x4b')]=function(_0x38805a,_0x45ad9d){return db[_0xeaf6('0x2b')][_0xeaf6('0x49')]({'where':{'id':_0x38805a[_0xeaf6('0x4a')]['id']}})[_0xeaf6('0x25')](handleEntityNotFound(_0x45ad9d,null))[_0xeaf6('0x25')](removeEntity(_0x45ad9d,null))[_0xeaf6('0x42')](handleError(_0x45ad9d,null));};