8999e306936a8665d9c9cb97d1749682efa615e9
[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 _0x38fb=['show','params','rawAttributes','includeAll','create','update','body','find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','apply','reject','save','then','destroy','error','stack','name','send','index','map','ServicenowField','type','query','keys','filters','intersection','attributes','fields','length','model','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','include','findAll','rows','catch'];(function(_0x5b8da2,_0x13cd42){var _0x24f9e5=function(_0x8595ab){while(--_0x8595ab){_0x5b8da2['push'](_0x5b8da2['shift']());}};_0x24f9e5(++_0x13cd42);}(_0x38fb,0x1d0));var _0xb38f=function(_0x29d849,_0x209ceb){_0x29d849=_0x29d849-0x0;var _0x30b104=_0x38fb[_0x29d849];return _0x30b104;};'use strict';var emlformat=require(_0xb38f('0x0'));var rimraf=require(_0xb38f('0x1'));var zipdir=require(_0xb38f('0x2'));var jsonpatch=require(_0xb38f('0x3'));var rp=require(_0xb38f('0x4'));var moment=require(_0xb38f('0x5'));var BPromise=require(_0xb38f('0x6'));var Mustache=require(_0xb38f('0x7'));var util=require(_0xb38f('0x8'));var path=require('path');var sox=require(_0xb38f('0x9'));var csv=require(_0xb38f('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb38f('0xb'));var _=require(_0xb38f('0xc'));var squel=require(_0xb38f('0xd'));var crypto=require(_0xb38f('0xe'));var jsforce=require(_0xb38f('0xf'));var deskjs=require(_0xb38f('0x10'));var toCsv=require(_0xb38f('0xa'));var querystring=require(_0xb38f('0x11'));var Papa=require(_0xb38f('0x12'));var Redis=require(_0xb38f('0x13'));var authService=require(_0xb38f('0x14'));var qs=require(_0xb38f('0x15'));var as=require(_0xb38f('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb38f('0x17'))('api');var utils=require(_0xb38f('0x18'));var config=require(_0xb38f('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0xb38f('0x1a'))['db'];function respondWithStatusCode(_0x383fcc,_0x1732b0){_0x1732b0=_0x1732b0||0xcc;return function(_0x548fc8){if(_0x548fc8){return _0x383fcc[_0xb38f('0x1b')](_0x1732b0);}return _0x383fcc[_0xb38f('0x1c')](_0x1732b0)[_0xb38f('0x1d')]();};}function respondWithResult(_0x38dc5a,_0x329d60){_0x329d60=_0x329d60||0xc8;return function(_0x3095ca){if(_0x3095ca){return _0x38dc5a['status'](_0x329d60)['json'](_0x3095ca);}};}function respondWithFilteredResult(_0x5e26ff,_0x95d0c){return function(_0x4fed10){if(_0x4fed10){var _0x29c929=typeof _0x95d0c[_0xb38f('0x1e')]===_0xb38f('0x1f')&&typeof _0x95d0c[_0xb38f('0x20')]===_0xb38f('0x1f');var _0x5068ec=_0x4fed10[_0xb38f('0x21')];var _0x52688b=_0x29c929?0x0:_0x95d0c['offset'];var _0x3c14c1=_0x29c929?_0x4fed10[_0xb38f('0x21')]:_0x95d0c['offset']+_0x95d0c[_0xb38f('0x20')];var _0x36747b;if(_0x3c14c1>=_0x5068ec){_0x3c14c1=_0x5068ec;_0x36747b=0xc8;}else{_0x36747b=0xce;}_0x5e26ff['status'](_0x36747b);return _0x5e26ff[_0xb38f('0x22')]('Content-Range',_0x52688b+'-'+_0x3c14c1+'/'+_0x5068ec)['json'](_0x4fed10);}return null;};}function patchUpdates(_0x3d96e2){return function(_0x305d35){try{jsonpatch[_0xb38f('0x23')](_0x305d35,_0x3d96e2,!![]);}catch(_0x3e4cc0){return BPromise[_0xb38f('0x24')](_0x3e4cc0);}return _0x305d35[_0xb38f('0x25')]();};}function saveUpdates(_0x314747,_0x55e508){return function(_0x591b0a){if(_0x591b0a){return _0x591b0a['update'](_0x314747)[_0xb38f('0x26')](function(_0x2742b9){return _0x2742b9;});}return null;};}function removeEntity(_0xe85ed4,_0x16cfb7){return function(_0x2eeba8){if(_0x2eeba8){return _0x2eeba8[_0xb38f('0x27')]()[_0xb38f('0x26')](function(){_0xe85ed4[_0xb38f('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4659ae,_0x491681){return function(_0x24d871){if(!_0x24d871){_0x4659ae[_0xb38f('0x1b')](0x194);}return _0x24d871;};}function handleError(_0xd5f810,_0x4a6c2e){_0x4a6c2e=_0x4a6c2e||0x1f4;return function(_0x580ce3){logger[_0xb38f('0x28')](_0x580ce3[_0xb38f('0x29')]);if(_0x580ce3[_0xb38f('0x2a')]){delete _0x580ce3[_0xb38f('0x2a')];}_0xd5f810[_0xb38f('0x1c')](_0x4a6c2e)[_0xb38f('0x2b')](_0x580ce3);};}exports[_0xb38f('0x2c')]=function(_0x43f500,_0xb90ba2){var _0x11dcaf={},_0x5993ef={},_0x86aac={'count':0x0,'rows':[]};var _0x54c667=_[_0xb38f('0x2d')](db[_0xb38f('0x2e')]['rawAttributes'],function(_0x3e0afa){return{'name':_0x3e0afa['fieldName'],'type':_0x3e0afa[_0xb38f('0x2f')]['key']};});_0x5993ef['model']=_[_0xb38f('0x2d')](_0x54c667,'name');_0x5993ef[_0xb38f('0x30')]=_[_0xb38f('0x31')](_0x43f500[_0xb38f('0x30')]);_0x5993ef[_0xb38f('0x32')]=_[_0xb38f('0x33')](_0x5993ef['model'],_0x5993ef[_0xb38f('0x30')]);_0x11dcaf[_0xb38f('0x34')]=_[_0xb38f('0x33')](_0x5993ef['model'],qs[_0xb38f('0x35')](_0x43f500[_0xb38f('0x30')][_0xb38f('0x35')]));_0x11dcaf['attributes']=_0x11dcaf[_0xb38f('0x34')][_0xb38f('0x36')]?_0x11dcaf[_0xb38f('0x34')]:_0x5993ef[_0xb38f('0x37')];if(!_0x43f500[_0xb38f('0x30')][_0xb38f('0x38')](_0xb38f('0x39'))){_0x11dcaf[_0xb38f('0x20')]=qs[_0xb38f('0x20')](_0x43f500['query'][_0xb38f('0x20')]);_0x11dcaf[_0xb38f('0x1e')]=qs['offset'](_0x43f500['query'][_0xb38f('0x1e')]);}_0x11dcaf[_0xb38f('0x3a')]=qs[_0xb38f('0x3b')](_0x43f500['query']['sort']);_0x11dcaf[_0xb38f('0x3c')]=qs[_0xb38f('0x32')](_['pick'](_0x43f500[_0xb38f('0x30')],_0x5993ef['filters']),_0x54c667);if(_0x43f500[_0xb38f('0x30')][_0xb38f('0x3d')]){_0x11dcaf[_0xb38f('0x3c')]=_['merge'](_0x11dcaf[_0xb38f('0x3c')],{'$or':_['map'](_0x54c667,function(_0x2808c2){if(_0x2808c2['type']!=='VIRTUAL'){var _0x1973cd={};_0x1973cd[_0x2808c2[_0xb38f('0x2a')]]={'$like':'%'+_0x43f500[_0xb38f('0x30')][_0xb38f('0x3d')]+'%'};return _0x1973cd;}})});}_0x11dcaf=_[_0xb38f('0x3e')]({},_0x11dcaf,_0x43f500[_0xb38f('0x3f')]);var _0x4c385c={'where':_0x11dcaf[_0xb38f('0x3c')]};return db[_0xb38f('0x2e')][_0xb38f('0x21')](_0x4c385c)[_0xb38f('0x26')](function(_0x194272){_0x86aac[_0xb38f('0x21')]=_0x194272;if(_0x43f500[_0xb38f('0x30')]['includeAll']){_0x11dcaf[_0xb38f('0x40')]=[{'all':!![]}];}return db[_0xb38f('0x2e')][_0xb38f('0x41')](_0x11dcaf);})[_0xb38f('0x26')](function(_0x23a288){_0x86aac[_0xb38f('0x42')]=_0x23a288;return _0x86aac;})[_0xb38f('0x26')](respondWithFilteredResult(_0xb90ba2,_0x11dcaf))[_0xb38f('0x43')](handleError(_0xb90ba2,null));};exports[_0xb38f('0x44')]=function(_0x4ecc0a,_0x2879ac){var _0x38f362={'raw':!![],'where':{'id':_0x4ecc0a[_0xb38f('0x45')]['id']}},_0x67e0f8={};_0x67e0f8[_0xb38f('0x37')]=_[_0xb38f('0x31')](db[_0xb38f('0x2e')][_0xb38f('0x46')]);_0x67e0f8['query']=_[_0xb38f('0x31')](_0x4ecc0a['query']);_0x67e0f8[_0xb38f('0x32')]=_[_0xb38f('0x33')](_0x67e0f8[_0xb38f('0x37')],_0x67e0f8[_0xb38f('0x30')]);_0x38f362['attributes']=_['intersection'](_0x67e0f8[_0xb38f('0x37')],qs['fields'](_0x4ecc0a[_0xb38f('0x30')][_0xb38f('0x35')]));_0x38f362[_0xb38f('0x34')]=_0x38f362[_0xb38f('0x34')][_0xb38f('0x36')]?_0x38f362[_0xb38f('0x34')]:_0x67e0f8['model'];if(_0x4ecc0a[_0xb38f('0x30')][_0xb38f('0x47')]){_0x38f362['include']=[{'all':!![]}];}_0x38f362=_[_0xb38f('0x3e')]({},_0x38f362,_0x4ecc0a[_0xb38f('0x3f')]);return db[_0xb38f('0x2e')]['find'](_0x38f362)[_0xb38f('0x26')](handleEntityNotFound(_0x2879ac,null))[_0xb38f('0x26')](respondWithResult(_0x2879ac,null))[_0xb38f('0x43')](handleError(_0x2879ac,null));};exports[_0xb38f('0x48')]=function(_0x3fd4dc,_0x596417){return db[_0xb38f('0x2e')][_0xb38f('0x48')](_0x3fd4dc['body'],{})[_0xb38f('0x26')](respondWithResult(_0x596417,0xc9))['catch'](handleError(_0x596417,null));};exports[_0xb38f('0x49')]=function(_0xe6d133,_0x29434a){if(_0xe6d133[_0xb38f('0x4a')]['id']){delete _0xe6d133['body']['id'];}return db[_0xb38f('0x2e')][_0xb38f('0x4b')]({'where':{'id':_0xe6d133[_0xb38f('0x45')]['id']}})[_0xb38f('0x26')](handleEntityNotFound(_0x29434a,null))[_0xb38f('0x26')](saveUpdates(_0xe6d133[_0xb38f('0x4a')],null))[_0xb38f('0x26')](respondWithResult(_0x29434a,null))[_0xb38f('0x43')](handleError(_0x29434a,null));};exports['destroy']=function(_0x5edcda,_0x593ac2){return db['ServicenowField'][_0xb38f('0x4b')]({'where':{'id':_0x5edcda[_0xb38f('0x45')]['id']}})['then'](handleEntityNotFound(_0x593ac2,null))[_0xb38f('0x26')](removeEntity(_0x593ac2,null))['catch'](handleError(_0x593ac2,null));};