Built motion from commit c738b9ac.|2.6.25
[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 _0xaf64=['sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','destroy','stack','name','send','index','fieldName','key','model','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','query','order','sort','pick','filter','where','merge','VIRTUAL','options','ServicenowField','then','includeAll','include','findAll','rows','catch','show','rawAttributes','find','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path'];(function(_0x34a8c8,_0x31e259){var _0x1fe6e5=function(_0x30f28d){while(--_0x30f28d){_0x34a8c8['push'](_0x34a8c8['shift']());}};_0x1fe6e5(++_0x31e259);}(_0xaf64,0x127));var _0x4af6=function(_0x213518,_0x51e022){_0x213518=_0x213518-0x0;var _0x1baf75=_0xaf64[_0x213518];return _0x1baf75;};'use strict';var emlformat=require(_0x4af6('0x0'));var rimraf=require(_0x4af6('0x1'));var zipdir=require(_0x4af6('0x2'));var jsonpatch=require(_0x4af6('0x3'));var rp=require(_0x4af6('0x4'));var moment=require(_0x4af6('0x5'));var BPromise=require(_0x4af6('0x6'));var Mustache=require('mustache');var util=require(_0x4af6('0x7'));var path=require(_0x4af6('0x8'));var sox=require(_0x4af6('0x9'));var csv=require(_0x4af6('0xa'));var ejs=require(_0x4af6('0xb'));var fs=require('fs');var fs_extra=require(_0x4af6('0xc'));var _=require(_0x4af6('0xd'));var squel=require('squel');var crypto=require(_0x4af6('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x4af6('0xf'));var toCsv=require(_0x4af6('0xa'));var querystring=require('querystring');var Papa=require(_0x4af6('0x10'));var Redis=require('ioredis');var authService=require(_0x4af6('0x11'));var qs=require(_0x4af6('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4af6('0x13'));var logger=require(_0x4af6('0x14'))(_0x4af6('0x15'));var utils=require(_0x4af6('0x16'));var config=require(_0x4af6('0x17'));var licenseUtil=require(_0x4af6('0x18'));var db=require(_0x4af6('0x19'))['db'];function respondWithStatusCode(_0x2caf1c,_0x3a42e2){_0x3a42e2=_0x3a42e2||0xcc;return function(_0x2c0791){if(_0x2c0791){return _0x2caf1c[_0x4af6('0x1a')](_0x3a42e2);}return _0x2caf1c['status'](_0x3a42e2)[_0x4af6('0x1b')]();};}function respondWithResult(_0x3e8ac1,_0x1c0c53){_0x1c0c53=_0x1c0c53||0xc8;return function(_0x48327b){if(_0x48327b){return _0x3e8ac1[_0x4af6('0x1c')](_0x1c0c53)[_0x4af6('0x1d')](_0x48327b);}};}function respondWithFilteredResult(_0x1a728c,_0x3a2fa2){return function(_0x34d79){if(_0x34d79){var _0xc153ad=typeof _0x3a2fa2[_0x4af6('0x1e')]===_0x4af6('0x1f')&&typeof _0x3a2fa2[_0x4af6('0x20')]===_0x4af6('0x1f');var _0x57608b=_0x34d79[_0x4af6('0x21')];var _0x506234=_0xc153ad?0x0:_0x3a2fa2[_0x4af6('0x1e')];var _0xd2e549=_0xc153ad?_0x34d79[_0x4af6('0x21')]:_0x3a2fa2['offset']+_0x3a2fa2[_0x4af6('0x20')];var _0xc2f137;if(_0xd2e549>=_0x57608b){_0xd2e549=_0x57608b;_0xc2f137=0xc8;}else{_0xc2f137=0xce;}_0x1a728c[_0x4af6('0x1c')](_0xc2f137);return _0x1a728c[_0x4af6('0x22')](_0x4af6('0x23'),_0x506234+'-'+_0xd2e549+'/'+_0x57608b)['json'](_0x34d79);}return null;};}function patchUpdates(_0x37b0e4){return function(_0x58e2e4){try{jsonpatch[_0x4af6('0x24')](_0x58e2e4,_0x37b0e4,!![]);}catch(_0x41784e){return BPromise['reject'](_0x41784e);}return _0x58e2e4[_0x4af6('0x25')]();};}function saveUpdates(_0x426336,_0x522f6a){return function(_0x1eb749){if(_0x1eb749){return _0x1eb749['update'](_0x426336)['then'](function(_0x4b1051){return _0x4b1051;});}return null;};}function removeEntity(_0x7e2da5,_0x192c5a){return function(_0x2b8d88){if(_0x2b8d88){return _0x2b8d88[_0x4af6('0x26')]()['then'](function(){_0x7e2da5[_0x4af6('0x1c')](0xcc)[_0x4af6('0x1b')]();});}};}function handleEntityNotFound(_0x351622,_0x438920){return function(_0x4ada69){if(!_0x4ada69){_0x351622[_0x4af6('0x1a')](0x194);}return _0x4ada69;};}function handleError(_0x304bca,_0x5a3156){_0x5a3156=_0x5a3156||0x1f4;return function(_0x56d98a){logger['error'](_0x56d98a[_0x4af6('0x27')]);if(_0x56d98a[_0x4af6('0x28')]){delete _0x56d98a[_0x4af6('0x28')];}_0x304bca['status'](_0x5a3156)[_0x4af6('0x29')](_0x56d98a);};}exports[_0x4af6('0x2a')]=function(_0x4bed4c,_0x2292a7){var _0x41f69a={},_0x2acbb1={},_0x13c1eb={'count':0x0,'rows':[]};var _0x53b3d8=_['map'](db['ServicenowField']['rawAttributes'],function(_0x46cbb0){return{'name':_0x46cbb0[_0x4af6('0x2b')],'type':_0x46cbb0['type'][_0x4af6('0x2c')]};});_0x2acbb1[_0x4af6('0x2d')]=_['map'](_0x53b3d8,_0x4af6('0x28'));_0x2acbb1['query']=_[_0x4af6('0x2e')](_0x4bed4c['query']);_0x2acbb1[_0x4af6('0x2f')]=_['intersection'](_0x2acbb1[_0x4af6('0x2d')],_0x2acbb1['query']);_0x41f69a[_0x4af6('0x30')]=_[_0x4af6('0x31')](_0x2acbb1[_0x4af6('0x2d')],qs[_0x4af6('0x32')](_0x4bed4c['query']['fields']));_0x41f69a[_0x4af6('0x30')]=_0x41f69a[_0x4af6('0x30')][_0x4af6('0x33')]?_0x41f69a[_0x4af6('0x30')]:_0x2acbb1[_0x4af6('0x2d')];if(!_0x4bed4c['query'][_0x4af6('0x34')](_0x4af6('0x35'))){_0x41f69a[_0x4af6('0x20')]=qs[_0x4af6('0x20')](_0x4bed4c[_0x4af6('0x36')][_0x4af6('0x20')]);_0x41f69a[_0x4af6('0x1e')]=qs[_0x4af6('0x1e')](_0x4bed4c[_0x4af6('0x36')][_0x4af6('0x1e')]);}_0x41f69a[_0x4af6('0x37')]=qs[_0x4af6('0x38')](_0x4bed4c[_0x4af6('0x36')][_0x4af6('0x38')]);_0x41f69a['where']=qs[_0x4af6('0x2f')](_[_0x4af6('0x39')](_0x4bed4c[_0x4af6('0x36')],_0x2acbb1['filters']),_0x53b3d8);if(_0x4bed4c[_0x4af6('0x36')][_0x4af6('0x3a')]){_0x41f69a[_0x4af6('0x3b')]=_[_0x4af6('0x3c')](_0x41f69a[_0x4af6('0x3b')],{'$or':_['map'](_0x53b3d8,function(_0x41ddb5){if(_0x41ddb5['type']!==_0x4af6('0x3d')){var _0x27d99c={};_0x27d99c[_0x41ddb5[_0x4af6('0x28')]]={'$like':'%'+_0x4bed4c['query'][_0x4af6('0x3a')]+'%'};return _0x27d99c;}})});}_0x41f69a=_[_0x4af6('0x3c')]({},_0x41f69a,_0x4bed4c[_0x4af6('0x3e')]);var _0x593390={'where':_0x41f69a[_0x4af6('0x3b')]};return db[_0x4af6('0x3f')][_0x4af6('0x21')](_0x593390)[_0x4af6('0x40')](function(_0x4afa1b){_0x13c1eb['count']=_0x4afa1b;if(_0x4bed4c[_0x4af6('0x36')][_0x4af6('0x41')]){_0x41f69a[_0x4af6('0x42')]=[{'all':!![]}];}return db[_0x4af6('0x3f')][_0x4af6('0x43')](_0x41f69a);})[_0x4af6('0x40')](function(_0x2e14e5){_0x13c1eb[_0x4af6('0x44')]=_0x2e14e5;return _0x13c1eb;})[_0x4af6('0x40')](respondWithFilteredResult(_0x2292a7,_0x41f69a))[_0x4af6('0x45')](handleError(_0x2292a7,null));};exports[_0x4af6('0x46')]=function(_0x5ba946,_0x2b0386){var _0x3ba57c={'raw':!![],'where':{'id':_0x5ba946['params']['id']}},_0x40d5e4={};_0x40d5e4[_0x4af6('0x2d')]=_[_0x4af6('0x2e')](db[_0x4af6('0x3f')][_0x4af6('0x47')]);_0x40d5e4[_0x4af6('0x36')]=_[_0x4af6('0x2e')](_0x5ba946['query']);_0x40d5e4[_0x4af6('0x2f')]=_[_0x4af6('0x31')](_0x40d5e4[_0x4af6('0x2d')],_0x40d5e4[_0x4af6('0x36')]);_0x3ba57c[_0x4af6('0x30')]=_[_0x4af6('0x31')](_0x40d5e4[_0x4af6('0x2d')],qs[_0x4af6('0x32')](_0x5ba946['query'][_0x4af6('0x32')]));_0x3ba57c['attributes']=_0x3ba57c[_0x4af6('0x30')][_0x4af6('0x33')]?_0x3ba57c['attributes']:_0x40d5e4[_0x4af6('0x2d')];if(_0x5ba946[_0x4af6('0x36')][_0x4af6('0x41')]){_0x3ba57c[_0x4af6('0x42')]=[{'all':!![]}];}_0x3ba57c=_[_0x4af6('0x3c')]({},_0x3ba57c,_0x5ba946[_0x4af6('0x3e')]);return db[_0x4af6('0x3f')][_0x4af6('0x48')](_0x3ba57c)[_0x4af6('0x40')](handleEntityNotFound(_0x2b0386,null))[_0x4af6('0x40')](respondWithResult(_0x2b0386,null))[_0x4af6('0x45')](handleError(_0x2b0386,null));};exports[_0x4af6('0x49')]=function(_0x5dd743,_0x1e91d4){return db[_0x4af6('0x3f')][_0x4af6('0x49')](_0x5dd743[_0x4af6('0x4a')],{})[_0x4af6('0x40')](respondWithResult(_0x1e91d4,0xc9))['catch'](handleError(_0x1e91d4,null));};exports['update']=function(_0x50e7ee,_0x5efec5){if(_0x50e7ee[_0x4af6('0x4a')]['id']){delete _0x50e7ee[_0x4af6('0x4a')]['id'];}return db['ServicenowField'][_0x4af6('0x48')]({'where':{'id':_0x50e7ee[_0x4af6('0x4b')]['id']}})['then'](handleEntityNotFound(_0x5efec5,null))[_0x4af6('0x40')](saveUpdates(_0x50e7ee[_0x4af6('0x4a')],null))[_0x4af6('0x40')](respondWithResult(_0x5efec5,null))[_0x4af6('0x45')](handleError(_0x5efec5,null));};exports[_0x4af6('0x26')]=function(_0x2d2ac8,_0x18ecf0){return db[_0x4af6('0x3f')][_0x4af6('0x48')]({'where':{'id':_0x2d2ac8[_0x4af6('0x4b')]['id']}})[_0x4af6('0x40')](handleEntityNotFound(_0x18ecf0,null))[_0x4af6('0x40')](removeEntity(_0x18ecf0,null))[_0x4af6('0x45')](handleError(_0x18ecf0,null));};