Built motion from commit (unavailable).|2.5.15
[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 _0x9bb3=['fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','pick','filter','where','VIRTUAL','merge','options','ServicenowField','catch','params','includeAll','include','find','create','body','update','destroy','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','then','error','stack','name','map','rawAttributes'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0x9bb3,0x134));var _0x39bb=function(_0xafb4c7,_0x349379){_0xafb4c7=_0xafb4c7-0x0;var _0x426a41=_0x9bb3[_0xafb4c7];return _0x426a41;};'use strict';var pdf=require(_0x39bb('0x0'));var emlformat=require(_0x39bb('0x1'));var rimraf=require(_0x39bb('0x2'));var zipdir=require(_0x39bb('0x3'));var jsonpatch=require(_0x39bb('0x4'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x39bb('0x5'));var Mustache=require(_0x39bb('0x6'));var util=require(_0x39bb('0x7'));var path=require(_0x39bb('0x8'));var sox=require(_0x39bb('0x9'));var csv=require(_0x39bb('0xa'));var ejs=require(_0x39bb('0xb'));var fs=require('fs');var _=require(_0x39bb('0xc'));var squel=require(_0x39bb('0xd'));var crypto=require(_0x39bb('0xe'));var jsforce=require(_0x39bb('0xf'));var deskjs=require(_0x39bb('0x10'));var toCsv=require(_0x39bb('0xa'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x39bb('0x11'));var authService=require(_0x39bb('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x39bb('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x39bb('0x14'))(_0x39bb('0x15'));var utils=require(_0x39bb('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x39bb('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5cec25,_0x986cf){_0x986cf=_0x986cf||0xcc;return function(_0x9856b6){if(_0x9856b6){return _0x5cec25[_0x39bb('0x18')](_0x986cf);}return _0x5cec25[_0x39bb('0x19')](_0x986cf)[_0x39bb('0x1a')]();};}function respondWithResult(_0x16b2f3,_0x2fea51){_0x2fea51=_0x2fea51||0xc8;return function(_0x4a7a94){if(_0x4a7a94){return _0x16b2f3['status'](_0x2fea51)[_0x39bb('0x1b')](_0x4a7a94);}};}function respondWithFilteredResult(_0x4a569c,_0x46e92a){return function(_0x40ee8f){if(_0x40ee8f){var _0x34c794=_0x40ee8f[_0x39bb('0x1c')],_0x240e20=_0x46e92a[_0x39bb('0x1d')],_0x2a81d9=_0x46e92a[_0x39bb('0x1d')]+_0x46e92a[_0x39bb('0x1e')],_0x138879;if(_0x2a81d9>=_0x34c794){_0x2a81d9=_0x34c794;_0x138879=0xc8;}else{_0x138879=0xce;}_0x4a569c['status'](_0x138879);return _0x4a569c[_0x39bb('0x1f')](_0x39bb('0x20'),_0x240e20+'-'+_0x2a81d9+'/'+_0x34c794)[_0x39bb('0x1b')](_0x40ee8f);}return null;};}function patchUpdates(_0x541cec){return function(_0x12b6a4){try{jsonpatch[_0x39bb('0x21')](_0x12b6a4,_0x541cec,!![]);}catch(_0xd92981){return BPromise[_0x39bb('0x22')](_0xd92981);}return _0x12b6a4[_0x39bb('0x23')]();};}function saveUpdates(_0xfa6090,_0x459580){return function(_0x942492){if(_0x942492){return _0x942492['update'](_0xfa6090)[_0x39bb('0x24')](function(_0x4d88dd){return _0x4d88dd;});}return null;};}function removeEntity(_0x5f14a0,_0xee257d){return function(_0x475768){if(_0x475768){return _0x475768['destroy']()['then'](function(){_0x5f14a0[_0x39bb('0x19')](0xcc)[_0x39bb('0x1a')]();});}};}function handleEntityNotFound(_0x54509b,_0x2f9390){return function(_0x119a90){if(!_0x119a90){_0x54509b[_0x39bb('0x18')](0x194);}return _0x119a90;};}function handleError(_0x4b8f5b,_0x206b48){_0x206b48=_0x206b48||0x1f4;return function(_0x492eb6){logger[_0x39bb('0x25')](_0x492eb6[_0x39bb('0x26')]);if(_0x492eb6[_0x39bb('0x27')]){delete _0x492eb6[_0x39bb('0x27')];}_0x4b8f5b[_0x39bb('0x19')](_0x206b48)['send'](_0x492eb6);};}exports['index']=function(_0xe597b8,_0x41acf4){var _0x5841f9={},_0x5d4427={},_0x39e416={'count':0x0,'rows':[]};var _0x475657=_[_0x39bb('0x28')](db['ServicenowField'][_0x39bb('0x29')],function(_0x512573){return{'name':_0x512573[_0x39bb('0x2a')],'type':_0x512573[_0x39bb('0x2b')]['key']};});_0x5d4427[_0x39bb('0x2c')]=_[_0x39bb('0x28')](_0x475657,_0x39bb('0x27'));_0x5d4427[_0x39bb('0x2d')]=_[_0x39bb('0x2e')](_0xe597b8[_0x39bb('0x2d')]);_0x5d4427[_0x39bb('0x2f')]=_[_0x39bb('0x30')](_0x5d4427[_0x39bb('0x2c')],_0x5d4427[_0x39bb('0x2d')]);_0x5841f9[_0x39bb('0x31')]=_[_0x39bb('0x30')](_0x5d4427[_0x39bb('0x2c')],qs['fields'](_0xe597b8[_0x39bb('0x2d')][_0x39bb('0x32')]));_0x5841f9['attributes']=_0x5841f9[_0x39bb('0x31')][_0x39bb('0x33')]?_0x5841f9['attributes']:_0x5d4427[_0x39bb('0x2c')];if(!_0xe597b8[_0x39bb('0x2d')][_0x39bb('0x34')]('nolimit')){_0x5841f9['limit']=qs['limit'](_0xe597b8[_0x39bb('0x2d')][_0x39bb('0x1e')]);_0x5841f9[_0x39bb('0x1d')]=qs[_0x39bb('0x1d')](_0xe597b8['query'][_0x39bb('0x1d')]);}_0x5841f9['order']=qs[_0x39bb('0x35')](_0xe597b8['query']['sort']);_0x5841f9['where']=qs['filters'](_[_0x39bb('0x36')](_0xe597b8[_0x39bb('0x2d')],_0x5d4427['filters']),_0x475657);if(_0xe597b8[_0x39bb('0x2d')][_0x39bb('0x37')]){_0x5841f9['where']=_['merge'](_0x5841f9[_0x39bb('0x38')],{'$or':_[_0x39bb('0x28')](_0x475657,function(_0x322959){if(_0x322959[_0x39bb('0x2b')]!==_0x39bb('0x39')){var _0x100ab4={};_0x100ab4[_0x322959[_0x39bb('0x27')]]={'$like':'%'+_0xe597b8[_0x39bb('0x2d')][_0x39bb('0x37')]+'%'};return _0x100ab4;}})});}_0x5841f9=_[_0x39bb('0x3a')]({},_0x5841f9,_0xe597b8[_0x39bb('0x3b')]);var _0x5cbab9={'where':_0x5841f9['where']};return db[_0x39bb('0x3c')][_0x39bb('0x1c')](_0x5cbab9)[_0x39bb('0x24')](function(_0x138820){_0x39e416[_0x39bb('0x1c')]=_0x138820;if(_0xe597b8['query']['includeAll']){_0x5841f9['include']=[{'all':!![]}];}return db['ServicenowField']['findAll'](_0x5841f9);})['then'](function(_0x404fd9){_0x39e416['rows']=_0x404fd9;return _0x39e416;})['then'](respondWithFilteredResult(_0x41acf4,_0x5841f9))[_0x39bb('0x3d')](handleError(_0x41acf4,null));};exports['show']=function(_0x59c197,_0x219ea8){var _0x1ce8a0={'raw':!![],'where':{'id':_0x59c197[_0x39bb('0x3e')]['id']}},_0x1fe090={};_0x1fe090[_0x39bb('0x2c')]=_[_0x39bb('0x2e')](db[_0x39bb('0x3c')][_0x39bb('0x29')]);_0x1fe090['query']=_['keys'](_0x59c197[_0x39bb('0x2d')]);_0x1fe090[_0x39bb('0x2f')]=_[_0x39bb('0x30')](_0x1fe090[_0x39bb('0x2c')],_0x1fe090[_0x39bb('0x2d')]);_0x1ce8a0[_0x39bb('0x31')]=_[_0x39bb('0x30')](_0x1fe090[_0x39bb('0x2c')],qs[_0x39bb('0x32')](_0x59c197['query'][_0x39bb('0x32')]));_0x1ce8a0['attributes']=_0x1ce8a0['attributes'][_0x39bb('0x33')]?_0x1ce8a0[_0x39bb('0x31')]:_0x1fe090['model'];if(_0x59c197[_0x39bb('0x2d')][_0x39bb('0x3f')]){_0x1ce8a0[_0x39bb('0x40')]=[{'all':!![]}];}_0x1ce8a0=_['merge']({},_0x1ce8a0,_0x59c197[_0x39bb('0x3b')]);return db[_0x39bb('0x3c')][_0x39bb('0x41')](_0x1ce8a0)[_0x39bb('0x24')](handleEntityNotFound(_0x219ea8,null))[_0x39bb('0x24')](respondWithResult(_0x219ea8,null))[_0x39bb('0x3d')](handleError(_0x219ea8,null));};exports[_0x39bb('0x42')]=function(_0x3a1846,_0x2bd781){return db[_0x39bb('0x3c')][_0x39bb('0x42')](_0x3a1846[_0x39bb('0x43')],{})[_0x39bb('0x24')](respondWithResult(_0x2bd781,0xc9))[_0x39bb('0x3d')](handleError(_0x2bd781,null));};exports[_0x39bb('0x44')]=function(_0x532299,_0x27b27b){if(_0x532299[_0x39bb('0x43')]['id']){delete _0x532299[_0x39bb('0x43')]['id'];}return db[_0x39bb('0x3c')][_0x39bb('0x41')]({'where':{'id':_0x532299['params']['id']}})['then'](handleEntityNotFound(_0x27b27b,null))[_0x39bb('0x24')](saveUpdates(_0x532299['body'],null))[_0x39bb('0x24')](respondWithResult(_0x27b27b,null))[_0x39bb('0x3d')](handleError(_0x27b27b,null));};exports[_0x39bb('0x45')]=function(_0x27e3be,_0x3e9b4d){return db['ServicenowField'][_0x39bb('0x41')]({'where':{'id':_0x27e3be[_0x39bb('0x3e')]['id']}})[_0x39bb('0x24')](handleEntityNotFound(_0x3e9b4d,null))[_0x39bb('0x24')](removeEntity(_0x3e9b4d,null))[_0x39bb('0x3d')](handleError(_0x3e9b4d,null));};