Built motion from commit ddca4d0d.|2.5.47
[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 _0x00f2=['include','findAll','rows','show','params','find','catch','create','body','getFields','findOne','ServicenowField','order','pick','filter','getSubjects','getDescriptions','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','then','destroy','stack','name','send','index','map','ServicenowConfiguration','rawAttributes','fieldName','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','merge','VIRTUAL','options','includeAll'];(function(_0x35fd47,_0x1e6e9b){var _0x7b52c2=function(_0x325c67){while(--_0x325c67){_0x35fd47['push'](_0x35fd47['shift']());}};_0x7b52c2(++_0x1e6e9b);}(_0x00f2,0xb1));var _0x200f=function(_0x171dc5,_0x254b48){_0x171dc5=_0x171dc5-0x0;var _0x512efc=_0x00f2[_0x171dc5];return _0x512efc;};'use strict';var emlformat=require(_0x200f('0x0'));var rimraf=require(_0x200f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x200f('0x2'));var rp=require(_0x200f('0x3'));var moment=require(_0x200f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x200f('0x5'));var util=require('util');var path=require(_0x200f('0x6'));var sox=require(_0x200f('0x7'));var csv=require(_0x200f('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x200f('0x9'));var _=require(_0x200f('0xa'));var squel=require('squel');var crypto=require(_0x200f('0xb'));var jsforce=require(_0x200f('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x200f('0x8'));var querystring=require(_0x200f('0xd'));var Papa=require(_0x200f('0xe'));var Redis=require('ioredis');var authService=require(_0x200f('0xf'));var qs=require(_0x200f('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x200f('0x11'));var logger=require(_0x200f('0x12'))(_0x200f('0x13'));var utils=require(_0x200f('0x14'));var config=require(_0x200f('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x200f('0x16'))['db'];function respondWithStatusCode(_0x582a10,_0x600b0f){_0x600b0f=_0x600b0f||0xcc;return function(_0x52010d){if(_0x52010d){return _0x582a10[_0x200f('0x17')](_0x600b0f);}return _0x582a10[_0x200f('0x18')](_0x600b0f)['end']();};}function respondWithResult(_0x395847,_0x8f3889){_0x8f3889=_0x8f3889||0xc8;return function(_0x5d5e7a){if(_0x5d5e7a){return _0x395847[_0x200f('0x18')](_0x8f3889)[_0x200f('0x19')](_0x5d5e7a);}};}function respondWithFilteredResult(_0x2c6f9d,_0x3dc147){return function(_0x3772bb){if(_0x3772bb){var _0x460f39=typeof _0x3dc147[_0x200f('0x1a')]===_0x200f('0x1b')&&typeof _0x3dc147[_0x200f('0x1c')]===_0x200f('0x1b');var _0x8dc336=_0x3772bb[_0x200f('0x1d')];var _0x4ce355=_0x460f39?0x0:_0x3dc147[_0x200f('0x1a')];var _0x16a112=_0x460f39?_0x3772bb[_0x200f('0x1d')]:_0x3dc147[_0x200f('0x1a')]+_0x3dc147['limit'];var _0x105ace;if(_0x16a112>=_0x8dc336){_0x16a112=_0x8dc336;_0x105ace=0xc8;}else{_0x105ace=0xce;}_0x2c6f9d[_0x200f('0x18')](_0x105ace);return _0x2c6f9d[_0x200f('0x1e')](_0x200f('0x1f'),_0x4ce355+'-'+_0x16a112+'/'+_0x8dc336)[_0x200f('0x19')](_0x3772bb);}return null;};}function patchUpdates(_0x257631){return function(_0x104441){try{jsonpatch[_0x200f('0x20')](_0x104441,_0x257631,!![]);}catch(_0x506405){return BPromise['reject'](_0x506405);}return _0x104441[_0x200f('0x21')]();};}function saveUpdates(_0x29427a,_0x3f0644){return function(_0x3cbf43){if(_0x3cbf43){return _0x3cbf43[_0x200f('0x22')](_0x29427a)[_0x200f('0x23')](function(_0xed552b){return _0xed552b;});}return null;};}function removeEntity(_0x20b4b7,_0x72e85f){return function(_0x435141){if(_0x435141){return _0x435141[_0x200f('0x24')]()[_0x200f('0x23')](function(){_0x20b4b7[_0x200f('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x11b770,_0x433f54){return function(_0x1017f0){if(!_0x1017f0){_0x11b770[_0x200f('0x17')](0x194);}return _0x1017f0;};}function handleError(_0x488a30,_0x5d07ef){_0x5d07ef=_0x5d07ef||0x1f4;return function(_0x8660b2){logger['error'](_0x8660b2[_0x200f('0x25')]);if(_0x8660b2['name']){delete _0x8660b2[_0x200f('0x26')];}_0x488a30[_0x200f('0x18')](_0x5d07ef)[_0x200f('0x27')](_0x8660b2);};}exports[_0x200f('0x28')]=function(_0x242f6b,_0x572b8a){var _0xce3902={},_0x55d556={},_0x104d42={'count':0x0,'rows':[]};var _0x110620=_[_0x200f('0x29')](db[_0x200f('0x2a')][_0x200f('0x2b')],function(_0x5ec8f6){return{'name':_0x5ec8f6[_0x200f('0x2c')],'type':_0x5ec8f6[_0x200f('0x2d')][_0x200f('0x2e')]};});_0x55d556[_0x200f('0x2f')]=_[_0x200f('0x29')](_0x110620,_0x200f('0x26'));_0x55d556['query']=_[_0x200f('0x30')](_0x242f6b[_0x200f('0x31')]);_0x55d556[_0x200f('0x32')]=_['intersection'](_0x55d556[_0x200f('0x2f')],_0x55d556['query']);_0xce3902[_0x200f('0x33')]=_[_0x200f('0x34')](_0x55d556[_0x200f('0x2f')],qs[_0x200f('0x35')](_0x242f6b['query'][_0x200f('0x35')]));_0xce3902['attributes']=_0xce3902[_0x200f('0x33')][_0x200f('0x36')]?_0xce3902['attributes']:_0x55d556['model'];if(!_0x242f6b[_0x200f('0x31')][_0x200f('0x37')](_0x200f('0x38'))){_0xce3902['limit']=qs['limit'](_0x242f6b[_0x200f('0x31')][_0x200f('0x1c')]);_0xce3902[_0x200f('0x1a')]=qs[_0x200f('0x1a')](_0x242f6b[_0x200f('0x31')][_0x200f('0x1a')]);}_0xce3902['order']=qs[_0x200f('0x39')](_0x242f6b[_0x200f('0x31')]['sort']);_0xce3902[_0x200f('0x3a')]=qs[_0x200f('0x32')](_['pick'](_0x242f6b[_0x200f('0x31')],_0x55d556[_0x200f('0x32')]),_0x110620);if(_0x242f6b[_0x200f('0x31')]['filter']){_0xce3902[_0x200f('0x3a')]=_[_0x200f('0x3b')](_0xce3902[_0x200f('0x3a')],{'$or':_[_0x200f('0x29')](_0x110620,function(_0x33bd96){if(_0x33bd96['type']!==_0x200f('0x3c')){var _0x31c1e3={};_0x31c1e3[_0x33bd96['name']]={'$like':'%'+_0x242f6b[_0x200f('0x31')]['filter']+'%'};return _0x31c1e3;}})});}_0xce3902=_[_0x200f('0x3b')]({},_0xce3902,_0x242f6b[_0x200f('0x3d')]);var _0x5cab62={'where':_0xce3902['where']};return db[_0x200f('0x2a')][_0x200f('0x1d')](_0x5cab62)[_0x200f('0x23')](function(_0x15be8a){_0x104d42['count']=_0x15be8a;if(_0x242f6b['query'][_0x200f('0x3e')]){_0xce3902[_0x200f('0x3f')]=[{'all':!![]}];}return db[_0x200f('0x2a')][_0x200f('0x40')](_0xce3902);})[_0x200f('0x23')](function(_0x43f977){_0x104d42[_0x200f('0x41')]=_0x43f977;return _0x104d42;})[_0x200f('0x23')](respondWithFilteredResult(_0x572b8a,_0xce3902))['catch'](handleError(_0x572b8a,null));};exports[_0x200f('0x42')]=function(_0x3874e9,_0x2c652c){var _0x9043ca={'raw':![],'where':{'id':_0x3874e9[_0x200f('0x43')]['id']}},_0x1963e3={};_0x1963e3[_0x200f('0x2f')]=_[_0x200f('0x30')](db[_0x200f('0x2a')][_0x200f('0x2b')]);_0x1963e3['query']=_[_0x200f('0x30')](_0x3874e9[_0x200f('0x31')]);_0x1963e3[_0x200f('0x32')]=_['intersection'](_0x1963e3[_0x200f('0x2f')],_0x1963e3[_0x200f('0x31')]);_0x9043ca['attributes']=_[_0x200f('0x34')](_0x1963e3[_0x200f('0x2f')],qs[_0x200f('0x35')](_0x3874e9[_0x200f('0x31')][_0x200f('0x35')]));_0x9043ca[_0x200f('0x33')]=_0x9043ca[_0x200f('0x33')][_0x200f('0x36')]?_0x9043ca[_0x200f('0x33')]:_0x1963e3[_0x200f('0x2f')];if(_0x3874e9[_0x200f('0x31')][_0x200f('0x3e')]){_0x9043ca[_0x200f('0x3f')]=[{'all':!![]}];}_0x9043ca=_[_0x200f('0x3b')]({},_0x9043ca,_0x3874e9[_0x200f('0x3d')]);return db[_0x200f('0x2a')][_0x200f('0x44')](_0x9043ca)[_0x200f('0x23')](handleEntityNotFound(_0x2c652c,null))['then'](respondWithResult(_0x2c652c,null))[_0x200f('0x45')](handleError(_0x2c652c,null));};exports[_0x200f('0x46')]=function(_0x2d2e98,_0x40efb9){return db[_0x200f('0x2a')]['create'](_0x2d2e98[_0x200f('0x47')],{})['then'](respondWithResult(_0x40efb9,0xc9))['catch'](handleError(_0x40efb9,null));};exports[_0x200f('0x22')]=function(_0x519d10,_0x4eeba5){if(_0x519d10[_0x200f('0x47')]['id']){delete _0x519d10[_0x200f('0x47')]['id'];}return db['ServicenowConfiguration'][_0x200f('0x44')]({'where':{'id':_0x519d10[_0x200f('0x43')]['id']}})[_0x200f('0x23')](handleEntityNotFound(_0x4eeba5,null))[_0x200f('0x23')](saveUpdates(_0x519d10[_0x200f('0x47')],null))[_0x200f('0x23')](respondWithResult(_0x4eeba5,null))['catch'](handleError(_0x4eeba5,null));};exports[_0x200f('0x24')]=function(_0x285981,_0x1496e2){return db[_0x200f('0x2a')][_0x200f('0x44')]({'where':{'id':_0x285981[_0x200f('0x43')]['id']}})[_0x200f('0x23')](handleEntityNotFound(_0x1496e2,null))['then'](removeEntity(_0x1496e2,null))['catch'](handleError(_0x1496e2,null));};exports[_0x200f('0x48')]=function(_0x2f05f0,_0x1b5de7,_0x34f880){var _0x3ebc82={};var _0x4d3a64={};var _0x30207c;var _0x17d391;return db['ServicenowConfiguration'][_0x200f('0x49')]({'where':{'id':_0x2f05f0[_0x200f('0x43')]['id']}})['then'](handleEntityNotFound(_0x1b5de7,null))[_0x200f('0x23')](function(_0x5c0f4a){if(_0x5c0f4a){_0x30207c=_0x5c0f4a;_0x4d3a64[_0x200f('0x2f')]=_['keys'](db[_0x200f('0x4a')]['rawAttributes']);_0x4d3a64[_0x200f('0x31')]=_['keys'](_0x2f05f0['query']);_0x4d3a64['filters']=_[_0x200f('0x34')](_0x4d3a64[_0x200f('0x2f')],_0x4d3a64['query']);_0x3ebc82['attributes']=_[_0x200f('0x34')](_0x4d3a64['model'],qs['fields'](_0x2f05f0[_0x200f('0x31')][_0x200f('0x35')]));_0x3ebc82[_0x200f('0x33')]=_0x3ebc82['attributes']['length']?_0x3ebc82[_0x200f('0x33')]:_0x4d3a64['model'];_0x3ebc82[_0x200f('0x4b')]=qs[_0x200f('0x39')](_0x2f05f0['query']['sort']);_0x3ebc82[_0x200f('0x3a')]=qs[_0x200f('0x32')](_[_0x200f('0x4c')](_0x2f05f0['query'],_0x4d3a64['filters']));if(_0x2f05f0[_0x200f('0x31')]['filter']){_0x3ebc82['where']=_[_0x200f('0x3b')](_0x3ebc82[_0x200f('0x3a')],{'$or':_[_0x200f('0x29')](_0x3ebc82['attributes'],function(_0xb66acd){var _0xdf1824={};_0xdf1824[_0xb66acd]={'$like':'%'+_0x2f05f0[_0x200f('0x31')][_0x200f('0x4d')]+'%'};return _0xdf1824;})});}_0x3ebc82=_[_0x200f('0x3b')]({},_0x3ebc82,_0x2f05f0[_0x200f('0x3d')]);return _0x30207c[_0x200f('0x48')](_0x3ebc82);}})[_0x200f('0x23')](function(_0x435a5c){if(_0x435a5c){_0x17d391=_0x435a5c[_0x200f('0x36')];if(!_0x2f05f0[_0x200f('0x31')][_0x200f('0x37')](_0x200f('0x38'))){_0x3ebc82['limit']=qs[_0x200f('0x1c')](_0x2f05f0[_0x200f('0x31')]['limit']);_0x3ebc82[_0x200f('0x1a')]=qs[_0x200f('0x1a')](_0x2f05f0[_0x200f('0x31')][_0x200f('0x1a')]);}return _0x30207c[_0x200f('0x48')](_0x3ebc82);}})[_0x200f('0x23')](function(_0x35cd25){if(_0x35cd25){return _0x35cd25?{'count':_0x17d391,'rows':_0x35cd25}:null;}})[_0x200f('0x23')](respondWithResult(_0x1b5de7,null))[_0x200f('0x45')](handleError(_0x1b5de7,null));};exports[_0x200f('0x4e')]=function(_0x4595bb,_0x35f5b9,_0x3e4c92){var _0x4f6ace={};var _0x584b4d={};var _0x28e762;var _0x5114fa;return db[_0x200f('0x2a')][_0x200f('0x49')]({'where':{'id':_0x4595bb[_0x200f('0x43')]['id']}})[_0x200f('0x23')](handleEntityNotFound(_0x35f5b9,null))['then'](function(_0x2496ae){if(_0x2496ae){_0x28e762=_0x2496ae;_0x584b4d[_0x200f('0x2f')]=_['keys'](db['ServicenowField'][_0x200f('0x2b')]);_0x584b4d[_0x200f('0x31')]=_['keys'](_0x4595bb[_0x200f('0x31')]);_0x584b4d['filters']=_[_0x200f('0x34')](_0x584b4d[_0x200f('0x2f')],_0x584b4d[_0x200f('0x31')]);_0x4f6ace[_0x200f('0x33')]=_[_0x200f('0x34')](_0x584b4d['model'],qs[_0x200f('0x35')](_0x4595bb[_0x200f('0x31')][_0x200f('0x35')]));_0x4f6ace['attributes']=_0x4f6ace[_0x200f('0x33')][_0x200f('0x36')]?_0x4f6ace[_0x200f('0x33')]:_0x584b4d[_0x200f('0x2f')];_0x4f6ace[_0x200f('0x4b')]=qs[_0x200f('0x39')](_0x4595bb['query'][_0x200f('0x39')]);_0x4f6ace[_0x200f('0x3a')]=qs[_0x200f('0x32')](_[_0x200f('0x4c')](_0x4595bb[_0x200f('0x31')],_0x584b4d[_0x200f('0x32')]));if(_0x4595bb['query'][_0x200f('0x4d')]){_0x4f6ace['where']=_[_0x200f('0x3b')](_0x4f6ace[_0x200f('0x3a')],{'$or':_[_0x200f('0x29')](_0x4f6ace[_0x200f('0x33')],function(_0x260a59){var _0x2eb69b={};_0x2eb69b[_0x260a59]={'$like':'%'+_0x4595bb[_0x200f('0x31')][_0x200f('0x4d')]+'%'};return _0x2eb69b;})});}_0x4f6ace=_[_0x200f('0x3b')]({},_0x4f6ace,_0x4595bb[_0x200f('0x3d')]);return _0x28e762[_0x200f('0x4e')](_0x4f6ace);}})[_0x200f('0x23')](function(_0x4de931){if(_0x4de931){_0x5114fa=_0x4de931[_0x200f('0x36')];if(!_0x4595bb['query']['hasOwnProperty']('nolimit')){_0x4f6ace[_0x200f('0x1c')]=qs[_0x200f('0x1c')](_0x4595bb[_0x200f('0x31')][_0x200f('0x1c')]);_0x4f6ace[_0x200f('0x1a')]=qs['offset'](_0x4595bb[_0x200f('0x31')]['offset']);}return _0x28e762[_0x200f('0x4e')](_0x4f6ace);}})[_0x200f('0x23')](function(_0x405a4e){if(_0x405a4e){return _0x405a4e?{'count':_0x5114fa,'rows':_0x405a4e}:null;}})[_0x200f('0x23')](respondWithResult(_0x35f5b9,null))[_0x200f('0x45')](handleError(_0x35f5b9,null));};exports[_0x200f('0x4f')]=function(_0x346260,_0x461286,_0x5b698c){var _0xd18fad={};var _0x36f277={};var _0xfc6e17;var _0x5f144e;return db['ServicenowConfiguration'][_0x200f('0x49')]({'where':{'id':_0x346260[_0x200f('0x43')]['id']}})[_0x200f('0x23')](handleEntityNotFound(_0x461286,null))[_0x200f('0x23')](function(_0x2c3648){if(_0x2c3648){_0xfc6e17=_0x2c3648;_0x36f277[_0x200f('0x2f')]=_['keys'](db[_0x200f('0x4a')][_0x200f('0x2b')]);_0x36f277[_0x200f('0x31')]=_[_0x200f('0x30')](_0x346260[_0x200f('0x31')]);_0x36f277[_0x200f('0x32')]=_[_0x200f('0x34')](_0x36f277[_0x200f('0x2f')],_0x36f277[_0x200f('0x31')]);_0xd18fad[_0x200f('0x33')]=_[_0x200f('0x34')](_0x36f277[_0x200f('0x2f')],qs[_0x200f('0x35')](_0x346260[_0x200f('0x31')][_0x200f('0x35')]));_0xd18fad[_0x200f('0x33')]=_0xd18fad[_0x200f('0x33')][_0x200f('0x36')]?_0xd18fad[_0x200f('0x33')]:_0x36f277[_0x200f('0x2f')];_0xd18fad[_0x200f('0x4b')]=qs['sort'](_0x346260[_0x200f('0x31')][_0x200f('0x39')]);_0xd18fad[_0x200f('0x3a')]=qs[_0x200f('0x32')](_[_0x200f('0x4c')](_0x346260[_0x200f('0x31')],_0x36f277[_0x200f('0x32')]));if(_0x346260[_0x200f('0x31')]['filter']){_0xd18fad[_0x200f('0x3a')]=_['merge'](_0xd18fad['where'],{'$or':_[_0x200f('0x29')](_0xd18fad[_0x200f('0x33')],function(_0x45edc5){var _0x2dea69={};_0x2dea69[_0x45edc5]={'$like':'%'+_0x346260['query'][_0x200f('0x4d')]+'%'};return _0x2dea69;})});}_0xd18fad=_[_0x200f('0x3b')]({},_0xd18fad,_0x346260[_0x200f('0x3d')]);return _0xfc6e17[_0x200f('0x4f')](_0xd18fad);}})[_0x200f('0x23')](function(_0x775571){if(_0x775571){_0x5f144e=_0x775571[_0x200f('0x36')];if(!_0x346260[_0x200f('0x31')]['hasOwnProperty']('nolimit')){_0xd18fad['limit']=qs[_0x200f('0x1c')](_0x346260[_0x200f('0x31')]['limit']);_0xd18fad[_0x200f('0x1a')]=qs[_0x200f('0x1a')](_0x346260[_0x200f('0x31')][_0x200f('0x1a')]);}return _0xfc6e17[_0x200f('0x4f')](_0xd18fad);}})[_0x200f('0x23')](function(_0x2ee1a1){if(_0x2ee1a1){return _0x2ee1a1?{'count':_0x5f144e,'rows':_0x2ee1a1}:null;}})[_0x200f('0x23')](respondWithResult(_0x461286,null))[_0x200f('0x45')](handleError(_0x461286,null));};