c62acd166aefa7fc919a5980e47abd276988aedd
[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 _0x3ace=['bluebird','mustache','path','ejs','squel','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','Content-Range','apply','reject','save','then','error','stack','name','send','map','ServicenowField','rawAttributes','fieldName','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','type','VIRTUAL','count','include','rows','catch','show','params','includeAll','options','create','body','update','find','destroy','eml-format','rimraf','zip-dir','moment'];(function(_0x3ebd50,_0x3e323a){var _0x43e065=function(_0x162da3){while(--_0x162da3){_0x3ebd50['push'](_0x3ebd50['shift']());}};_0x43e065(++_0x3e323a);}(_0x3ace,0xda));var _0xe3ac=function(_0x3589b8,_0x5ae6c9){_0x3589b8=_0x3589b8-0x0;var _0x19edc2=_0x3ace[_0x3589b8];return _0x19edc2;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xe3ac('0x0'));var rimraf=require(_0xe3ac('0x1'));var zipdir=require(_0xe3ac('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xe3ac('0x3'));var BPromise=require(_0xe3ac('0x4'));var Mustache=require(_0xe3ac('0x5'));var util=require('util');var path=require(_0xe3ac('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xe3ac('0x7'));var fs=require('fs');var _=require('lodash');var squel=require(_0xe3ac('0x8'));var crypto=require('crypto');var jsforce=require(_0xe3ac('0x9'));var deskjs=require(_0xe3ac('0xa'));var toCsv=require(_0xe3ac('0xb'));var querystring=require(_0xe3ac('0xc'));var Papa=require(_0xe3ac('0xd'));var Redis=require('ioredis');var authService=require(_0xe3ac('0xe'));var qs=require(_0xe3ac('0xf'));var as=require(_0xe3ac('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xe3ac('0x11'))(_0xe3ac('0x12'));var utils=require(_0xe3ac('0x13'));var config=require(_0xe3ac('0x14'));var licenseUtil=require(_0xe3ac('0x15'));var db=require(_0xe3ac('0x16'))['db'];function respondWithStatusCode(_0x17b8ff,_0x468285){_0x468285=_0x468285||0xcc;return function(_0x3da97e){if(_0x3da97e){return _0x17b8ff[_0xe3ac('0x17')](_0x468285);}return _0x17b8ff[_0xe3ac('0x18')](_0x468285)[_0xe3ac('0x19')]();};}function respondWithResult(_0x44f99f,_0x186e03){_0x186e03=_0x186e03||0xc8;return function(_0x28e237){if(_0x28e237){return _0x44f99f[_0xe3ac('0x18')](_0x186e03)[_0xe3ac('0x1a')](_0x28e237);}};}function respondWithFilteredResult(_0x4c69c6,_0x1e4109){return function(_0xd8ccd8){if(_0xd8ccd8){var _0x3d8377=_0xd8ccd8['count'],_0x5a5ecc=_0x1e4109[_0xe3ac('0x1b')],_0x4fd50a=_0x1e4109[_0xe3ac('0x1b')]+_0x1e4109['limit'],_0x476bd6;if(_0x4fd50a>=_0x3d8377){_0x4fd50a=_0x3d8377;_0x476bd6=0xc8;}else{_0x476bd6=0xce;}_0x4c69c6[_0xe3ac('0x18')](_0x476bd6);return _0x4c69c6['set'](_0xe3ac('0x1c'),_0x5a5ecc+'-'+_0x4fd50a+'/'+_0x3d8377)['json'](_0xd8ccd8);}return null;};}function patchUpdates(_0x22f661){return function(_0x110ec9){try{jsonpatch[_0xe3ac('0x1d')](_0x110ec9,_0x22f661,!![]);}catch(_0x1eabfb){return BPromise[_0xe3ac('0x1e')](_0x1eabfb);}return _0x110ec9[_0xe3ac('0x1f')]();};}function saveUpdates(_0x5635b7,_0x383395){return function(_0x2d9357){if(_0x2d9357){return _0x2d9357['update'](_0x5635b7)[_0xe3ac('0x20')](function(_0x2ba0d4){return _0x2ba0d4;});}return null;};}function removeEntity(_0x1cd1d9,_0x1b9983){return function(_0x36bb0a){if(_0x36bb0a){return _0x36bb0a['destroy']()[_0xe3ac('0x20')](function(){_0x1cd1d9[_0xe3ac('0x18')](0xcc)[_0xe3ac('0x19')]();});}};}function handleEntityNotFound(_0x11b2d8,_0x4bd5e3){return function(_0x20a8ac){if(!_0x20a8ac){_0x11b2d8[_0xe3ac('0x17')](0x194);}return _0x20a8ac;};}function handleError(_0x4da4b3,_0x3a5952){_0x3a5952=_0x3a5952||0x1f4;return function(_0x55f658){logger[_0xe3ac('0x21')](_0x55f658[_0xe3ac('0x22')]);if(_0x55f658[_0xe3ac('0x23')]){delete _0x55f658[_0xe3ac('0x23')];}_0x4da4b3[_0xe3ac('0x18')](_0x3a5952)[_0xe3ac('0x24')](_0x55f658);};}exports['index']=function(_0x2ce196,_0x51b2ec){var _0x3ab2ec={},_0x1090d2={},_0x2cf797={'count':0x0,'rows':[]};var _0x4dd764=_[_0xe3ac('0x25')](db[_0xe3ac('0x26')][_0xe3ac('0x27')],function(_0x3c9c36){return{'name':_0x3c9c36[_0xe3ac('0x28')],'type':_0x3c9c36['type'][_0xe3ac('0x29')]};});_0x1090d2[_0xe3ac('0x2a')]=_[_0xe3ac('0x25')](_0x4dd764,'name');_0x1090d2[_0xe3ac('0x2b')]=_[_0xe3ac('0x2c')](_0x2ce196['query']);_0x1090d2[_0xe3ac('0x2d')]=_[_0xe3ac('0x2e')](_0x1090d2[_0xe3ac('0x2a')],_0x1090d2['query']);_0x3ab2ec['attributes']=_[_0xe3ac('0x2e')](_0x1090d2[_0xe3ac('0x2a')],qs[_0xe3ac('0x2f')](_0x2ce196[_0xe3ac('0x2b')][_0xe3ac('0x2f')]));_0x3ab2ec[_0xe3ac('0x30')]=_0x3ab2ec[_0xe3ac('0x30')][_0xe3ac('0x31')]?_0x3ab2ec[_0xe3ac('0x30')]:_0x1090d2['model'];if(!_0x2ce196[_0xe3ac('0x2b')][_0xe3ac('0x32')](_0xe3ac('0x33'))){_0x3ab2ec[_0xe3ac('0x34')]=qs[_0xe3ac('0x34')](_0x2ce196[_0xe3ac('0x2b')]['limit']);_0x3ab2ec[_0xe3ac('0x1b')]=qs[_0xe3ac('0x1b')](_0x2ce196[_0xe3ac('0x2b')][_0xe3ac('0x1b')]);}_0x3ab2ec[_0xe3ac('0x35')]=qs[_0xe3ac('0x36')](_0x2ce196[_0xe3ac('0x2b')]['sort']);_0x3ab2ec[_0xe3ac('0x37')]=qs[_0xe3ac('0x2d')](_[_0xe3ac('0x38')](_0x2ce196['query'],_0x1090d2[_0xe3ac('0x2d')]),_0x4dd764);if(_0x2ce196[_0xe3ac('0x2b')][_0xe3ac('0x39')]){_0x3ab2ec[_0xe3ac('0x37')]=_[_0xe3ac('0x3a')](_0x3ab2ec['where'],{'$or':_[_0xe3ac('0x25')](_0x4dd764,function(_0x4be11e){if(_0x4be11e[_0xe3ac('0x3b')]!==_0xe3ac('0x3c')){var _0x62e371={};_0x62e371[_0x4be11e[_0xe3ac('0x23')]]={'$like':'%'+_0x2ce196[_0xe3ac('0x2b')][_0xe3ac('0x39')]+'%'};return _0x62e371;}})});}_0x3ab2ec=_[_0xe3ac('0x3a')]({},_0x3ab2ec,_0x2ce196['options']);var _0x3a9018={'where':_0x3ab2ec[_0xe3ac('0x37')]};return db['ServicenowField'][_0xe3ac('0x3d')](_0x3a9018)[_0xe3ac('0x20')](function(_0x4f317c){_0x2cf797[_0xe3ac('0x3d')]=_0x4f317c;if(_0x2ce196[_0xe3ac('0x2b')]['includeAll']){_0x3ab2ec[_0xe3ac('0x3e')]=[{'all':!![]}];}return db['ServicenowField']['findAll'](_0x3ab2ec);})[_0xe3ac('0x20')](function(_0x308c12){_0x2cf797[_0xe3ac('0x3f')]=_0x308c12;return _0x2cf797;})['then'](respondWithFilteredResult(_0x51b2ec,_0x3ab2ec))[_0xe3ac('0x40')](handleError(_0x51b2ec,null));};exports[_0xe3ac('0x41')]=function(_0x13a455,_0x2d4053){var _0x185b95={'raw':!![],'where':{'id':_0x13a455[_0xe3ac('0x42')]['id']}},_0x1a26ce={};_0x1a26ce['model']=_[_0xe3ac('0x2c')](db['ServicenowField'][_0xe3ac('0x27')]);_0x1a26ce[_0xe3ac('0x2b')]=_[_0xe3ac('0x2c')](_0x13a455[_0xe3ac('0x2b')]);_0x1a26ce[_0xe3ac('0x2d')]=_[_0xe3ac('0x2e')](_0x1a26ce[_0xe3ac('0x2a')],_0x1a26ce[_0xe3ac('0x2b')]);_0x185b95['attributes']=_[_0xe3ac('0x2e')](_0x1a26ce[_0xe3ac('0x2a')],qs[_0xe3ac('0x2f')](_0x13a455['query'][_0xe3ac('0x2f')]));_0x185b95[_0xe3ac('0x30')]=_0x185b95['attributes']['length']?_0x185b95[_0xe3ac('0x30')]:_0x1a26ce[_0xe3ac('0x2a')];if(_0x13a455[_0xe3ac('0x2b')][_0xe3ac('0x43')]){_0x185b95['include']=[{'all':!![]}];}_0x185b95=_['merge']({},_0x185b95,_0x13a455[_0xe3ac('0x44')]);return db[_0xe3ac('0x26')]['find'](_0x185b95)[_0xe3ac('0x20')](handleEntityNotFound(_0x2d4053,null))[_0xe3ac('0x20')](respondWithResult(_0x2d4053,null))['catch'](handleError(_0x2d4053,null));};exports[_0xe3ac('0x45')]=function(_0x1b60e5,_0x24462b){return db[_0xe3ac('0x26')][_0xe3ac('0x45')](_0x1b60e5[_0xe3ac('0x46')],{})[_0xe3ac('0x20')](respondWithResult(_0x24462b,0xc9))['catch'](handleError(_0x24462b,null));};exports[_0xe3ac('0x47')]=function(_0x2f7031,_0x3ff4eb){if(_0x2f7031[_0xe3ac('0x46')]['id']){delete _0x2f7031[_0xe3ac('0x46')]['id'];}return db[_0xe3ac('0x26')][_0xe3ac('0x48')]({'where':{'id':_0x2f7031['params']['id']}})['then'](handleEntityNotFound(_0x3ff4eb,null))['then'](saveUpdates(_0x2f7031[_0xe3ac('0x46')],null))[_0xe3ac('0x20')](respondWithResult(_0x3ff4eb,null))[_0xe3ac('0x40')](handleError(_0x3ff4eb,null));};exports[_0xe3ac('0x49')]=function(_0x6c7c0a,_0xb50e50){return db['ServicenowField']['find']({'where':{'id':_0x6c7c0a[_0xe3ac('0x42')]['id']}})['then'](handleEntityNotFound(_0xb50e50,null))['then'](removeEntity(_0xb50e50,null))[_0xe3ac('0x40')](handleError(_0xb50e50,null));};