9bed77c87e0dc2d122c7a42740556f984d230c10
[motion2.git] / server / api / intZendeskField / intZendeskField.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 _0xffb6=['api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','offset','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','index','map','ZendeskField','rawAttributes','model','name','query','keys','filters','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','type','merge','includeAll','findAll','rows','catch','show','params','intersection','fields','include','find','create','body','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger'];(function(_0x1d2bbb,_0x202267){var _0x38082b=function(_0x27d153){while(--_0x27d153){_0x1d2bbb['push'](_0x1d2bbb['shift']());}};_0x38082b(++_0x202267);}(_0xffb6,0x81));var _0x6ffb=function(_0x384f06,_0x3ba3aa){_0x384f06=_0x384f06-0x0;var _0x5ebeb7=_0xffb6[_0x384f06];return _0x5ebeb7;};'use strict';var emlformat=require(_0x6ffb('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x6ffb('0x1'));var jsonpatch=require(_0x6ffb('0x2'));var rp=require(_0x6ffb('0x3'));var moment=require('moment');var BPromise=require(_0x6ffb('0x4'));var Mustache=require(_0x6ffb('0x5'));var util=require(_0x6ffb('0x6'));var path=require(_0x6ffb('0x7'));var sox=require(_0x6ffb('0x8'));var csv=require(_0x6ffb('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x6ffb('0xa'));var _=require(_0x6ffb('0xb'));var squel=require(_0x6ffb('0xc'));var crypto=require(_0x6ffb('0xd'));var jsforce=require(_0x6ffb('0xe'));var deskjs=require(_0x6ffb('0xf'));var toCsv=require(_0x6ffb('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x6ffb('0x10'));var qs=require(_0x6ffb('0x11'));var as=require(_0x6ffb('0x12'));var hardwareService=require(_0x6ffb('0x13'));var logger=require(_0x6ffb('0x14'))(_0x6ffb('0x15'));var utils=require('../../config/utils');var config=require(_0x6ffb('0x16'));var licenseUtil=require(_0x6ffb('0x17'));var db=require(_0x6ffb('0x18'))['db'];function respondWithStatusCode(_0x318440,_0x38f11b){_0x38f11b=_0x38f11b||0xcc;return function(_0x537100){if(_0x537100){return _0x318440[_0x6ffb('0x19')](_0x38f11b);}return _0x318440[_0x6ffb('0x1a')](_0x38f11b)[_0x6ffb('0x1b')]();};}function respondWithResult(_0x31d09f,_0x260bb4){_0x260bb4=_0x260bb4||0xc8;return function(_0x419240){if(_0x419240){return _0x31d09f[_0x6ffb('0x1a')](_0x260bb4)[_0x6ffb('0x1c')](_0x419240);}};}function respondWithFilteredResult(_0x41f926,_0x577a2b){return function(_0x567da6){if(_0x567da6){var _0xbd665=typeof _0x577a2b['offset']===_0x6ffb('0x1d')&&typeof _0x577a2b[_0x6ffb('0x1e')]==='undefined';var _0x3b505e=_0x567da6['count'];var _0xf43542=_0xbd665?0x0:_0x577a2b[_0x6ffb('0x1f')];var _0x71c643=_0xbd665?_0x567da6[_0x6ffb('0x20')]:_0x577a2b[_0x6ffb('0x1f')]+_0x577a2b[_0x6ffb('0x1e')];var _0x3d2482;if(_0x71c643>=_0x3b505e){_0x71c643=_0x3b505e;_0x3d2482=0xc8;}else{_0x3d2482=0xce;}_0x41f926[_0x6ffb('0x1a')](_0x3d2482);return _0x41f926[_0x6ffb('0x21')](_0x6ffb('0x22'),_0xf43542+'-'+_0x71c643+'/'+_0x3b505e)[_0x6ffb('0x1c')](_0x567da6);}return null;};}function patchUpdates(_0x338f7c){return function(_0x267a5){try{jsonpatch[_0x6ffb('0x23')](_0x267a5,_0x338f7c,!![]);}catch(_0x4c9e02){return BPromise[_0x6ffb('0x24')](_0x4c9e02);}return _0x267a5[_0x6ffb('0x25')]();};}function saveUpdates(_0xf7573b,_0x45bf57){return function(_0x2c41f1){if(_0x2c41f1){return _0x2c41f1[_0x6ffb('0x26')](_0xf7573b)[_0x6ffb('0x27')](function(_0x4ddc9e){return _0x4ddc9e;});}return null;};}function removeEntity(_0x2e950f,_0x1a54f0){return function(_0x1e2798){if(_0x1e2798){return _0x1e2798[_0x6ffb('0x28')]()['then'](function(){_0x2e950f[_0x6ffb('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x22ebf1,_0x2642a2){return function(_0x5ef447){if(!_0x5ef447){_0x22ebf1[_0x6ffb('0x19')](0x194);}return _0x5ef447;};}function handleError(_0x4b4b9d,_0x48919c){_0x48919c=_0x48919c||0x1f4;return function(_0x4a089b){logger[_0x6ffb('0x29')](_0x4a089b[_0x6ffb('0x2a')]);if(_0x4a089b['name']){delete _0x4a089b['name'];}_0x4b4b9d[_0x6ffb('0x1a')](_0x48919c)['send'](_0x4a089b);};}exports[_0x6ffb('0x2b')]=function(_0x25244a,_0x117be0){var _0x1e207d={},_0x29ad25={},_0x5b608a={'count':0x0,'rows':[]};var _0x2aa677=_[_0x6ffb('0x2c')](db[_0x6ffb('0x2d')][_0x6ffb('0x2e')],function(_0x6fd038){return{'name':_0x6fd038['fieldName'],'type':_0x6fd038['type']['key']};});_0x29ad25[_0x6ffb('0x2f')]=_[_0x6ffb('0x2c')](_0x2aa677,_0x6ffb('0x30'));_0x29ad25[_0x6ffb('0x31')]=_[_0x6ffb('0x32')](_0x25244a[_0x6ffb('0x31')]);_0x29ad25[_0x6ffb('0x33')]=_['intersection'](_0x29ad25[_0x6ffb('0x2f')],_0x29ad25[_0x6ffb('0x31')]);_0x1e207d[_0x6ffb('0x34')]=_['intersection'](_0x29ad25[_0x6ffb('0x2f')],qs['fields'](_0x25244a[_0x6ffb('0x31')]['fields']));_0x1e207d[_0x6ffb('0x34')]=_0x1e207d[_0x6ffb('0x34')][_0x6ffb('0x35')]?_0x1e207d[_0x6ffb('0x34')]:_0x29ad25[_0x6ffb('0x2f')];if(!_0x25244a[_0x6ffb('0x31')][_0x6ffb('0x36')](_0x6ffb('0x37'))){_0x1e207d[_0x6ffb('0x1e')]=qs[_0x6ffb('0x1e')](_0x25244a[_0x6ffb('0x31')][_0x6ffb('0x1e')]);_0x1e207d[_0x6ffb('0x1f')]=qs['offset'](_0x25244a['query']['offset']);}_0x1e207d[_0x6ffb('0x38')]=qs[_0x6ffb('0x39')](_0x25244a['query'][_0x6ffb('0x39')]);_0x1e207d[_0x6ffb('0x3a')]=qs[_0x6ffb('0x33')](_[_0x6ffb('0x3b')](_0x25244a[_0x6ffb('0x31')],_0x29ad25['filters']),_0x2aa677);if(_0x25244a[_0x6ffb('0x31')][_0x6ffb('0x3c')]){_0x1e207d[_0x6ffb('0x3a')]=_['merge'](_0x1e207d[_0x6ffb('0x3a')],{'$or':_[_0x6ffb('0x2c')](_0x2aa677,function(_0x2b1c5b){if(_0x2b1c5b[_0x6ffb('0x3d')]!=='VIRTUAL'){var _0xea8f41={};_0xea8f41[_0x2b1c5b[_0x6ffb('0x30')]]={'$like':'%'+_0x25244a['query'][_0x6ffb('0x3c')]+'%'};return _0xea8f41;}})});}_0x1e207d=_[_0x6ffb('0x3e')]({},_0x1e207d,_0x25244a['options']);var _0x1e95ef={'where':_0x1e207d[_0x6ffb('0x3a')]};return db[_0x6ffb('0x2d')][_0x6ffb('0x20')](_0x1e95ef)[_0x6ffb('0x27')](function(_0x1c1501){_0x5b608a['count']=_0x1c1501;if(_0x25244a[_0x6ffb('0x31')][_0x6ffb('0x3f')]){_0x1e207d['include']=[{'all':!![]}];}return db['ZendeskField'][_0x6ffb('0x40')](_0x1e207d);})[_0x6ffb('0x27')](function(_0x4d99e8){_0x5b608a[_0x6ffb('0x41')]=_0x4d99e8;return _0x5b608a;})[_0x6ffb('0x27')](respondWithFilteredResult(_0x117be0,_0x1e207d))[_0x6ffb('0x42')](handleError(_0x117be0,null));};exports[_0x6ffb('0x43')]=function(_0x31bf8b,_0xdacf33){var _0x183668={'raw':!![],'where':{'id':_0x31bf8b[_0x6ffb('0x44')]['id']}},_0x130cfe={};_0x130cfe[_0x6ffb('0x2f')]=_[_0x6ffb('0x32')](db['ZendeskField'][_0x6ffb('0x2e')]);_0x130cfe['query']=_[_0x6ffb('0x32')](_0x31bf8b[_0x6ffb('0x31')]);_0x130cfe[_0x6ffb('0x33')]=_['intersection'](_0x130cfe[_0x6ffb('0x2f')],_0x130cfe[_0x6ffb('0x31')]);_0x183668[_0x6ffb('0x34')]=_[_0x6ffb('0x45')](_0x130cfe['model'],qs['fields'](_0x31bf8b['query'][_0x6ffb('0x46')]));_0x183668[_0x6ffb('0x34')]=_0x183668[_0x6ffb('0x34')][_0x6ffb('0x35')]?_0x183668['attributes']:_0x130cfe[_0x6ffb('0x2f')];if(_0x31bf8b[_0x6ffb('0x31')]['includeAll']){_0x183668[_0x6ffb('0x47')]=[{'all':!![]}];}_0x183668=_[_0x6ffb('0x3e')]({},_0x183668,_0x31bf8b['options']);return db[_0x6ffb('0x2d')][_0x6ffb('0x48')](_0x183668)[_0x6ffb('0x27')](handleEntityNotFound(_0xdacf33,null))['then'](respondWithResult(_0xdacf33,null))[_0x6ffb('0x42')](handleError(_0xdacf33,null));};exports[_0x6ffb('0x49')]=function(_0x4e1261,_0x1fe41f){return db[_0x6ffb('0x2d')][_0x6ffb('0x49')](_0x4e1261[_0x6ffb('0x4a')],{})[_0x6ffb('0x27')](respondWithResult(_0x1fe41f,0xc9))[_0x6ffb('0x42')](handleError(_0x1fe41f,null));};exports['update']=function(_0x30b969,_0x5db5de){if(_0x30b969[_0x6ffb('0x4a')]['id']){delete _0x30b969['body']['id'];}return db['ZendeskField'][_0x6ffb('0x48')]({'where':{'id':_0x30b969['params']['id']}})['then'](handleEntityNotFound(_0x5db5de,null))[_0x6ffb('0x27')](saveUpdates(_0x30b969[_0x6ffb('0x4a')],null))['then'](respondWithResult(_0x5db5de,null))['catch'](handleError(_0x5db5de,null));};exports[_0x6ffb('0x28')]=function(_0x2064c3,_0x42a2e6){return db['ZendeskField'][_0x6ffb('0x48')]({'where':{'id':_0x2064c3['params']['id']}})[_0x6ffb('0x27')](handleEntityNotFound(_0x42a2e6,null))[_0x6ffb('0x27')](removeEntity(_0x42a2e6,null))[_0x6ffb('0x42')](handleError(_0x42a2e6,null));};