5804b444f6c46ccf2dbd39db474d249fc01ac200
[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 _0x1f76=['../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','Content-Range','json','apply','reject','save','update','then','error','stack','name','index','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','limit','sort','where','filter','merge','map','VIRTUAL','options','ServicenowField','includeAll','include','rows','catch','params','rawAttributes','length','find','body','destroy','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils'];(function(_0xe0065c,_0x853b78){var _0xc816fe=function(_0x1a7144){while(--_0x1a7144){_0xe0065c['push'](_0xe0065c['shift']());}};_0xc816fe(++_0x853b78);}(_0x1f76,0xb8));var _0x61f7=function(_0x337c21,_0x220df7){_0x337c21=_0x337c21-0x0;var _0x56082a=_0x1f76[_0x337c21];return _0x56082a;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x61f7('0x0'));var zipdir=require(_0x61f7('0x1'));var jsonpatch=require(_0x61f7('0x2'));var rp=require(_0x61f7('0x3'));var moment=require(_0x61f7('0x4'));var BPromise=require(_0x61f7('0x5'));var Mustache=require(_0x61f7('0x6'));var util=require('util');var path=require('path');var sox=require(_0x61f7('0x7'));var csv=require(_0x61f7('0x8'));var ejs=require(_0x61f7('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x61f7('0xa'));var squel=require(_0x61f7('0xb'));var crypto=require(_0x61f7('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x61f7('0xd'));var toCsv=require(_0x61f7('0x8'));var querystring=require(_0x61f7('0xe'));var Papa=require(_0x61f7('0xf'));var Redis=require(_0x61f7('0x10'));var authService=require(_0x61f7('0x11'));var qs=require(_0x61f7('0x12'));var as=require(_0x61f7('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x61f7('0x14'))(_0x61f7('0x15'));var utils=require(_0x61f7('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x61f7('0x17'));var db=require(_0x61f7('0x18'))['db'];function respondWithStatusCode(_0x13aa8e,_0x2914f4){_0x2914f4=_0x2914f4||0xcc;return function(_0x1d4c34){if(_0x1d4c34){return _0x13aa8e[_0x61f7('0x19')](_0x2914f4);}return _0x13aa8e[_0x61f7('0x1a')](_0x2914f4)[_0x61f7('0x1b')]();};}function respondWithResult(_0x4a14e3,_0x480de1){_0x480de1=_0x480de1||0xc8;return function(_0x26e028){if(_0x26e028){return _0x4a14e3[_0x61f7('0x1a')](_0x480de1)['json'](_0x26e028);}};}function respondWithFilteredResult(_0x4ab59b,_0x3a7a45){return function(_0x13d419){if(_0x13d419){var _0x1af427=_0x13d419[_0x61f7('0x1c')],_0x518399=_0x3a7a45[_0x61f7('0x1d')],_0x242156=_0x3a7a45['offset']+_0x3a7a45['limit'],_0x41d90d;if(_0x242156>=_0x1af427){_0x242156=_0x1af427;_0x41d90d=0xc8;}else{_0x41d90d=0xce;}_0x4ab59b[_0x61f7('0x1a')](_0x41d90d);return _0x4ab59b['set'](_0x61f7('0x1e'),_0x518399+'-'+_0x242156+'/'+_0x1af427)[_0x61f7('0x1f')](_0x13d419);}return null;};}function patchUpdates(_0x1b755f){return function(_0x58a1b4){try{jsonpatch[_0x61f7('0x20')](_0x58a1b4,_0x1b755f,!![]);}catch(_0x40753a){return BPromise[_0x61f7('0x21')](_0x40753a);}return _0x58a1b4[_0x61f7('0x22')]();};}function saveUpdates(_0x591ed4,_0x267eee){return function(_0x58614a){if(_0x58614a){return _0x58614a[_0x61f7('0x23')](_0x591ed4)['then'](function(_0x39529e){return _0x39529e;});}return null;};}function removeEntity(_0xaf852d,_0x3b3f88){return function(_0x5a0674){if(_0x5a0674){return _0x5a0674['destroy']()[_0x61f7('0x24')](function(){_0xaf852d[_0x61f7('0x1a')](0xcc)[_0x61f7('0x1b')]();});}};}function handleEntityNotFound(_0x1d914b,_0xd4b676){return function(_0x34c240){if(!_0x34c240){_0x1d914b[_0x61f7('0x19')](0x194);}return _0x34c240;};}function handleError(_0x570753,_0x561116){_0x561116=_0x561116||0x1f4;return function(_0x2eb545){logger[_0x61f7('0x25')](_0x2eb545[_0x61f7('0x26')]);if(_0x2eb545[_0x61f7('0x27')]){delete _0x2eb545[_0x61f7('0x27')];}_0x570753[_0x61f7('0x1a')](_0x561116)['send'](_0x2eb545);};}exports[_0x61f7('0x28')]=function(_0x2e046b,_0x5604d3){var _0x5e0196={},_0x58f9e9={},_0x3f03b2={'count':0x0,'rows':[]};var _0x1b1aa1=_['map'](db['ServicenowField']['rawAttributes'],function(_0x1b4cc4){return{'name':_0x1b4cc4['fieldName'],'type':_0x1b4cc4['type']['key']};});_0x58f9e9[_0x61f7('0x29')]=_['map'](_0x1b1aa1,_0x61f7('0x27'));_0x58f9e9[_0x61f7('0x2a')]=_[_0x61f7('0x2b')](_0x2e046b[_0x61f7('0x2a')]);_0x58f9e9[_0x61f7('0x2c')]=_[_0x61f7('0x2d')](_0x58f9e9[_0x61f7('0x29')],_0x58f9e9[_0x61f7('0x2a')]);_0x5e0196['attributes']=_['intersection'](_0x58f9e9[_0x61f7('0x29')],qs['fields'](_0x2e046b[_0x61f7('0x2a')][_0x61f7('0x2e')]));_0x5e0196[_0x61f7('0x2f')]=_0x5e0196[_0x61f7('0x2f')]['length']?_0x5e0196[_0x61f7('0x2f')]:_0x58f9e9[_0x61f7('0x29')];if(!_0x2e046b[_0x61f7('0x2a')][_0x61f7('0x30')](_0x61f7('0x31'))){_0x5e0196[_0x61f7('0x32')]=qs['limit'](_0x2e046b['query'][_0x61f7('0x32')]);_0x5e0196['offset']=qs['offset'](_0x2e046b['query'][_0x61f7('0x1d')]);}_0x5e0196['order']=qs[_0x61f7('0x33')](_0x2e046b[_0x61f7('0x2a')]['sort']);_0x5e0196[_0x61f7('0x34')]=qs[_0x61f7('0x2c')](_['pick'](_0x2e046b[_0x61f7('0x2a')],_0x58f9e9[_0x61f7('0x2c')]),_0x1b1aa1);if(_0x2e046b[_0x61f7('0x2a')][_0x61f7('0x35')]){_0x5e0196[_0x61f7('0x34')]=_[_0x61f7('0x36')](_0x5e0196[_0x61f7('0x34')],{'$or':_[_0x61f7('0x37')](_0x1b1aa1,function(_0x18b10e){if(_0x18b10e['type']!==_0x61f7('0x38')){var _0x35783e={};_0x35783e[_0x18b10e[_0x61f7('0x27')]]={'$like':'%'+_0x2e046b[_0x61f7('0x2a')]['filter']+'%'};return _0x35783e;}})});}_0x5e0196=_['merge']({},_0x5e0196,_0x2e046b[_0x61f7('0x39')]);var _0x57091a={'where':_0x5e0196[_0x61f7('0x34')]};return db[_0x61f7('0x3a')][_0x61f7('0x1c')](_0x57091a)['then'](function(_0x550a5d){_0x3f03b2[_0x61f7('0x1c')]=_0x550a5d;if(_0x2e046b[_0x61f7('0x2a')][_0x61f7('0x3b')]){_0x5e0196[_0x61f7('0x3c')]=[{'all':!![]}];}return db[_0x61f7('0x3a')]['findAll'](_0x5e0196);})['then'](function(_0x1f5d76){_0x3f03b2[_0x61f7('0x3d')]=_0x1f5d76;return _0x3f03b2;})[_0x61f7('0x24')](respondWithFilteredResult(_0x5604d3,_0x5e0196))[_0x61f7('0x3e')](handleError(_0x5604d3,null));};exports['show']=function(_0x344de1,_0x1e3115){var _0x276a99={'raw':!![],'where':{'id':_0x344de1[_0x61f7('0x3f')]['id']}},_0x3c1cb5={};_0x3c1cb5[_0x61f7('0x29')]=_[_0x61f7('0x2b')](db[_0x61f7('0x3a')][_0x61f7('0x40')]);_0x3c1cb5['query']=_['keys'](_0x344de1[_0x61f7('0x2a')]);_0x3c1cb5[_0x61f7('0x2c')]=_[_0x61f7('0x2d')](_0x3c1cb5[_0x61f7('0x29')],_0x3c1cb5[_0x61f7('0x2a')]);_0x276a99[_0x61f7('0x2f')]=_[_0x61f7('0x2d')](_0x3c1cb5[_0x61f7('0x29')],qs[_0x61f7('0x2e')](_0x344de1[_0x61f7('0x2a')]['fields']));_0x276a99[_0x61f7('0x2f')]=_0x276a99[_0x61f7('0x2f')][_0x61f7('0x41')]?_0x276a99[_0x61f7('0x2f')]:_0x3c1cb5[_0x61f7('0x29')];if(_0x344de1[_0x61f7('0x2a')][_0x61f7('0x3b')]){_0x276a99[_0x61f7('0x3c')]=[{'all':!![]}];}_0x276a99=_['merge']({},_0x276a99,_0x344de1[_0x61f7('0x39')]);return db[_0x61f7('0x3a')][_0x61f7('0x42')](_0x276a99)[_0x61f7('0x24')](handleEntityNotFound(_0x1e3115,null))[_0x61f7('0x24')](respondWithResult(_0x1e3115,null))[_0x61f7('0x3e')](handleError(_0x1e3115,null));};exports['create']=function(_0xf7dc2,_0xd9170b){return db[_0x61f7('0x3a')]['create'](_0xf7dc2[_0x61f7('0x43')],{})['then'](respondWithResult(_0xd9170b,0xc9))[_0x61f7('0x3e')](handleError(_0xd9170b,null));};exports[_0x61f7('0x23')]=function(_0x5e6ee4,_0x515222){if(_0x5e6ee4[_0x61f7('0x43')]['id']){delete _0x5e6ee4['body']['id'];}return db[_0x61f7('0x3a')]['find']({'where':{'id':_0x5e6ee4['params']['id']}})['then'](handleEntityNotFound(_0x515222,null))['then'](saveUpdates(_0x5e6ee4[_0x61f7('0x43')],null))[_0x61f7('0x24')](respondWithResult(_0x515222,null))[_0x61f7('0x3e')](handleError(_0x515222,null));};exports[_0x61f7('0x44')]=function(_0x5e5f8c,_0x154631){return db[_0x61f7('0x3a')][_0x61f7('0x42')]({'where':{'id':_0x5e5f8c['params']['id']}})[_0x61f7('0x24')](handleEntityNotFound(_0x154631,null))[_0x61f7('0x24')](removeEntity(_0x154631,null))[_0x61f7('0x3e')](handleError(_0x154631,null));};