943405a9b791ad84838a987f472791fa8ad3af88
[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 _0x9bc7=['count','offset','limit','set','Content-Range','apply','save','update','then','destroy','error','stack','name','send','fieldName','type','model','map','keys','filters','intersection','attributes','fields','query','length','nolimit','order','filter','where','merge','VIRTUAL','options','ServicenowField','include','rows','catch','params','rawAttributes','find','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json'];(function(_0x397e5f,_0x454c8f){var _0x5302b8=function(_0x1a29ef){while(--_0x1a29ef){_0x397e5f['push'](_0x397e5f['shift']());}};_0x5302b8(++_0x454c8f);}(_0x9bc7,0x1cd));var _0x79bc=function(_0x3bf83f,_0x181cac){_0x3bf83f=_0x3bf83f-0x0;var _0x22c4a9=_0x9bc7[_0x3bf83f];return _0x22c4a9;};'use strict';var pdf=require(_0x79bc('0x0'));var emlformat=require(_0x79bc('0x1'));var rimraf=require(_0x79bc('0x2'));var zipdir=require(_0x79bc('0x3'));var jsonpatch=require(_0x79bc('0x4'));var rp=require(_0x79bc('0x5'));var moment=require(_0x79bc('0x6'));var BPromise=require(_0x79bc('0x7'));var Mustache=require(_0x79bc('0x8'));var util=require(_0x79bc('0x9'));var path=require('path');var sox=require(_0x79bc('0xa'));var csv=require(_0x79bc('0xb'));var ejs=require(_0x79bc('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0x79bc('0xd'));var crypto=require('crypto');var jsforce=require(_0x79bc('0xe'));var deskjs=require(_0x79bc('0xf'));var toCsv=require(_0x79bc('0xb'));var querystring=require(_0x79bc('0x10'));var Papa=require(_0x79bc('0x11'));var Redis=require('ioredis');var authService=require(_0x79bc('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x79bc('0x13'));var hardwareService=require(_0x79bc('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0x79bc('0x15'));var config=require(_0x79bc('0x16'));var licenseUtil=require(_0x79bc('0x17'));var db=require(_0x79bc('0x18'))['db'];function respondWithStatusCode(_0x174eff,_0x401de9){_0x401de9=_0x401de9||0xcc;return function(_0x29e987){if(_0x29e987){return _0x174eff[_0x79bc('0x19')](_0x401de9);}return _0x174eff['status'](_0x401de9)[_0x79bc('0x1a')]();};}function respondWithResult(_0x57530f,_0x404adf){_0x404adf=_0x404adf||0xc8;return function(_0x2ee065){if(_0x2ee065){return _0x57530f[_0x79bc('0x1b')](_0x404adf)[_0x79bc('0x1c')](_0x2ee065);}};}function respondWithFilteredResult(_0x564d68,_0x21cb53){return function(_0x3e4244){if(_0x3e4244){var _0x510906=_0x3e4244[_0x79bc('0x1d')],_0x1b3b2c=_0x21cb53['offset'],_0x561e9a=_0x21cb53[_0x79bc('0x1e')]+_0x21cb53[_0x79bc('0x1f')],_0x403ebe;if(_0x561e9a>=_0x510906){_0x561e9a=_0x510906;_0x403ebe=0xc8;}else{_0x403ebe=0xce;}_0x564d68[_0x79bc('0x1b')](_0x403ebe);return _0x564d68[_0x79bc('0x20')](_0x79bc('0x21'),_0x1b3b2c+'-'+_0x561e9a+'/'+_0x510906)['json'](_0x3e4244);}return null;};}function patchUpdates(_0x30e0fb){return function(_0x2f3b0c){try{jsonpatch[_0x79bc('0x22')](_0x2f3b0c,_0x30e0fb,!![]);}catch(_0x269d07){return BPromise['reject'](_0x269d07);}return _0x2f3b0c[_0x79bc('0x23')]();};}function saveUpdates(_0x52a423,_0x51282d){return function(_0xb7ab74){if(_0xb7ab74){return _0xb7ab74[_0x79bc('0x24')](_0x52a423)[_0x79bc('0x25')](function(_0x533720){return _0x533720;});}return null;};}function removeEntity(_0xc9c88a,_0x3cbe59){return function(_0x1a62fa){if(_0x1a62fa){return _0x1a62fa[_0x79bc('0x26')]()[_0x79bc('0x25')](function(){_0xc9c88a[_0x79bc('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5bc690,_0x307147){return function(_0x36da6f){if(!_0x36da6f){_0x5bc690[_0x79bc('0x19')](0x194);}return _0x36da6f;};}function handleError(_0x3a2467,_0x27b266){_0x27b266=_0x27b266||0x1f4;return function(_0x121a28){logger[_0x79bc('0x27')](_0x121a28[_0x79bc('0x28')]);if(_0x121a28[_0x79bc('0x29')]){delete _0x121a28[_0x79bc('0x29')];}_0x3a2467[_0x79bc('0x1b')](_0x27b266)[_0x79bc('0x2a')](_0x121a28);};}exports['index']=function(_0x4b3eb9,_0x32a531){var _0x18f21e={},_0x5bee88={},_0x1d6141={'count':0x0,'rows':[]};var _0x2aa24d=_['map'](db['ServicenowField']['rawAttributes'],function(_0x143bb3){return{'name':_0x143bb3[_0x79bc('0x2b')],'type':_0x143bb3[_0x79bc('0x2c')]['key']};});_0x5bee88[_0x79bc('0x2d')]=_[_0x79bc('0x2e')](_0x2aa24d,'name');_0x5bee88['query']=_[_0x79bc('0x2f')](_0x4b3eb9['query']);_0x5bee88[_0x79bc('0x30')]=_[_0x79bc('0x31')](_0x5bee88[_0x79bc('0x2d')],_0x5bee88['query']);_0x18f21e[_0x79bc('0x32')]=_['intersection'](_0x5bee88[_0x79bc('0x2d')],qs[_0x79bc('0x33')](_0x4b3eb9[_0x79bc('0x34')][_0x79bc('0x33')]));_0x18f21e[_0x79bc('0x32')]=_0x18f21e['attributes'][_0x79bc('0x35')]?_0x18f21e[_0x79bc('0x32')]:_0x5bee88[_0x79bc('0x2d')];if(!_0x4b3eb9[_0x79bc('0x34')]['hasOwnProperty'](_0x79bc('0x36'))){_0x18f21e[_0x79bc('0x1f')]=qs['limit'](_0x4b3eb9[_0x79bc('0x34')][_0x79bc('0x1f')]);_0x18f21e[_0x79bc('0x1e')]=qs['offset'](_0x4b3eb9[_0x79bc('0x34')][_0x79bc('0x1e')]);}_0x18f21e[_0x79bc('0x37')]=qs['sort'](_0x4b3eb9[_0x79bc('0x34')]['sort']);_0x18f21e['where']=qs[_0x79bc('0x30')](_['pick'](_0x4b3eb9[_0x79bc('0x34')],_0x5bee88[_0x79bc('0x30')]),_0x2aa24d);if(_0x4b3eb9[_0x79bc('0x34')][_0x79bc('0x38')]){_0x18f21e[_0x79bc('0x39')]=_[_0x79bc('0x3a')](_0x18f21e['where'],{'$or':_['map'](_0x2aa24d,function(_0x1dafbb){if(_0x1dafbb[_0x79bc('0x2c')]!==_0x79bc('0x3b')){var _0x510aae={};_0x510aae[_0x1dafbb[_0x79bc('0x29')]]={'$like':'%'+_0x4b3eb9['query']['filter']+'%'};return _0x510aae;}})});}_0x18f21e=_[_0x79bc('0x3a')]({},_0x18f21e,_0x4b3eb9[_0x79bc('0x3c')]);var _0xbb2ede={'where':_0x18f21e[_0x79bc('0x39')]};return db[_0x79bc('0x3d')][_0x79bc('0x1d')](_0xbb2ede)[_0x79bc('0x25')](function(_0x2f1141){_0x1d6141[_0x79bc('0x1d')]=_0x2f1141;if(_0x4b3eb9[_0x79bc('0x34')]['includeAll']){_0x18f21e[_0x79bc('0x3e')]=[{'all':!![]}];}return db[_0x79bc('0x3d')]['findAll'](_0x18f21e);})[_0x79bc('0x25')](function(_0x2576ac){_0x1d6141[_0x79bc('0x3f')]=_0x2576ac;return _0x1d6141;})[_0x79bc('0x25')](respondWithFilteredResult(_0x32a531,_0x18f21e))[_0x79bc('0x40')](handleError(_0x32a531,null));};exports['show']=function(_0x3da2d9,_0x3ea23c){var _0x3d96a4={'raw':!![],'where':{'id':_0x3da2d9[_0x79bc('0x41')]['id']}},_0x3b9494={};_0x3b9494[_0x79bc('0x2d')]=_[_0x79bc('0x2f')](db[_0x79bc('0x3d')][_0x79bc('0x42')]);_0x3b9494[_0x79bc('0x34')]=_[_0x79bc('0x2f')](_0x3da2d9['query']);_0x3b9494[_0x79bc('0x30')]=_[_0x79bc('0x31')](_0x3b9494[_0x79bc('0x2d')],_0x3b9494[_0x79bc('0x34')]);_0x3d96a4[_0x79bc('0x32')]=_[_0x79bc('0x31')](_0x3b9494[_0x79bc('0x2d')],qs[_0x79bc('0x33')](_0x3da2d9[_0x79bc('0x34')][_0x79bc('0x33')]));_0x3d96a4[_0x79bc('0x32')]=_0x3d96a4[_0x79bc('0x32')]['length']?_0x3d96a4[_0x79bc('0x32')]:_0x3b9494[_0x79bc('0x2d')];if(_0x3da2d9[_0x79bc('0x34')]['includeAll']){_0x3d96a4['include']=[{'all':!![]}];}_0x3d96a4=_[_0x79bc('0x3a')]({},_0x3d96a4,_0x3da2d9[_0x79bc('0x3c')]);return db[_0x79bc('0x3d')][_0x79bc('0x43')](_0x3d96a4)['then'](handleEntityNotFound(_0x3ea23c,null))[_0x79bc('0x25')](respondWithResult(_0x3ea23c,null))[_0x79bc('0x40')](handleError(_0x3ea23c,null));};exports['create']=function(_0x560ccf,_0x984270){return db[_0x79bc('0x3d')][_0x79bc('0x44')](_0x560ccf[_0x79bc('0x45')],{})[_0x79bc('0x25')](respondWithResult(_0x984270,0xc9))[_0x79bc('0x40')](handleError(_0x984270,null));};exports['update']=function(_0x519be4,_0x1e86cd){if(_0x519be4[_0x79bc('0x45')]['id']){delete _0x519be4[_0x79bc('0x45')]['id'];}return db[_0x79bc('0x3d')]['find']({'where':{'id':_0x519be4[_0x79bc('0x41')]['id']}})['then'](handleEntityNotFound(_0x1e86cd,null))[_0x79bc('0x25')](saveUpdates(_0x519be4[_0x79bc('0x45')],null))[_0x79bc('0x25')](respondWithResult(_0x1e86cd,null))['catch'](handleError(_0x1e86cd,null));};exports[_0x79bc('0x26')]=function(_0x43388d,_0x4c7d28){return db[_0x79bc('0x3d')][_0x79bc('0x43')]({'where':{'id':_0x43388d[_0x79bc('0x41')]['id']}})[_0x79bc('0x25')](handleEntityNotFound(_0x4c7d28,null))[_0x79bc('0x25')](removeEntity(_0x4c7d28,null))[_0x79bc('0x40')](handleError(_0x4c7d28,null));};