Built motion from commit (unavailable).|2.5.31
[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 _0x64f7=['status','end','json','undefined','limit','count','offset','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','index','map','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','merge','type','VIRTUAL','filter','ServicenowField','includeAll','include','findAll','rows','catch','params','keys','options','find','body','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus'];(function(_0xbf5e16,_0x146ce3){var _0x5975a5=function(_0x2387a7){while(--_0x2387a7){_0xbf5e16['push'](_0xbf5e16['shift']());}};_0x5975a5(++_0x146ce3);}(_0x64f7,0x115));var _0x764f=function(_0x4c5811,_0x2bbbc1){_0x4c5811=_0x4c5811-0x0;var _0x3ec305=_0x64f7[_0x4c5811];return _0x3ec305;};'use strict';var emlformat=require(_0x764f('0x0'));var rimraf=require(_0x764f('0x1'));var zipdir=require(_0x764f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x764f('0x3'));var moment=require(_0x764f('0x4'));var BPromise=require(_0x764f('0x5'));var Mustache=require(_0x764f('0x6'));var util=require(_0x764f('0x7'));var path=require(_0x764f('0x8'));var sox=require('sox');var csv=require(_0x764f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x764f('0xa'));var _=require(_0x764f('0xb'));var squel=require(_0x764f('0xc'));var crypto=require(_0x764f('0xd'));var jsforce=require(_0x764f('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x764f('0x9'));var querystring=require(_0x764f('0xf'));var Papa=require(_0x764f('0x10'));var Redis=require(_0x764f('0x11'));var authService=require(_0x764f('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x764f('0x13'));var hardwareService=require(_0x764f('0x14'));var logger=require(_0x764f('0x15'))(_0x764f('0x16'));var utils=require('../../config/utils');var config=require(_0x764f('0x17'));var licenseUtil=require(_0x764f('0x18'));var db=require(_0x764f('0x19'))['db'];function respondWithStatusCode(_0x40d2e9,_0x196f7a){_0x196f7a=_0x196f7a||0xcc;return function(_0x4db167){if(_0x4db167){return _0x40d2e9[_0x764f('0x1a')](_0x196f7a);}return _0x40d2e9[_0x764f('0x1b')](_0x196f7a)[_0x764f('0x1c')]();};}function respondWithResult(_0x15636c,_0x8c7b07){_0x8c7b07=_0x8c7b07||0xc8;return function(_0x2cb185){if(_0x2cb185){return _0x15636c['status'](_0x8c7b07)[_0x764f('0x1d')](_0x2cb185);}};}function respondWithFilteredResult(_0x1efecd,_0x47702a){return function(_0x22c67b){if(_0x22c67b){var _0x23c20f=typeof _0x47702a['offset']===_0x764f('0x1e')&&typeof _0x47702a[_0x764f('0x1f')]===_0x764f('0x1e');var _0x3de210=_0x22c67b['count'];var _0x246b05=_0x23c20f?0x0:_0x47702a['offset'];var _0xd13eb8=_0x23c20f?_0x22c67b[_0x764f('0x20')]:_0x47702a[_0x764f('0x21')]+_0x47702a[_0x764f('0x1f')];var _0x498f49;if(_0xd13eb8>=_0x3de210){_0xd13eb8=_0x3de210;_0x498f49=0xc8;}else{_0x498f49=0xce;}_0x1efecd[_0x764f('0x1b')](_0x498f49);return _0x1efecd['set'](_0x764f('0x22'),_0x246b05+'-'+_0xd13eb8+'/'+_0x3de210)[_0x764f('0x1d')](_0x22c67b);}return null;};}function patchUpdates(_0x50a3ae){return function(_0x554e25){try{jsonpatch[_0x764f('0x23')](_0x554e25,_0x50a3ae,!![]);}catch(_0x165e1b){return BPromise[_0x764f('0x24')](_0x165e1b);}return _0x554e25[_0x764f('0x25')]();};}function saveUpdates(_0x48bbe3,_0x93ea6b){return function(_0x2ae6a1){if(_0x2ae6a1){return _0x2ae6a1[_0x764f('0x26')](_0x48bbe3)[_0x764f('0x27')](function(_0xc5f3f2){return _0xc5f3f2;});}return null;};}function removeEntity(_0x36da9b,_0x2e7125){return function(_0x475d51){if(_0x475d51){return _0x475d51[_0x764f('0x28')]()[_0x764f('0x27')](function(){_0x36da9b[_0x764f('0x1b')](0xcc)[_0x764f('0x1c')]();});}};}function handleEntityNotFound(_0x5a62b1,_0x3fa08f){return function(_0x1b14d3){if(!_0x1b14d3){_0x5a62b1[_0x764f('0x1a')](0x194);}return _0x1b14d3;};}function handleError(_0x3a7729,_0x585830){_0x585830=_0x585830||0x1f4;return function(_0xdfb81d){logger[_0x764f('0x29')](_0xdfb81d[_0x764f('0x2a')]);if(_0xdfb81d['name']){delete _0xdfb81d[_0x764f('0x2b')];}_0x3a7729[_0x764f('0x1b')](_0x585830)['send'](_0xdfb81d);};}exports[_0x764f('0x2c')]=function(_0x588ae1,_0x2f419a){var _0x157e48={},_0x3f5946={},_0x4629c5={'count':0x0,'rows':[]};var _0x3ed911=_[_0x764f('0x2d')](db['ServicenowField'][_0x764f('0x2e')],function(_0x355a10){return{'name':_0x355a10[_0x764f('0x2f')],'type':_0x355a10['type'][_0x764f('0x30')]};});_0x3f5946[_0x764f('0x31')]=_['map'](_0x3ed911,_0x764f('0x2b'));_0x3f5946['query']=_['keys'](_0x588ae1[_0x764f('0x32')]);_0x3f5946[_0x764f('0x33')]=_[_0x764f('0x34')](_0x3f5946[_0x764f('0x31')],_0x3f5946[_0x764f('0x32')]);_0x157e48[_0x764f('0x35')]=_[_0x764f('0x34')](_0x3f5946[_0x764f('0x31')],qs[_0x764f('0x36')](_0x588ae1[_0x764f('0x32')]['fields']));_0x157e48[_0x764f('0x35')]=_0x157e48[_0x764f('0x35')][_0x764f('0x37')]?_0x157e48[_0x764f('0x35')]:_0x3f5946[_0x764f('0x31')];if(!_0x588ae1[_0x764f('0x32')]['hasOwnProperty'](_0x764f('0x38'))){_0x157e48[_0x764f('0x1f')]=qs[_0x764f('0x1f')](_0x588ae1[_0x764f('0x32')][_0x764f('0x1f')]);_0x157e48[_0x764f('0x21')]=qs[_0x764f('0x21')](_0x588ae1[_0x764f('0x32')][_0x764f('0x21')]);}_0x157e48[_0x764f('0x39')]=qs[_0x764f('0x3a')](_0x588ae1[_0x764f('0x32')][_0x764f('0x3a')]);_0x157e48[_0x764f('0x3b')]=qs[_0x764f('0x33')](_[_0x764f('0x3c')](_0x588ae1['query'],_0x3f5946['filters']),_0x3ed911);if(_0x588ae1[_0x764f('0x32')]['filter']){_0x157e48['where']=_[_0x764f('0x3d')](_0x157e48[_0x764f('0x3b')],{'$or':_['map'](_0x3ed911,function(_0x10a5fd){if(_0x10a5fd[_0x764f('0x3e')]!==_0x764f('0x3f')){var _0x586e8a={};_0x586e8a[_0x10a5fd[_0x764f('0x2b')]]={'$like':'%'+_0x588ae1[_0x764f('0x32')][_0x764f('0x40')]+'%'};return _0x586e8a;}})});}_0x157e48=_['merge']({},_0x157e48,_0x588ae1['options']);var _0xabb5cd={'where':_0x157e48[_0x764f('0x3b')]};return db[_0x764f('0x41')][_0x764f('0x20')](_0xabb5cd)['then'](function(_0x4bdcdd){_0x4629c5['count']=_0x4bdcdd;if(_0x588ae1[_0x764f('0x32')][_0x764f('0x42')]){_0x157e48[_0x764f('0x43')]=[{'all':!![]}];}return db[_0x764f('0x41')][_0x764f('0x44')](_0x157e48);})[_0x764f('0x27')](function(_0x26e0f3){_0x4629c5[_0x764f('0x45')]=_0x26e0f3;return _0x4629c5;})[_0x764f('0x27')](respondWithFilteredResult(_0x2f419a,_0x157e48))[_0x764f('0x46')](handleError(_0x2f419a,null));};exports['show']=function(_0x2ec523,_0x9b1639){var _0x5d3709={'raw':!![],'where':{'id':_0x2ec523[_0x764f('0x47')]['id']}},_0x26aa0c={};_0x26aa0c[_0x764f('0x31')]=_[_0x764f('0x48')](db[_0x764f('0x41')][_0x764f('0x2e')]);_0x26aa0c[_0x764f('0x32')]=_[_0x764f('0x48')](_0x2ec523[_0x764f('0x32')]);_0x26aa0c[_0x764f('0x33')]=_[_0x764f('0x34')](_0x26aa0c[_0x764f('0x31')],_0x26aa0c[_0x764f('0x32')]);_0x5d3709[_0x764f('0x35')]=_['intersection'](_0x26aa0c[_0x764f('0x31')],qs[_0x764f('0x36')](_0x2ec523[_0x764f('0x32')]['fields']));_0x5d3709[_0x764f('0x35')]=_0x5d3709[_0x764f('0x35')]['length']?_0x5d3709[_0x764f('0x35')]:_0x26aa0c[_0x764f('0x31')];if(_0x2ec523[_0x764f('0x32')][_0x764f('0x42')]){_0x5d3709[_0x764f('0x43')]=[{'all':!![]}];}_0x5d3709=_[_0x764f('0x3d')]({},_0x5d3709,_0x2ec523[_0x764f('0x49')]);return db[_0x764f('0x41')][_0x764f('0x4a')](_0x5d3709)[_0x764f('0x27')](handleEntityNotFound(_0x9b1639,null))[_0x764f('0x27')](respondWithResult(_0x9b1639,null))['catch'](handleError(_0x9b1639,null));};exports['create']=function(_0x47eb94,_0xcb9cc0){return db['ServicenowField']['create'](_0x47eb94[_0x764f('0x4b')],{})[_0x764f('0x27')](respondWithResult(_0xcb9cc0,0xc9))[_0x764f('0x46')](handleError(_0xcb9cc0,null));};exports[_0x764f('0x26')]=function(_0x1d3965,_0x36b3b1){if(_0x1d3965['body']['id']){delete _0x1d3965[_0x764f('0x4b')]['id'];}return db['ServicenowField'][_0x764f('0x4a')]({'where':{'id':_0x1d3965[_0x764f('0x47')]['id']}})[_0x764f('0x27')](handleEntityNotFound(_0x36b3b1,null))['then'](saveUpdates(_0x1d3965['body'],null))[_0x764f('0x27')](respondWithResult(_0x36b3b1,null))[_0x764f('0x46')](handleError(_0x36b3b1,null));};exports['destroy']=function(_0x45a968,_0x2c0f5b){return db[_0x764f('0x41')][_0x764f('0x4a')]({'where':{'id':_0x45a968[_0x764f('0x47')]['id']}})[_0x764f('0x27')](handleEntityNotFound(_0x2c0f5b,null))[_0x764f('0x27')](removeEntity(_0x2c0f5b,null))['catch'](handleError(_0x2c0f5b,null));};