e6d1c27d73fb6aae991f4c9eb414af30e5b89976
[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 _0xb4f7=['../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','apply','save','update','then','destroy','stack','name','send','index','map','ServicenowField','rawAttributes','fieldName','type','key','query','keys','filters','intersection','attributes','model','fields','length','nolimit','sort','where','pick','VIRTUAL','filter','merge','options','include','findAll','catch','show','includeAll','find','create','body','params','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis'];(function(_0x210727,_0x220396){var _0x1f40ef=function(_0x4a6780){while(--_0x4a6780){_0x210727['push'](_0x210727['shift']());}};_0x1f40ef(++_0x220396);}(_0xb4f7,0x7e));var _0x7b4f=function(_0xcaaec0,_0x253fb3){_0xcaaec0=_0xcaaec0-0x0;var _0x1e6ae4=_0xb4f7[_0xcaaec0];return _0x1e6ae4;};'use strict';var emlformat=require(_0x7b4f('0x0'));var rimraf=require(_0x7b4f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7b4f('0x2'));var rp=require(_0x7b4f('0x3'));var moment=require(_0x7b4f('0x4'));var BPromise=require(_0x7b4f('0x5'));var Mustache=require(_0x7b4f('0x6'));var util=require('util');var path=require(_0x7b4f('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x7b4f('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x7b4f('0x9'));var crypto=require(_0x7b4f('0xa'));var jsforce=require(_0x7b4f('0xb'));var deskjs=require(_0x7b4f('0xc'));var toCsv=require('to-csv');var querystring=require(_0x7b4f('0xd'));var Papa=require(_0x7b4f('0xe'));var Redis=require(_0x7b4f('0xf'));var authService=require(_0x7b4f('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x7b4f('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7b4f('0x12'))('api');var utils=require('../../config/utils');var config=require(_0x7b4f('0x13'));var licenseUtil=require(_0x7b4f('0x14'));var db=require(_0x7b4f('0x15'))['db'];function respondWithStatusCode(_0x1668ec,_0x388559){_0x388559=_0x388559||0xcc;return function(_0x568d40){if(_0x568d40){return _0x1668ec[_0x7b4f('0x16')](_0x388559);}return _0x1668ec[_0x7b4f('0x17')](_0x388559)[_0x7b4f('0x18')]();};}function respondWithResult(_0x146d31,_0x1715eb){_0x1715eb=_0x1715eb||0xc8;return function(_0x4e80d5){if(_0x4e80d5){return _0x146d31[_0x7b4f('0x17')](_0x1715eb)[_0x7b4f('0x19')](_0x4e80d5);}};}function respondWithFilteredResult(_0x48ffdf,_0x4536e3){return function(_0x7a8bc3){if(_0x7a8bc3){var _0x3c6f9a=typeof _0x4536e3[_0x7b4f('0x1a')]===_0x7b4f('0x1b')&&typeof _0x4536e3['limit']===_0x7b4f('0x1b');var _0x509520=_0x7a8bc3[_0x7b4f('0x1c')];var _0x31c13f=_0x3c6f9a?0x0:_0x4536e3[_0x7b4f('0x1a')];var _0x329e99=_0x3c6f9a?_0x7a8bc3[_0x7b4f('0x1c')]:_0x4536e3[_0x7b4f('0x1a')]+_0x4536e3[_0x7b4f('0x1d')];var _0x53cf9c;if(_0x329e99>=_0x509520){_0x329e99=_0x509520;_0x53cf9c=0xc8;}else{_0x53cf9c=0xce;}_0x48ffdf['status'](_0x53cf9c);return _0x48ffdf[_0x7b4f('0x1e')]('Content-Range',_0x31c13f+'-'+_0x329e99+'/'+_0x509520)['json'](_0x7a8bc3);}return null;};}function patchUpdates(_0x320dbe){return function(_0xae0bd1){try{jsonpatch[_0x7b4f('0x1f')](_0xae0bd1,_0x320dbe,!![]);}catch(_0x3b5e8a){return BPromise['reject'](_0x3b5e8a);}return _0xae0bd1[_0x7b4f('0x20')]();};}function saveUpdates(_0x1de13a,_0x1e821f){return function(_0x2e2d0d){if(_0x2e2d0d){return _0x2e2d0d[_0x7b4f('0x21')](_0x1de13a)[_0x7b4f('0x22')](function(_0x1cd4fa){return _0x1cd4fa;});}return null;};}function removeEntity(_0x3a351c,_0xc7bdab){return function(_0x5e0e9b){if(_0x5e0e9b){return _0x5e0e9b[_0x7b4f('0x23')]()[_0x7b4f('0x22')](function(){_0x3a351c['status'](0xcc)[_0x7b4f('0x18')]();});}};}function handleEntityNotFound(_0x18cd2c,_0x1cdb52){return function(_0x1be8a1){if(!_0x1be8a1){_0x18cd2c[_0x7b4f('0x16')](0x194);}return _0x1be8a1;};}function handleError(_0x662126,_0xedd051){_0xedd051=_0xedd051||0x1f4;return function(_0x33f0b1){logger['error'](_0x33f0b1[_0x7b4f('0x24')]);if(_0x33f0b1[_0x7b4f('0x25')]){delete _0x33f0b1['name'];}_0x662126['status'](_0xedd051)[_0x7b4f('0x26')](_0x33f0b1);};}exports[_0x7b4f('0x27')]=function(_0x136f9f,_0x132bc){var _0x3ce2d7={},_0x45ab10={},_0x3eb260={'count':0x0,'rows':[]};var _0x221357=_[_0x7b4f('0x28')](db[_0x7b4f('0x29')][_0x7b4f('0x2a')],function(_0x527a0a){return{'name':_0x527a0a[_0x7b4f('0x2b')],'type':_0x527a0a[_0x7b4f('0x2c')][_0x7b4f('0x2d')]};});_0x45ab10['model']=_[_0x7b4f('0x28')](_0x221357,_0x7b4f('0x25'));_0x45ab10[_0x7b4f('0x2e')]=_[_0x7b4f('0x2f')](_0x136f9f[_0x7b4f('0x2e')]);_0x45ab10[_0x7b4f('0x30')]=_[_0x7b4f('0x31')](_0x45ab10['model'],_0x45ab10[_0x7b4f('0x2e')]);_0x3ce2d7[_0x7b4f('0x32')]=_[_0x7b4f('0x31')](_0x45ab10[_0x7b4f('0x33')],qs[_0x7b4f('0x34')](_0x136f9f[_0x7b4f('0x2e')][_0x7b4f('0x34')]));_0x3ce2d7[_0x7b4f('0x32')]=_0x3ce2d7[_0x7b4f('0x32')][_0x7b4f('0x35')]?_0x3ce2d7['attributes']:_0x45ab10[_0x7b4f('0x33')];if(!_0x136f9f[_0x7b4f('0x2e')]['hasOwnProperty'](_0x7b4f('0x36'))){_0x3ce2d7['limit']=qs[_0x7b4f('0x1d')](_0x136f9f[_0x7b4f('0x2e')][_0x7b4f('0x1d')]);_0x3ce2d7[_0x7b4f('0x1a')]=qs['offset'](_0x136f9f[_0x7b4f('0x2e')][_0x7b4f('0x1a')]);}_0x3ce2d7['order']=qs['sort'](_0x136f9f[_0x7b4f('0x2e')][_0x7b4f('0x37')]);_0x3ce2d7[_0x7b4f('0x38')]=qs[_0x7b4f('0x30')](_[_0x7b4f('0x39')](_0x136f9f[_0x7b4f('0x2e')],_0x45ab10[_0x7b4f('0x30')]),_0x221357);if(_0x136f9f[_0x7b4f('0x2e')]['filter']){_0x3ce2d7[_0x7b4f('0x38')]=_['merge'](_0x3ce2d7['where'],{'$or':_['map'](_0x221357,function(_0x202c97){if(_0x202c97[_0x7b4f('0x2c')]!==_0x7b4f('0x3a')){var _0xbc7364={};_0xbc7364[_0x202c97[_0x7b4f('0x25')]]={'$like':'%'+_0x136f9f['query'][_0x7b4f('0x3b')]+'%'};return _0xbc7364;}})});}_0x3ce2d7=_[_0x7b4f('0x3c')]({},_0x3ce2d7,_0x136f9f[_0x7b4f('0x3d')]);var _0x3aedcb={'where':_0x3ce2d7[_0x7b4f('0x38')]};return db[_0x7b4f('0x29')]['count'](_0x3aedcb)[_0x7b4f('0x22')](function(_0x1e7dbc){_0x3eb260[_0x7b4f('0x1c')]=_0x1e7dbc;if(_0x136f9f['query']['includeAll']){_0x3ce2d7[_0x7b4f('0x3e')]=[{'all':!![]}];}return db[_0x7b4f('0x29')][_0x7b4f('0x3f')](_0x3ce2d7);})[_0x7b4f('0x22')](function(_0x44a024){_0x3eb260['rows']=_0x44a024;return _0x3eb260;})['then'](respondWithFilteredResult(_0x132bc,_0x3ce2d7))[_0x7b4f('0x40')](handleError(_0x132bc,null));};exports[_0x7b4f('0x41')]=function(_0x48ff73,_0x413f61){var _0x271814={'raw':!![],'where':{'id':_0x48ff73['params']['id']}},_0x4ad0ee={};_0x4ad0ee[_0x7b4f('0x33')]=_[_0x7b4f('0x2f')](db[_0x7b4f('0x29')]['rawAttributes']);_0x4ad0ee[_0x7b4f('0x2e')]=_['keys'](_0x48ff73['query']);_0x4ad0ee[_0x7b4f('0x30')]=_['intersection'](_0x4ad0ee[_0x7b4f('0x33')],_0x4ad0ee[_0x7b4f('0x2e')]);_0x271814[_0x7b4f('0x32')]=_[_0x7b4f('0x31')](_0x4ad0ee[_0x7b4f('0x33')],qs['fields'](_0x48ff73['query'][_0x7b4f('0x34')]));_0x271814['attributes']=_0x271814[_0x7b4f('0x32')][_0x7b4f('0x35')]?_0x271814[_0x7b4f('0x32')]:_0x4ad0ee[_0x7b4f('0x33')];if(_0x48ff73[_0x7b4f('0x2e')][_0x7b4f('0x42')]){_0x271814[_0x7b4f('0x3e')]=[{'all':!![]}];}_0x271814=_[_0x7b4f('0x3c')]({},_0x271814,_0x48ff73[_0x7b4f('0x3d')]);return db[_0x7b4f('0x29')][_0x7b4f('0x43')](_0x271814)[_0x7b4f('0x22')](handleEntityNotFound(_0x413f61,null))[_0x7b4f('0x22')](respondWithResult(_0x413f61,null))[_0x7b4f('0x40')](handleError(_0x413f61,null));};exports['create']=function(_0x25bc2c,_0x527ced){return db['ServicenowField'][_0x7b4f('0x44')](_0x25bc2c['body'],{})[_0x7b4f('0x22')](respondWithResult(_0x527ced,0xc9))[_0x7b4f('0x40')](handleError(_0x527ced,null));};exports[_0x7b4f('0x21')]=function(_0x52a188,_0x2f4794){if(_0x52a188[_0x7b4f('0x45')]['id']){delete _0x52a188[_0x7b4f('0x45')]['id'];}return db[_0x7b4f('0x29')][_0x7b4f('0x43')]({'where':{'id':_0x52a188[_0x7b4f('0x46')]['id']}})['then'](handleEntityNotFound(_0x2f4794,null))[_0x7b4f('0x22')](saveUpdates(_0x52a188[_0x7b4f('0x45')],null))[_0x7b4f('0x22')](respondWithResult(_0x2f4794,null))[_0x7b4f('0x40')](handleError(_0x2f4794,null));};exports['destroy']=function(_0x3ba768,_0x3906ec){return db[_0x7b4f('0x29')][_0x7b4f('0x43')]({'where':{'id':_0x3ba768[_0x7b4f('0x46')]['id']}})['then'](handleEntityNotFound(_0x3906ec,null))[_0x7b4f('0x22')](removeEntity(_0x3906ec,null))[_0x7b4f('0x40')](handleError(_0x3906ec,null));};