Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / intServicenowConfiguration / intServicenowConfiguration.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 _0x6011=['end','status','json','undefined','limit','count','offset','set','apply','reject','then','destroy','error','stack','name','send','index','map','ServicenowConfiguration','rawAttributes','fieldName','type','model','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','includeAll','include','findAll','rows','params','keys','options','find','catch','create','body','getFields','findOne','ServicenowField','getSubjects','getDescriptions','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus'];(function(_0x30b5d1,_0x39826f){var _0x47faaa=function(_0x2e96b9){while(--_0x2e96b9){_0x30b5d1['push'](_0x30b5d1['shift']());}};_0x47faaa(++_0x39826f);}(_0x6011,0x120));var _0x1601=function(_0x1d14b0,_0x151f6e){_0x1d14b0=_0x1d14b0-0x0;var _0x4c831d=_0x6011[_0x1d14b0];return _0x4c831d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1601('0x0'));var zipdir=require(_0x1601('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x1601('0x2'));var moment=require('moment');var BPromise=require(_0x1601('0x3'));var Mustache=require(_0x1601('0x4'));var util=require(_0x1601('0x5'));var path=require(_0x1601('0x6'));var sox=require(_0x1601('0x7'));var csv=require(_0x1601('0x8'));var ejs=require(_0x1601('0x9'));var fs=require('fs');var fs_extra=require(_0x1601('0xa'));var _=require(_0x1601('0xb'));var squel=require('squel');var crypto=require(_0x1601('0xc'));var jsforce=require(_0x1601('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x1601('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x1601('0xf'));var qs=require(_0x1601('0x10'));var as=require(_0x1601('0x11'));var hardwareService=require(_0x1601('0x12'));var logger=require(_0x1601('0x13'))('api');var utils=require(_0x1601('0x14'));var config=require(_0x1601('0x15'));var licenseUtil=require(_0x1601('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3535dc,_0x343e52){_0x343e52=_0x343e52||0xcc;return function(_0x2cca0d){if(_0x2cca0d){return _0x3535dc[_0x1601('0x17')](_0x343e52);}return _0x3535dc['status'](_0x343e52)[_0x1601('0x18')]();};}function respondWithResult(_0x21bcd9,_0x934b35){_0x934b35=_0x934b35||0xc8;return function(_0x44068d){if(_0x44068d){return _0x21bcd9[_0x1601('0x19')](_0x934b35)[_0x1601('0x1a')](_0x44068d);}};}function respondWithFilteredResult(_0x44b75e,_0x2bdc68){return function(_0x179d66){if(_0x179d66){var _0x24f789=typeof _0x2bdc68['offset']===_0x1601('0x1b')&&typeof _0x2bdc68[_0x1601('0x1c')]==='undefined';var _0x1abca1=_0x179d66[_0x1601('0x1d')];var _0x264913=_0x24f789?0x0:_0x2bdc68[_0x1601('0x1e')];var _0x3da9aa=_0x24f789?_0x179d66['count']:_0x2bdc68['offset']+_0x2bdc68[_0x1601('0x1c')];var _0x27f685;if(_0x3da9aa>=_0x1abca1){_0x3da9aa=_0x1abca1;_0x27f685=0xc8;}else{_0x27f685=0xce;}_0x44b75e[_0x1601('0x19')](_0x27f685);return _0x44b75e[_0x1601('0x1f')]('Content-Range',_0x264913+'-'+_0x3da9aa+'/'+_0x1abca1)['json'](_0x179d66);}return null;};}function patchUpdates(_0x301c47){return function(_0x3cc8a4){try{jsonpatch[_0x1601('0x20')](_0x3cc8a4,_0x301c47,!![]);}catch(_0x2bc468){return BPromise[_0x1601('0x21')](_0x2bc468);}return _0x3cc8a4['save']();};}function saveUpdates(_0x4e7c75,_0x3a4657){return function(_0x50751f){if(_0x50751f){return _0x50751f['update'](_0x4e7c75)[_0x1601('0x22')](function(_0x491734){return _0x491734;});}return null;};}function removeEntity(_0x4d4626,_0x174088){return function(_0x221a98){if(_0x221a98){return _0x221a98[_0x1601('0x23')]()['then'](function(){_0x4d4626[_0x1601('0x19')](0xcc)[_0x1601('0x18')]();});}};}function handleEntityNotFound(_0x89f60a,_0x77f1cb){return function(_0x1e602d){if(!_0x1e602d){_0x89f60a[_0x1601('0x17')](0x194);}return _0x1e602d;};}function handleError(_0x13a7a9,_0x5841e2){_0x5841e2=_0x5841e2||0x1f4;return function(_0x118c3f){logger[_0x1601('0x24')](_0x118c3f[_0x1601('0x25')]);if(_0x118c3f[_0x1601('0x26')]){delete _0x118c3f[_0x1601('0x26')];}_0x13a7a9[_0x1601('0x19')](_0x5841e2)[_0x1601('0x27')](_0x118c3f);};}exports[_0x1601('0x28')]=function(_0x223ab3,_0x245e1a){var _0x4549c3={},_0x1cafe0={},_0x34ed6e={'count':0x0,'rows':[]};var _0x25157f=_[_0x1601('0x29')](db[_0x1601('0x2a')][_0x1601('0x2b')],function(_0x267926){return{'name':_0x267926[_0x1601('0x2c')],'type':_0x267926[_0x1601('0x2d')]['key']};});_0x1cafe0[_0x1601('0x2e')]=_['map'](_0x25157f,_0x1601('0x26'));_0x1cafe0[_0x1601('0x2f')]=_['keys'](_0x223ab3[_0x1601('0x2f')]);_0x1cafe0[_0x1601('0x30')]=_['intersection'](_0x1cafe0['model'],_0x1cafe0[_0x1601('0x2f')]);_0x4549c3[_0x1601('0x31')]=_[_0x1601('0x32')](_0x1cafe0['model'],qs['fields'](_0x223ab3[_0x1601('0x2f')][_0x1601('0x33')]));_0x4549c3['attributes']=_0x4549c3['attributes'][_0x1601('0x34')]?_0x4549c3['attributes']:_0x1cafe0[_0x1601('0x2e')];if(!_0x223ab3[_0x1601('0x2f')][_0x1601('0x35')](_0x1601('0x36'))){_0x4549c3[_0x1601('0x1c')]=qs[_0x1601('0x1c')](_0x223ab3[_0x1601('0x2f')][_0x1601('0x1c')]);_0x4549c3['offset']=qs[_0x1601('0x1e')](_0x223ab3[_0x1601('0x2f')][_0x1601('0x1e')]);}_0x4549c3[_0x1601('0x37')]=qs[_0x1601('0x38')](_0x223ab3[_0x1601('0x2f')]['sort']);_0x4549c3[_0x1601('0x39')]=qs['filters'](_[_0x1601('0x3a')](_0x223ab3['query'],_0x1cafe0['filters']),_0x25157f);if(_0x223ab3[_0x1601('0x2f')]['filter']){_0x4549c3['where']=_[_0x1601('0x3b')](_0x4549c3[_0x1601('0x39')],{'$or':_[_0x1601('0x29')](_0x25157f,function(_0x101bb3){if(_0x101bb3[_0x1601('0x2d')]!==_0x1601('0x3c')){var _0x3e8fa2={};_0x3e8fa2[_0x101bb3[_0x1601('0x26')]]={'$like':'%'+_0x223ab3['query'][_0x1601('0x3d')]+'%'};return _0x3e8fa2;}})});}_0x4549c3=_['merge']({},_0x4549c3,_0x223ab3['options']);var _0x55cd8b={'where':_0x4549c3[_0x1601('0x39')]};return db['ServicenowConfiguration'][_0x1601('0x1d')](_0x55cd8b)[_0x1601('0x22')](function(_0x4f79ad){_0x34ed6e['count']=_0x4f79ad;if(_0x223ab3[_0x1601('0x2f')][_0x1601('0x3e')]){_0x4549c3[_0x1601('0x3f')]=[{'all':!![]}];}return db[_0x1601('0x2a')][_0x1601('0x40')](_0x4549c3);})[_0x1601('0x22')](function(_0x34df59){_0x34ed6e[_0x1601('0x41')]=_0x34df59;return _0x34ed6e;})['then'](respondWithFilteredResult(_0x245e1a,_0x4549c3))['catch'](handleError(_0x245e1a,null));};exports['show']=function(_0x52bed4,_0x1e6f85){var _0x29c335={'raw':![],'where':{'id':_0x52bed4[_0x1601('0x42')]['id']}},_0xa5738c={};_0xa5738c[_0x1601('0x2e')]=_[_0x1601('0x43')](db[_0x1601('0x2a')][_0x1601('0x2b')]);_0xa5738c[_0x1601('0x2f')]=_[_0x1601('0x43')](_0x52bed4[_0x1601('0x2f')]);_0xa5738c[_0x1601('0x30')]=_['intersection'](_0xa5738c[_0x1601('0x2e')],_0xa5738c[_0x1601('0x2f')]);_0x29c335[_0x1601('0x31')]=_['intersection'](_0xa5738c[_0x1601('0x2e')],qs[_0x1601('0x33')](_0x52bed4[_0x1601('0x2f')][_0x1601('0x33')]));_0x29c335[_0x1601('0x31')]=_0x29c335[_0x1601('0x31')][_0x1601('0x34')]?_0x29c335['attributes']:_0xa5738c[_0x1601('0x2e')];if(_0x52bed4[_0x1601('0x2f')][_0x1601('0x3e')]){_0x29c335[_0x1601('0x3f')]=[{'all':!![]}];}_0x29c335=_[_0x1601('0x3b')]({},_0x29c335,_0x52bed4[_0x1601('0x44')]);return db['ServicenowConfiguration'][_0x1601('0x45')](_0x29c335)[_0x1601('0x22')](handleEntityNotFound(_0x1e6f85,null))[_0x1601('0x22')](respondWithResult(_0x1e6f85,null))[_0x1601('0x46')](handleError(_0x1e6f85,null));};exports[_0x1601('0x47')]=function(_0x5e0c0a,_0x293217){return db[_0x1601('0x2a')][_0x1601('0x47')](_0x5e0c0a[_0x1601('0x48')],{})[_0x1601('0x22')](respondWithResult(_0x293217,0xc9))['catch'](handleError(_0x293217,null));};exports['update']=function(_0x55e4e9,_0x5e9eec){if(_0x55e4e9['body']['id']){delete _0x55e4e9[_0x1601('0x48')]['id'];}return db['ServicenowConfiguration'][_0x1601('0x45')]({'where':{'id':_0x55e4e9[_0x1601('0x42')]['id']}})[_0x1601('0x22')](handleEntityNotFound(_0x5e9eec,null))['then'](saveUpdates(_0x55e4e9[_0x1601('0x48')],null))[_0x1601('0x22')](respondWithResult(_0x5e9eec,null))[_0x1601('0x46')](handleError(_0x5e9eec,null));};exports[_0x1601('0x23')]=function(_0x539770,_0x3db33b){return db[_0x1601('0x2a')][_0x1601('0x45')]({'where':{'id':_0x539770[_0x1601('0x42')]['id']}})[_0x1601('0x22')](handleEntityNotFound(_0x3db33b,null))[_0x1601('0x22')](removeEntity(_0x3db33b,null))[_0x1601('0x46')](handleError(_0x3db33b,null));};exports[_0x1601('0x49')]=function(_0x30871b,_0xf77dba,_0x2a3752){var _0x4bae86={};var _0x1cb55d={};var _0x8c82b1;var _0x440cce;return db[_0x1601('0x2a')][_0x1601('0x4a')]({'where':{'id':_0x30871b[_0x1601('0x42')]['id']}})[_0x1601('0x22')](handleEntityNotFound(_0xf77dba,null))[_0x1601('0x22')](function(_0x271c9d){if(_0x271c9d){_0x8c82b1=_0x271c9d;_0x1cb55d[_0x1601('0x2e')]=_[_0x1601('0x43')](db[_0x1601('0x4b')][_0x1601('0x2b')]);_0x1cb55d[_0x1601('0x2f')]=_[_0x1601('0x43')](_0x30871b[_0x1601('0x2f')]);_0x1cb55d[_0x1601('0x30')]=_[_0x1601('0x32')](_0x1cb55d['model'],_0x1cb55d[_0x1601('0x2f')]);_0x4bae86[_0x1601('0x31')]=_[_0x1601('0x32')](_0x1cb55d[_0x1601('0x2e')],qs[_0x1601('0x33')](_0x30871b[_0x1601('0x2f')][_0x1601('0x33')]));_0x4bae86[_0x1601('0x31')]=_0x4bae86[_0x1601('0x31')][_0x1601('0x34')]?_0x4bae86['attributes']:_0x1cb55d[_0x1601('0x2e')];_0x4bae86[_0x1601('0x37')]=qs[_0x1601('0x38')](_0x30871b['query'][_0x1601('0x38')]);_0x4bae86[_0x1601('0x39')]=qs[_0x1601('0x30')](_[_0x1601('0x3a')](_0x30871b[_0x1601('0x2f')],_0x1cb55d[_0x1601('0x30')]));if(_0x30871b[_0x1601('0x2f')][_0x1601('0x3d')]){_0x4bae86[_0x1601('0x39')]=_['merge'](_0x4bae86['where'],{'$or':_[_0x1601('0x29')](_0x4bae86['attributes'],function(_0x1ef12e){var _0x41fcf7={};_0x41fcf7[_0x1ef12e]={'$like':'%'+_0x30871b[_0x1601('0x2f')]['filter']+'%'};return _0x41fcf7;})});}_0x4bae86=_[_0x1601('0x3b')]({},_0x4bae86,_0x30871b[_0x1601('0x44')]);return _0x8c82b1['getFields'](_0x4bae86);}})['then'](function(_0x8b73d9){if(_0x8b73d9){_0x440cce=_0x8b73d9[_0x1601('0x34')];if(!_0x30871b[_0x1601('0x2f')][_0x1601('0x35')](_0x1601('0x36'))){_0x4bae86[_0x1601('0x1c')]=qs[_0x1601('0x1c')](_0x30871b['query'][_0x1601('0x1c')]);_0x4bae86[_0x1601('0x1e')]=qs[_0x1601('0x1e')](_0x30871b[_0x1601('0x2f')][_0x1601('0x1e')]);}return _0x8c82b1[_0x1601('0x49')](_0x4bae86);}})[_0x1601('0x22')](function(_0x453264){if(_0x453264){return _0x453264?{'count':_0x440cce,'rows':_0x453264}:null;}})[_0x1601('0x22')](respondWithResult(_0xf77dba,null))['catch'](handleError(_0xf77dba,null));};exports[_0x1601('0x4c')]=function(_0x333450,_0x58301b,_0x14dbf3){var _0x21539f={};var _0x5e5b34={};var _0x1b6a88;var _0x2d09e7;return db[_0x1601('0x2a')][_0x1601('0x4a')]({'where':{'id':_0x333450[_0x1601('0x42')]['id']}})[_0x1601('0x22')](handleEntityNotFound(_0x58301b,null))[_0x1601('0x22')](function(_0x8d1979){if(_0x8d1979){_0x1b6a88=_0x8d1979;_0x5e5b34['model']=_[_0x1601('0x43')](db[_0x1601('0x4b')][_0x1601('0x2b')]);_0x5e5b34[_0x1601('0x2f')]=_[_0x1601('0x43')](_0x333450['query']);_0x5e5b34['filters']=_[_0x1601('0x32')](_0x5e5b34[_0x1601('0x2e')],_0x5e5b34['query']);_0x21539f[_0x1601('0x31')]=_[_0x1601('0x32')](_0x5e5b34[_0x1601('0x2e')],qs[_0x1601('0x33')](_0x333450[_0x1601('0x2f')][_0x1601('0x33')]));_0x21539f[_0x1601('0x31')]=_0x21539f['attributes'][_0x1601('0x34')]?_0x21539f[_0x1601('0x31')]:_0x5e5b34[_0x1601('0x2e')];_0x21539f[_0x1601('0x37')]=qs[_0x1601('0x38')](_0x333450[_0x1601('0x2f')][_0x1601('0x38')]);_0x21539f[_0x1601('0x39')]=qs[_0x1601('0x30')](_[_0x1601('0x3a')](_0x333450[_0x1601('0x2f')],_0x5e5b34[_0x1601('0x30')]));if(_0x333450['query']['filter']){_0x21539f[_0x1601('0x39')]=_['merge'](_0x21539f[_0x1601('0x39')],{'$or':_[_0x1601('0x29')](_0x21539f[_0x1601('0x31')],function(_0x2dd53d){var _0x5d0d91={};_0x5d0d91[_0x2dd53d]={'$like':'%'+_0x333450[_0x1601('0x2f')][_0x1601('0x3d')]+'%'};return _0x5d0d91;})});}_0x21539f=_[_0x1601('0x3b')]({},_0x21539f,_0x333450['options']);return _0x1b6a88[_0x1601('0x4c')](_0x21539f);}})[_0x1601('0x22')](function(_0x1d883c){if(_0x1d883c){_0x2d09e7=_0x1d883c[_0x1601('0x34')];if(!_0x333450[_0x1601('0x2f')][_0x1601('0x35')](_0x1601('0x36'))){_0x21539f[_0x1601('0x1c')]=qs[_0x1601('0x1c')](_0x333450[_0x1601('0x2f')][_0x1601('0x1c')]);_0x21539f['offset']=qs[_0x1601('0x1e')](_0x333450[_0x1601('0x2f')][_0x1601('0x1e')]);}return _0x1b6a88['getSubjects'](_0x21539f);}})[_0x1601('0x22')](function(_0x39bf7b){if(_0x39bf7b){return _0x39bf7b?{'count':_0x2d09e7,'rows':_0x39bf7b}:null;}})[_0x1601('0x22')](respondWithResult(_0x58301b,null))[_0x1601('0x46')](handleError(_0x58301b,null));};exports[_0x1601('0x4d')]=function(_0xe2aa70,_0x267948,_0x8475e2){var _0x1b24be={};var _0x3bafb4={};var _0x8940b0;var _0xb842f2;return db[_0x1601('0x2a')][_0x1601('0x4a')]({'where':{'id':_0xe2aa70[_0x1601('0x42')]['id']}})[_0x1601('0x22')](handleEntityNotFound(_0x267948,null))[_0x1601('0x22')](function(_0x19c9bd){if(_0x19c9bd){_0x8940b0=_0x19c9bd;_0x3bafb4['model']=_[_0x1601('0x43')](db[_0x1601('0x4b')][_0x1601('0x2b')]);_0x3bafb4[_0x1601('0x2f')]=_[_0x1601('0x43')](_0xe2aa70[_0x1601('0x2f')]);_0x3bafb4[_0x1601('0x30')]=_['intersection'](_0x3bafb4[_0x1601('0x2e')],_0x3bafb4[_0x1601('0x2f')]);_0x1b24be[_0x1601('0x31')]=_['intersection'](_0x3bafb4[_0x1601('0x2e')],qs['fields'](_0xe2aa70['query'][_0x1601('0x33')]));_0x1b24be['attributes']=_0x1b24be[_0x1601('0x31')][_0x1601('0x34')]?_0x1b24be['attributes']:_0x3bafb4[_0x1601('0x2e')];_0x1b24be[_0x1601('0x37')]=qs[_0x1601('0x38')](_0xe2aa70['query'][_0x1601('0x38')]);_0x1b24be[_0x1601('0x39')]=qs['filters'](_[_0x1601('0x3a')](_0xe2aa70[_0x1601('0x2f')],_0x3bafb4[_0x1601('0x30')]));if(_0xe2aa70[_0x1601('0x2f')][_0x1601('0x3d')]){_0x1b24be[_0x1601('0x39')]=_['merge'](_0x1b24be[_0x1601('0x39')],{'$or':_['map'](_0x1b24be[_0x1601('0x31')],function(_0x56a3e2){var _0x2d3b3b={};_0x2d3b3b[_0x56a3e2]={'$like':'%'+_0xe2aa70[_0x1601('0x2f')][_0x1601('0x3d')]+'%'};return _0x2d3b3b;})});}_0x1b24be=_[_0x1601('0x3b')]({},_0x1b24be,_0xe2aa70[_0x1601('0x44')]);return _0x8940b0[_0x1601('0x4d')](_0x1b24be);}})[_0x1601('0x22')](function(_0x3ad7cb){if(_0x3ad7cb){_0xb842f2=_0x3ad7cb[_0x1601('0x34')];if(!_0xe2aa70['query'][_0x1601('0x35')]('nolimit')){_0x1b24be['limit']=qs[_0x1601('0x1c')](_0xe2aa70[_0x1601('0x2f')]['limit']);_0x1b24be['offset']=qs[_0x1601('0x1e')](_0xe2aa70[_0x1601('0x2f')][_0x1601('0x1e')]);}return _0x8940b0['getDescriptions'](_0x1b24be);}})[_0x1601('0x22')](function(_0x11c450){if(_0x11c450){return _0x11c450?{'count':_0xb842f2,'rows':_0x11c450}:null;}})[_0x1601('0x22')](respondWithResult(_0x267948,null))[_0x1601('0x46')](handleError(_0x267948,null));};