Built motion from commit d1eab355.|2.6.28
[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 _0x504f=['zip-dir','fast-json-patch','bluebird','mustache','util','path','ejs','lodash','squel','crypto','to-csv','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','offset','count','limit','set','reject','save','update','destroy','then','error','name','send','map','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','where','merge','VIRTUAL','filter','options','ServicenowField','includeAll','include','findAll','rows','catch','show','keys','length','find','create','body','params','rimraf'];(function(_0x3cb3ca,_0x44d697){var _0x214366=function(_0x6b38e1){while(--_0x6b38e1){_0x3cb3ca['push'](_0x3cb3ca['shift']());}};_0x214366(++_0x44d697);}(_0x504f,0xcb));var _0xf504=function(_0x240f2f,_0x9ef220){_0x240f2f=_0x240f2f-0x0;var _0xef2099=_0x504f[_0x240f2f];return _0xef2099;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf504('0x0'));var zipdir=require(_0xf504('0x1'));var jsonpatch=require(_0xf504('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xf504('0x3'));var Mustache=require(_0xf504('0x4'));var util=require(_0xf504('0x5'));var path=require(_0xf504('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf504('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf504('0x8'));var squel=require(_0xf504('0x9'));var crypto=require(_0xf504('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf504('0xb'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf504('0xc'));var authService=require('../../components/auth/service');var qs=require(_0xf504('0xd'));var as=require(_0xf504('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf504('0xf'))('api');var utils=require(_0xf504('0x10'));var config=require(_0xf504('0x11'));var licenseUtil=require(_0xf504('0x12'));var db=require(_0xf504('0x13'))['db'];function respondWithStatusCode(_0x10f754,_0xe9686a){_0xe9686a=_0xe9686a||0xcc;return function(_0xd4a84c){if(_0xd4a84c){return _0x10f754[_0xf504('0x14')](_0xe9686a);}return _0x10f754[_0xf504('0x15')](_0xe9686a)[_0xf504('0x16')]();};}function respondWithResult(_0x22c6ea,_0x5ea22a){_0x5ea22a=_0x5ea22a||0xc8;return function(_0x2bae57){if(_0x2bae57){return _0x22c6ea[_0xf504('0x15')](_0x5ea22a)[_0xf504('0x17')](_0x2bae57);}};}function respondWithFilteredResult(_0x42cc94,_0x4b7a18){return function(_0x4f1848){if(_0x4f1848){var _0x515ca1=typeof _0x4b7a18['offset']===_0xf504('0x18')&&typeof _0x4b7a18['limit']===_0xf504('0x18');var _0x1558b7=_0x4f1848['count'];var _0x17dfe9=_0x515ca1?0x0:_0x4b7a18[_0xf504('0x19')];var _0x339204=_0x515ca1?_0x4f1848[_0xf504('0x1a')]:_0x4b7a18[_0xf504('0x19')]+_0x4b7a18[_0xf504('0x1b')];var _0x44b5d1;if(_0x339204>=_0x1558b7){_0x339204=_0x1558b7;_0x44b5d1=0xc8;}else{_0x44b5d1=0xce;}_0x42cc94[_0xf504('0x15')](_0x44b5d1);return _0x42cc94[_0xf504('0x1c')]('Content-Range',_0x17dfe9+'-'+_0x339204+'/'+_0x1558b7)[_0xf504('0x17')](_0x4f1848);}return null;};}function patchUpdates(_0x21451d){return function(_0x16b3e6){try{jsonpatch['apply'](_0x16b3e6,_0x21451d,!![]);}catch(_0x12f6d9){return BPromise[_0xf504('0x1d')](_0x12f6d9);}return _0x16b3e6[_0xf504('0x1e')]();};}function saveUpdates(_0xca4e5c,_0x2cd868){return function(_0x365d63){if(_0x365d63){return _0x365d63[_0xf504('0x1f')](_0xca4e5c)['then'](function(_0x4f9e29){return _0x4f9e29;});}return null;};}function removeEntity(_0x35ea5e,_0x18a48e){return function(_0xa7cdb8){if(_0xa7cdb8){return _0xa7cdb8[_0xf504('0x20')]()[_0xf504('0x21')](function(){_0x35ea5e[_0xf504('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x66de51,_0x3378a4){return function(_0x5239de){if(!_0x5239de){_0x66de51['sendStatus'](0x194);}return _0x5239de;};}function handleError(_0x5c88fd,_0x5a32a7){_0x5a32a7=_0x5a32a7||0x1f4;return function(_0x3c26cc){logger[_0xf504('0x22')](_0x3c26cc['stack']);if(_0x3c26cc['name']){delete _0x3c26cc[_0xf504('0x23')];}_0x5c88fd['status'](_0x5a32a7)[_0xf504('0x24')](_0x3c26cc);};}exports['index']=function(_0x5288dc,_0x315530){var _0xadb47a={},_0x4197d2={},_0x142b24={'count':0x0,'rows':[]};var _0x2e85ac=_[_0xf504('0x25')](db['ServicenowField'][_0xf504('0x26')],function(_0x56bbb2){return{'name':_0x56bbb2[_0xf504('0x27')],'type':_0x56bbb2[_0xf504('0x28')][_0xf504('0x29')]};});_0x4197d2[_0xf504('0x2a')]=_[_0xf504('0x25')](_0x2e85ac,_0xf504('0x23'));_0x4197d2['query']=_['keys'](_0x5288dc[_0xf504('0x2b')]);_0x4197d2[_0xf504('0x2c')]=_[_0xf504('0x2d')](_0x4197d2[_0xf504('0x2a')],_0x4197d2[_0xf504('0x2b')]);_0xadb47a[_0xf504('0x2e')]=_[_0xf504('0x2d')](_0x4197d2[_0xf504('0x2a')],qs[_0xf504('0x2f')](_0x5288dc['query'][_0xf504('0x2f')]));_0xadb47a[_0xf504('0x2e')]=_0xadb47a[_0xf504('0x2e')]['length']?_0xadb47a[_0xf504('0x2e')]:_0x4197d2[_0xf504('0x2a')];if(!_0x5288dc['query'][_0xf504('0x30')](_0xf504('0x31'))){_0xadb47a[_0xf504('0x1b')]=qs[_0xf504('0x1b')](_0x5288dc[_0xf504('0x2b')][_0xf504('0x1b')]);_0xadb47a['offset']=qs[_0xf504('0x19')](_0x5288dc[_0xf504('0x2b')][_0xf504('0x19')]);}_0xadb47a['order']=qs['sort'](_0x5288dc[_0xf504('0x2b')]['sort']);_0xadb47a['where']=qs[_0xf504('0x2c')](_['pick'](_0x5288dc['query'],_0x4197d2[_0xf504('0x2c')]),_0x2e85ac);if(_0x5288dc[_0xf504('0x2b')]['filter']){_0xadb47a[_0xf504('0x32')]=_[_0xf504('0x33')](_0xadb47a[_0xf504('0x32')],{'$or':_[_0xf504('0x25')](_0x2e85ac,function(_0x1ebfb4){if(_0x1ebfb4[_0xf504('0x28')]!==_0xf504('0x34')){var _0x2c0f95={};_0x2c0f95[_0x1ebfb4[_0xf504('0x23')]]={'$like':'%'+_0x5288dc[_0xf504('0x2b')][_0xf504('0x35')]+'%'};return _0x2c0f95;}})});}_0xadb47a=_[_0xf504('0x33')]({},_0xadb47a,_0x5288dc[_0xf504('0x36')]);var _0x5dd975={'where':_0xadb47a[_0xf504('0x32')]};return db[_0xf504('0x37')][_0xf504('0x1a')](_0x5dd975)[_0xf504('0x21')](function(_0x4fa397){_0x142b24[_0xf504('0x1a')]=_0x4fa397;if(_0x5288dc['query'][_0xf504('0x38')]){_0xadb47a[_0xf504('0x39')]=[{'all':!![]}];}return db[_0xf504('0x37')][_0xf504('0x3a')](_0xadb47a);})['then'](function(_0x50890c){_0x142b24[_0xf504('0x3b')]=_0x50890c;return _0x142b24;})['then'](respondWithFilteredResult(_0x315530,_0xadb47a))[_0xf504('0x3c')](handleError(_0x315530,null));};exports[_0xf504('0x3d')]=function(_0x1b759a,_0x49ab26){var _0x116feb={'raw':!![],'where':{'id':_0x1b759a['params']['id']}},_0x4222c7={};_0x4222c7[_0xf504('0x2a')]=_['keys'](db[_0xf504('0x37')]['rawAttributes']);_0x4222c7['query']=_[_0xf504('0x3e')](_0x1b759a['query']);_0x4222c7[_0xf504('0x2c')]=_[_0xf504('0x2d')](_0x4222c7['model'],_0x4222c7['query']);_0x116feb[_0xf504('0x2e')]=_[_0xf504('0x2d')](_0x4222c7[_0xf504('0x2a')],qs[_0xf504('0x2f')](_0x1b759a[_0xf504('0x2b')]['fields']));_0x116feb[_0xf504('0x2e')]=_0x116feb[_0xf504('0x2e')][_0xf504('0x3f')]?_0x116feb[_0xf504('0x2e')]:_0x4222c7[_0xf504('0x2a')];if(_0x1b759a[_0xf504('0x2b')][_0xf504('0x38')]){_0x116feb['include']=[{'all':!![]}];}_0x116feb=_[_0xf504('0x33')]({},_0x116feb,_0x1b759a[_0xf504('0x36')]);return db[_0xf504('0x37')][_0xf504('0x40')](_0x116feb)[_0xf504('0x21')](handleEntityNotFound(_0x49ab26,null))[_0xf504('0x21')](respondWithResult(_0x49ab26,null))[_0xf504('0x3c')](handleError(_0x49ab26,null));};exports[_0xf504('0x41')]=function(_0x50fc25,_0x2531b4){return db[_0xf504('0x37')]['create'](_0x50fc25[_0xf504('0x42')],{})[_0xf504('0x21')](respondWithResult(_0x2531b4,0xc9))[_0xf504('0x3c')](handleError(_0x2531b4,null));};exports['update']=function(_0x38ac43,_0x425692){if(_0x38ac43['body']['id']){delete _0x38ac43[_0xf504('0x42')]['id'];}return db[_0xf504('0x37')]['find']({'where':{'id':_0x38ac43[_0xf504('0x43')]['id']}})['then'](handleEntityNotFound(_0x425692,null))[_0xf504('0x21')](saveUpdates(_0x38ac43[_0xf504('0x42')],null))[_0xf504('0x21')](respondWithResult(_0x425692,null))[_0xf504('0x3c')](handleError(_0x425692,null));};exports['destroy']=function(_0x240695,_0x46f96e){return db[_0xf504('0x37')][_0xf504('0x40')]({'where':{'id':_0x240695[_0xf504('0x43')]['id']}})[_0xf504('0x21')](handleEntityNotFound(_0x46f96e,null))[_0xf504('0x21')](removeEntity(_0x46f96e,null))[_0xf504('0x3c')](handleError(_0x46f96e,null));};