Built motion from commit (unavailable).|2.5.11
[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 _0x9ab9=['end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','ServicenowField','fieldName','type','query','keys','filters','intersection','model','attributes','fields','length','order','sort','where','pick','merge','filter','includeAll','include','findAll','rows','catch','show','rawAttributes','options','find','create','body','params','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','sox','to-csv','ejs','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','sendStatus','status'];(function(_0xbd08b4,_0x4790ed){var _0x314f1e=function(_0x161589){while(--_0x161589){_0xbd08b4['push'](_0xbd08b4['shift']());}};_0x314f1e(++_0x4790ed);}(_0x9ab9,0x19d));var _0x99ab=function(_0x3c6de9,_0x56eb84){_0x3c6de9=_0x3c6de9-0x0;var _0x247a9c=_0x9ab9[_0x3c6de9];return _0x247a9c;};'use strict';var pdf=require(_0x99ab('0x0'));var emlformat=require(_0x99ab('0x1'));var rimraf=require(_0x99ab('0x2'));var zipdir=require(_0x99ab('0x3'));var jsonpatch=require(_0x99ab('0x4'));var rp=require('request-promise');var moment=require(_0x99ab('0x5'));var BPromise=require(_0x99ab('0x6'));var Mustache=require('mustache');var util=require(_0x99ab('0x7'));var path=require('path');var sox=require(_0x99ab('0x8'));var csv=require(_0x99ab('0x9'));var ejs=require(_0x99ab('0xa'));var fs=require('fs');var _=require(_0x99ab('0xb'));var squel=require(_0x99ab('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x99ab('0xd'));var toCsv=require(_0x99ab('0x9'));var querystring=require('querystring');var Papa=require(_0x99ab('0xe'));var Redis=require(_0x99ab('0xf'));var authService=require(_0x99ab('0x10'));var qs=require(_0x99ab('0x11'));var as=require(_0x99ab('0x12'));var hardwareService=require(_0x99ab('0x13'));var logger=require('../../config/logger')(_0x99ab('0x14'));var utils=require(_0x99ab('0x15'));var config=require(_0x99ab('0x16'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xed2100,_0x24229c){_0x24229c=_0x24229c||0xcc;return function(_0x3739fb){if(_0x3739fb){return _0xed2100[_0x99ab('0x17')](_0x24229c);}return _0xed2100[_0x99ab('0x18')](_0x24229c)[_0x99ab('0x19')]();};}function respondWithResult(_0x584744,_0x97639f){_0x97639f=_0x97639f||0xc8;return function(_0x5bf382){if(_0x5bf382){return _0x584744['status'](_0x97639f)[_0x99ab('0x1a')](_0x5bf382);}};}function respondWithFilteredResult(_0x36d89e,_0xa60b53){return function(_0x4b11f1){if(_0x4b11f1){var _0x4299ae=_0x4b11f1[_0x99ab('0x1b')],_0x13b9aa=_0xa60b53[_0x99ab('0x1c')],_0x1c52a6=_0xa60b53[_0x99ab('0x1c')]+_0xa60b53[_0x99ab('0x1d')],_0x31b340;if(_0x1c52a6>=_0x4299ae){_0x1c52a6=_0x4299ae;_0x31b340=0xc8;}else{_0x31b340=0xce;}_0x36d89e['status'](_0x31b340);return _0x36d89e[_0x99ab('0x1e')](_0x99ab('0x1f'),_0x13b9aa+'-'+_0x1c52a6+'/'+_0x4299ae)[_0x99ab('0x1a')](_0x4b11f1);}return null;};}function patchUpdates(_0x1cdd6d){return function(_0x34e694){try{jsonpatch[_0x99ab('0x20')](_0x34e694,_0x1cdd6d,!![]);}catch(_0x2abddd){return BPromise[_0x99ab('0x21')](_0x2abddd);}return _0x34e694[_0x99ab('0x22')]();};}function saveUpdates(_0x51ded6,_0x5ab547){return function(_0x1fdcdf){if(_0x1fdcdf){return _0x1fdcdf[_0x99ab('0x23')](_0x51ded6)[_0x99ab('0x24')](function(_0x4e7647){return _0x4e7647;});}return null;};}function removeEntity(_0x2e0464,_0x3a0897){return function(_0xa3cf1e){if(_0xa3cf1e){return _0xa3cf1e[_0x99ab('0x25')]()[_0x99ab('0x24')](function(){_0x2e0464[_0x99ab('0x18')](0xcc)[_0x99ab('0x19')]();});}};}function handleEntityNotFound(_0x5411a6,_0x5de675){return function(_0x4cd112){if(!_0x4cd112){_0x5411a6[_0x99ab('0x17')](0x194);}return _0x4cd112;};}function handleError(_0x56bdb7,_0x4e52db){_0x4e52db=_0x4e52db||0x1f4;return function(_0x2d3281){logger[_0x99ab('0x26')](_0x2d3281[_0x99ab('0x27')]);if(_0x2d3281['name']){delete _0x2d3281[_0x99ab('0x28')];}_0x56bdb7[_0x99ab('0x18')](_0x4e52db)[_0x99ab('0x29')](_0x2d3281);};}exports[_0x99ab('0x2a')]=function(_0x36414c,_0x45d50e){var _0x970ce7={},_0x2efec3={},_0xe3945b={'count':0x0,'rows':[]};var _0x4ce5ce=_[_0x99ab('0x2b')](db[_0x99ab('0x2c')]['rawAttributes'],function(_0x35d09e){return{'name':_0x35d09e[_0x99ab('0x2d')],'type':_0x35d09e[_0x99ab('0x2e')]['key']};});_0x2efec3['model']=_[_0x99ab('0x2b')](_0x4ce5ce,_0x99ab('0x28'));_0x2efec3[_0x99ab('0x2f')]=_[_0x99ab('0x30')](_0x36414c[_0x99ab('0x2f')]);_0x2efec3[_0x99ab('0x31')]=_[_0x99ab('0x32')](_0x2efec3[_0x99ab('0x33')],_0x2efec3['query']);_0x970ce7[_0x99ab('0x34')]=_[_0x99ab('0x32')](_0x2efec3['model'],qs[_0x99ab('0x35')](_0x36414c[_0x99ab('0x2f')]['fields']));_0x970ce7['attributes']=_0x970ce7[_0x99ab('0x34')][_0x99ab('0x36')]?_0x970ce7[_0x99ab('0x34')]:_0x2efec3['model'];if(!_0x36414c['query']['hasOwnProperty']('nolimit')){_0x970ce7['limit']=qs['limit'](_0x36414c[_0x99ab('0x2f')][_0x99ab('0x1d')]);_0x970ce7[_0x99ab('0x1c')]=qs['offset'](_0x36414c[_0x99ab('0x2f')][_0x99ab('0x1c')]);}_0x970ce7[_0x99ab('0x37')]=qs['sort'](_0x36414c[_0x99ab('0x2f')][_0x99ab('0x38')]);_0x970ce7[_0x99ab('0x39')]=qs[_0x99ab('0x31')](_[_0x99ab('0x3a')](_0x36414c[_0x99ab('0x2f')],_0x2efec3[_0x99ab('0x31')]),_0x4ce5ce);if(_0x36414c['query']['filter']){_0x970ce7[_0x99ab('0x39')]=_[_0x99ab('0x3b')](_0x970ce7['where'],{'$or':_[_0x99ab('0x2b')](_0x4ce5ce,function(_0x41a54d){if(_0x41a54d[_0x99ab('0x2e')]!=='VIRTUAL'){var _0x285a0d={};_0x285a0d[_0x41a54d[_0x99ab('0x28')]]={'$like':'%'+_0x36414c[_0x99ab('0x2f')][_0x99ab('0x3c')]+'%'};return _0x285a0d;}})});}_0x970ce7=_[_0x99ab('0x3b')]({},_0x970ce7,_0x36414c['options']);var _0xcfba5a={'where':_0x970ce7[_0x99ab('0x39')]};return db['ServicenowField'][_0x99ab('0x1b')](_0xcfba5a)['then'](function(_0xb62fd6){_0xe3945b[_0x99ab('0x1b')]=_0xb62fd6;if(_0x36414c[_0x99ab('0x2f')][_0x99ab('0x3d')]){_0x970ce7[_0x99ab('0x3e')]=[{'all':!![]}];}return db[_0x99ab('0x2c')][_0x99ab('0x3f')](_0x970ce7);})[_0x99ab('0x24')](function(_0x7c7ac8){_0xe3945b[_0x99ab('0x40')]=_0x7c7ac8;return _0xe3945b;})['then'](respondWithFilteredResult(_0x45d50e,_0x970ce7))[_0x99ab('0x41')](handleError(_0x45d50e,null));};exports[_0x99ab('0x42')]=function(_0x4e6a11,_0x13c94f){var _0x5c6f5f={'raw':!![],'where':{'id':_0x4e6a11['params']['id']}},_0x165411={};_0x165411[_0x99ab('0x33')]=_[_0x99ab('0x30')](db[_0x99ab('0x2c')][_0x99ab('0x43')]);_0x165411['query']=_[_0x99ab('0x30')](_0x4e6a11[_0x99ab('0x2f')]);_0x165411[_0x99ab('0x31')]=_[_0x99ab('0x32')](_0x165411[_0x99ab('0x33')],_0x165411[_0x99ab('0x2f')]);_0x5c6f5f[_0x99ab('0x34')]=_[_0x99ab('0x32')](_0x165411[_0x99ab('0x33')],qs[_0x99ab('0x35')](_0x4e6a11[_0x99ab('0x2f')][_0x99ab('0x35')]));_0x5c6f5f[_0x99ab('0x34')]=_0x5c6f5f[_0x99ab('0x34')][_0x99ab('0x36')]?_0x5c6f5f['attributes']:_0x165411[_0x99ab('0x33')];if(_0x4e6a11[_0x99ab('0x2f')]['includeAll']){_0x5c6f5f[_0x99ab('0x3e')]=[{'all':!![]}];}_0x5c6f5f=_[_0x99ab('0x3b')]({},_0x5c6f5f,_0x4e6a11[_0x99ab('0x44')]);return db[_0x99ab('0x2c')][_0x99ab('0x45')](_0x5c6f5f)[_0x99ab('0x24')](handleEntityNotFound(_0x13c94f,null))[_0x99ab('0x24')](respondWithResult(_0x13c94f,null))[_0x99ab('0x41')](handleError(_0x13c94f,null));};exports[_0x99ab('0x46')]=function(_0x104657,_0x1c4442){return db['ServicenowField'][_0x99ab('0x46')](_0x104657[_0x99ab('0x47')],{})[_0x99ab('0x24')](respondWithResult(_0x1c4442,0xc9))[_0x99ab('0x41')](handleError(_0x1c4442,null));};exports['update']=function(_0x520420,_0x162867){if(_0x520420['body']['id']){delete _0x520420[_0x99ab('0x47')]['id'];}return db[_0x99ab('0x2c')][_0x99ab('0x45')]({'where':{'id':_0x520420[_0x99ab('0x48')]['id']}})[_0x99ab('0x24')](handleEntityNotFound(_0x162867,null))[_0x99ab('0x24')](saveUpdates(_0x520420[_0x99ab('0x47')],null))['then'](respondWithResult(_0x162867,null))[_0x99ab('0x41')](handleError(_0x162867,null));};exports[_0x99ab('0x25')]=function(_0x78eb5e,_0x436f84){return db[_0x99ab('0x2c')][_0x99ab('0x45')]({'where':{'id':_0x78eb5e[_0x99ab('0x48')]['id']}})[_0x99ab('0x24')](handleEntityNotFound(_0x436f84,null))[_0x99ab('0x24')](removeEntity(_0x436f84,null))[_0x99ab('0x41')](handleError(_0x436f84,null));};