Built motion from commit (unavailable).|2.5.22
[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 _0xbf77=['create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','lodash','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','send','ServicenowField','rawAttributes','fieldName','type','key','model','map','name','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','params','fields','options','find'];(function(_0x58db4e,_0x439d8d){var _0x40139a=function(_0x34cae4){while(--_0x34cae4){_0x58db4e['push'](_0x58db4e['shift']());}};_0x40139a(++_0x439d8d);}(_0xbf77,0xec));var _0x7bf7=function(_0x273c39,_0x1052e6){_0x273c39=_0x273c39-0x0;var _0x46d6b5=_0xbf77[_0x273c39];return _0x46d6b5;};'use strict';var pdf=require(_0x7bf7('0x0'));var emlformat=require(_0x7bf7('0x1'));var rimraf=require(_0x7bf7('0x2'));var zipdir=require(_0x7bf7('0x3'));var jsonpatch=require(_0x7bf7('0x4'));var rp=require(_0x7bf7('0x5'));var moment=require(_0x7bf7('0x6'));var BPromise=require(_0x7bf7('0x7'));var Mustache=require('mustache');var util=require(_0x7bf7('0x8'));var path=require(_0x7bf7('0x9'));var sox=require(_0x7bf7('0xa'));var csv=require('to-csv');var ejs=require(_0x7bf7('0xb'));var fs=require('fs');var _=require(_0x7bf7('0xc'));var squel=require('squel');var crypto=require(_0x7bf7('0xd'));var jsforce=require(_0x7bf7('0xe'));var deskjs=require(_0x7bf7('0xf'));var toCsv=require(_0x7bf7('0x10'));var querystring=require('querystring');var Papa=require(_0x7bf7('0x11'));var Redis=require(_0x7bf7('0x12'));var authService=require(_0x7bf7('0x13'));var qs=require(_0x7bf7('0x14'));var as=require(_0x7bf7('0x15'));var hardwareService=require(_0x7bf7('0x16'));var logger=require(_0x7bf7('0x17'))(_0x7bf7('0x18'));var utils=require(_0x7bf7('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0x7bf7('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x358af0,_0x20b1e7){_0x20b1e7=_0x20b1e7||0xcc;return function(_0x4df560){if(_0x4df560){return _0x358af0[_0x7bf7('0x1b')](_0x20b1e7);}return _0x358af0[_0x7bf7('0x1c')](_0x20b1e7)[_0x7bf7('0x1d')]();};}function respondWithResult(_0x25417e,_0x3c204f){_0x3c204f=_0x3c204f||0xc8;return function(_0x16c12d){if(_0x16c12d){return _0x25417e[_0x7bf7('0x1c')](_0x3c204f)[_0x7bf7('0x1e')](_0x16c12d);}};}function respondWithFilteredResult(_0x22e730,_0x4f78f1){return function(_0x1f1ff4){if(_0x1f1ff4){var _0x1dba4d=_0x1f1ff4[_0x7bf7('0x1f')],_0x508562=_0x4f78f1[_0x7bf7('0x20')],_0x3882d1=_0x4f78f1[_0x7bf7('0x20')]+_0x4f78f1[_0x7bf7('0x21')],_0x2feb44;if(_0x3882d1>=_0x1dba4d){_0x3882d1=_0x1dba4d;_0x2feb44=0xc8;}else{_0x2feb44=0xce;}_0x22e730['status'](_0x2feb44);return _0x22e730[_0x7bf7('0x22')](_0x7bf7('0x23'),_0x508562+'-'+_0x3882d1+'/'+_0x1dba4d)[_0x7bf7('0x1e')](_0x1f1ff4);}return null;};}function patchUpdates(_0x3513b3){return function(_0x1bf1c1){try{jsonpatch[_0x7bf7('0x24')](_0x1bf1c1,_0x3513b3,!![]);}catch(_0x47057a){return BPromise[_0x7bf7('0x25')](_0x47057a);}return _0x1bf1c1[_0x7bf7('0x26')]();};}function saveUpdates(_0x4b164a,_0x26aafc){return function(_0x3d1156){if(_0x3d1156){return _0x3d1156[_0x7bf7('0x27')](_0x4b164a)[_0x7bf7('0x28')](function(_0x235062){return _0x235062;});}return null;};}function removeEntity(_0x28ee36,_0xf17450){return function(_0x21b02d){if(_0x21b02d){return _0x21b02d[_0x7bf7('0x29')]()[_0x7bf7('0x28')](function(){_0x28ee36[_0x7bf7('0x1c')](0xcc)[_0x7bf7('0x1d')]();});}};}function handleEntityNotFound(_0x4a09eb,_0x4584c4){return function(_0x138fcf){if(!_0x138fcf){_0x4a09eb[_0x7bf7('0x1b')](0x194);}return _0x138fcf;};}function handleError(_0xf6dd77,_0xa055da){_0xa055da=_0xa055da||0x1f4;return function(_0x2d50d7){logger[_0x7bf7('0x2a')](_0x2d50d7[_0x7bf7('0x2b')]);if(_0x2d50d7['name']){delete _0x2d50d7['name'];}_0xf6dd77[_0x7bf7('0x1c')](_0xa055da)[_0x7bf7('0x2c')](_0x2d50d7);};}exports['index']=function(_0x303d84,_0x465664){var _0x30cd5d={},_0x2d936f={},_0x111531={'count':0x0,'rows':[]};var _0x58e36a=_['map'](db[_0x7bf7('0x2d')][_0x7bf7('0x2e')],function(_0x166719){return{'name':_0x166719[_0x7bf7('0x2f')],'type':_0x166719[_0x7bf7('0x30')][_0x7bf7('0x31')]};});_0x2d936f[_0x7bf7('0x32')]=_[_0x7bf7('0x33')](_0x58e36a,_0x7bf7('0x34'));_0x2d936f[_0x7bf7('0x35')]=_[_0x7bf7('0x36')](_0x303d84[_0x7bf7('0x35')]);_0x2d936f[_0x7bf7('0x37')]=_[_0x7bf7('0x38')](_0x2d936f['model'],_0x2d936f[_0x7bf7('0x35')]);_0x30cd5d[_0x7bf7('0x39')]=_['intersection'](_0x2d936f[_0x7bf7('0x32')],qs['fields'](_0x303d84[_0x7bf7('0x35')]['fields']));_0x30cd5d['attributes']=_0x30cd5d[_0x7bf7('0x39')][_0x7bf7('0x3a')]?_0x30cd5d['attributes']:_0x2d936f['model'];if(!_0x303d84[_0x7bf7('0x35')][_0x7bf7('0x3b')](_0x7bf7('0x3c'))){_0x30cd5d['limit']=qs[_0x7bf7('0x21')](_0x303d84['query'][_0x7bf7('0x21')]);_0x30cd5d['offset']=qs[_0x7bf7('0x20')](_0x303d84[_0x7bf7('0x35')]['offset']);}_0x30cd5d['order']=qs['sort'](_0x303d84[_0x7bf7('0x35')][_0x7bf7('0x3d')]);_0x30cd5d[_0x7bf7('0x3e')]=qs['filters'](_[_0x7bf7('0x3f')](_0x303d84[_0x7bf7('0x35')],_0x2d936f[_0x7bf7('0x37')]),_0x58e36a);if(_0x303d84[_0x7bf7('0x35')][_0x7bf7('0x40')]){_0x30cd5d[_0x7bf7('0x3e')]=_[_0x7bf7('0x41')](_0x30cd5d['where'],{'$or':_['map'](_0x58e36a,function(_0x3c3698){if(_0x3c3698[_0x7bf7('0x30')]!==_0x7bf7('0x42')){var _0x3f35d0={};_0x3f35d0[_0x3c3698[_0x7bf7('0x34')]]={'$like':'%'+_0x303d84[_0x7bf7('0x35')][_0x7bf7('0x40')]+'%'};return _0x3f35d0;}})});}_0x30cd5d=_[_0x7bf7('0x41')]({},_0x30cd5d,_0x303d84['options']);var _0xd152b3={'where':_0x30cd5d[_0x7bf7('0x3e')]};return db['ServicenowField']['count'](_0xd152b3)[_0x7bf7('0x28')](function(_0x4dca87){_0x111531[_0x7bf7('0x1f')]=_0x4dca87;if(_0x303d84[_0x7bf7('0x35')][_0x7bf7('0x43')]){_0x30cd5d[_0x7bf7('0x44')]=[{'all':!![]}];}return db[_0x7bf7('0x2d')][_0x7bf7('0x45')](_0x30cd5d);})[_0x7bf7('0x28')](function(_0x11bf6f){_0x111531[_0x7bf7('0x46')]=_0x11bf6f;return _0x111531;})['then'](respondWithFilteredResult(_0x465664,_0x30cd5d))[_0x7bf7('0x47')](handleError(_0x465664,null));};exports['show']=function(_0xe23446,_0x53add7){var _0x3a5d97={'raw':!![],'where':{'id':_0xe23446[_0x7bf7('0x48')]['id']}},_0x905a39={};_0x905a39[_0x7bf7('0x32')]=_[_0x7bf7('0x36')](db['ServicenowField'][_0x7bf7('0x2e')]);_0x905a39[_0x7bf7('0x35')]=_['keys'](_0xe23446[_0x7bf7('0x35')]);_0x905a39[_0x7bf7('0x37')]=_[_0x7bf7('0x38')](_0x905a39[_0x7bf7('0x32')],_0x905a39[_0x7bf7('0x35')]);_0x3a5d97['attributes']=_['intersection'](_0x905a39['model'],qs[_0x7bf7('0x49')](_0xe23446[_0x7bf7('0x35')][_0x7bf7('0x49')]));_0x3a5d97['attributes']=_0x3a5d97[_0x7bf7('0x39')][_0x7bf7('0x3a')]?_0x3a5d97['attributes']:_0x905a39[_0x7bf7('0x32')];if(_0xe23446[_0x7bf7('0x35')][_0x7bf7('0x43')]){_0x3a5d97[_0x7bf7('0x44')]=[{'all':!![]}];}_0x3a5d97=_['merge']({},_0x3a5d97,_0xe23446[_0x7bf7('0x4a')]);return db[_0x7bf7('0x2d')][_0x7bf7('0x4b')](_0x3a5d97)[_0x7bf7('0x28')](handleEntityNotFound(_0x53add7,null))[_0x7bf7('0x28')](respondWithResult(_0x53add7,null))[_0x7bf7('0x47')](handleError(_0x53add7,null));};exports['create']=function(_0x31ada9,_0x35cfc7){return db['ServicenowField'][_0x7bf7('0x4c')](_0x31ada9[_0x7bf7('0x4d')],{})[_0x7bf7('0x28')](respondWithResult(_0x35cfc7,0xc9))['catch'](handleError(_0x35cfc7,null));};exports[_0x7bf7('0x27')]=function(_0x520376,_0x3e513b){if(_0x520376[_0x7bf7('0x4d')]['id']){delete _0x520376[_0x7bf7('0x4d')]['id'];}return db[_0x7bf7('0x2d')][_0x7bf7('0x4b')]({'where':{'id':_0x520376['params']['id']}})['then'](handleEntityNotFound(_0x3e513b,null))[_0x7bf7('0x28')](saveUpdates(_0x520376[_0x7bf7('0x4d')],null))['then'](respondWithResult(_0x3e513b,null))[_0x7bf7('0x47')](handleError(_0x3e513b,null));};exports['destroy']=function(_0x47d2f1,_0xe395f0){return db[_0x7bf7('0x2d')][_0x7bf7('0x4b')]({'where':{'id':_0x47d2f1['params']['id']}})[_0x7bf7('0x28')](handleEntityNotFound(_0xe395f0,null))['then'](removeEntity(_0xe395f0,null))[_0x7bf7('0x47')](handleError(_0xe395f0,null));};