bd1066e8a6859e51757fb25eeaed3021f614f2f0
[motion2.git] / server / api / intFreshdeskField / intFreshdeskField.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 _0x730f=['send','map','FreshdeskField','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','nolimit','limit','sort','where','pick','filter','merge','options','includeAll','include','findAll','catch','find','create','body','params','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','count','offset','set','apply','reject','save','update','then','error','stack','name'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x730f,0xb0));var _0xf730=function(_0x1e61db,_0x439a46){_0x1e61db=_0x1e61db-0x0;var _0xe5c30e=_0x730f[_0x1e61db];return _0xe5c30e;};'use strict';var pdf=require(_0xf730('0x0'));var emlformat=require(_0xf730('0x1'));var rimraf=require(_0xf730('0x2'));var zipdir=require(_0xf730('0x3'));var jsonpatch=require(_0xf730('0x4'));var rp=require('request-promise');var moment=require(_0xf730('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xf730('0x6'));var util=require(_0xf730('0x7'));var path=require(_0xf730('0x8'));var sox=require(_0xf730('0x9'));var csv=require(_0xf730('0xa'));var ejs=require(_0xf730('0xb'));var fs=require('fs');var _=require(_0xf730('0xc'));var squel=require(_0xf730('0xd'));var crypto=require(_0xf730('0xe'));var jsforce=require(_0xf730('0xf'));var deskjs=require(_0xf730('0x10'));var toCsv=require(_0xf730('0xa'));var querystring=require(_0xf730('0x11'));var Papa=require(_0xf730('0x12'));var Redis=require(_0xf730('0x13'));var authService=require('../../components/auth/service');var qs=require(_0xf730('0x14'));var as=require(_0xf730('0x15'));var hardwareService=require(_0xf730('0x16'));var logger=require(_0xf730('0x17'))(_0xf730('0x18'));var utils=require(_0xf730('0x19'));var config=require(_0xf730('0x1a'));var db=require(_0xf730('0x1b'))['db'];function respondWithStatusCode(_0x432ada,_0x1d7547){_0x1d7547=_0x1d7547||0xcc;return function(_0x5ccfce){if(_0x5ccfce){return _0x432ada[_0xf730('0x1c')](_0x1d7547);}return _0x432ada['status'](_0x1d7547)[_0xf730('0x1d')]();};}function respondWithResult(_0x47c5c7,_0x3c2a9d){_0x3c2a9d=_0x3c2a9d||0xc8;return function(_0x10fdfa){if(_0x10fdfa){return _0x47c5c7[_0xf730('0x1e')](_0x3c2a9d)[_0xf730('0x1f')](_0x10fdfa);}};}function respondWithFilteredResult(_0x3665cb,_0x1889d5){return function(_0xc0d529){if(_0xc0d529){var _0x8a0c95=_0xc0d529[_0xf730('0x20')],_0x4e959e=_0x1889d5[_0xf730('0x21')],_0x4c1d7e=_0x1889d5[_0xf730('0x21')]+_0x1889d5['limit'],_0x3c9c80;if(_0x4c1d7e>=_0x8a0c95){_0x4c1d7e=_0x8a0c95;_0x3c9c80=0xc8;}else{_0x3c9c80=0xce;}_0x3665cb[_0xf730('0x1e')](_0x3c9c80);return _0x3665cb[_0xf730('0x22')]('Content-Range',_0x4e959e+'-'+_0x4c1d7e+'/'+_0x8a0c95)[_0xf730('0x1f')](_0xc0d529);}return null;};}function patchUpdates(_0xa8546d){return function(_0xbdffee){try{jsonpatch[_0xf730('0x23')](_0xbdffee,_0xa8546d,!![]);}catch(_0x16086b){return BPromise[_0xf730('0x24')](_0x16086b);}return _0xbdffee[_0xf730('0x25')]();};}function saveUpdates(_0x1161e9,_0x5495d6){return function(_0x331f5d){if(_0x331f5d){return _0x331f5d[_0xf730('0x26')](_0x1161e9)['then'](function(_0x3401a1){return _0x3401a1;});}return null;};}function removeEntity(_0x216291,_0x1b3f2d){return function(_0x11397f){if(_0x11397f){return _0x11397f['destroy']()[_0xf730('0x27')](function(){_0x216291[_0xf730('0x1e')](0xcc)[_0xf730('0x1d')]();});}};}function handleEntityNotFound(_0x28eb9c,_0x5a37fa){return function(_0x3a54b1){if(!_0x3a54b1){_0x28eb9c[_0xf730('0x1c')](0x194);}return _0x3a54b1;};}function handleError(_0x1f2e17,_0x15a2b0){_0x15a2b0=_0x15a2b0||0x1f4;return function(_0x5d8aa3){logger[_0xf730('0x28')](_0x5d8aa3[_0xf730('0x29')]);if(_0x5d8aa3[_0xf730('0x2a')]){delete _0x5d8aa3[_0xf730('0x2a')];}_0x1f2e17[_0xf730('0x1e')](_0x15a2b0)[_0xf730('0x2b')](_0x5d8aa3);};}exports['index']=function(_0x97bc86,_0x2b5b59){var _0x4e1686={},_0x4c652f={},_0x1b1beb={'count':0x0,'rows':[]};var _0x4c37e7=_[_0xf730('0x2c')](db[_0xf730('0x2d')][_0xf730('0x2e')],function(_0x4314e9){return{'name':_0x4314e9[_0xf730('0x2f')],'type':_0x4314e9[_0xf730('0x30')][_0xf730('0x31')]};});_0x4c652f[_0xf730('0x32')]=_[_0xf730('0x2c')](_0x4c37e7,'name');_0x4c652f[_0xf730('0x33')]=_[_0xf730('0x34')](_0x97bc86[_0xf730('0x33')]);_0x4c652f[_0xf730('0x35')]=_[_0xf730('0x36')](_0x4c652f['model'],_0x4c652f[_0xf730('0x33')]);_0x4e1686[_0xf730('0x37')]=_[_0xf730('0x36')](_0x4c652f[_0xf730('0x32')],qs[_0xf730('0x38')](_0x97bc86['query'][_0xf730('0x38')]));_0x4e1686[_0xf730('0x37')]=_0x4e1686[_0xf730('0x37')]['length']?_0x4e1686[_0xf730('0x37')]:_0x4c652f['model'];if(!_0x97bc86[_0xf730('0x33')]['hasOwnProperty'](_0xf730('0x39'))){_0x4e1686[_0xf730('0x3a')]=qs['limit'](_0x97bc86['query'][_0xf730('0x3a')]);_0x4e1686['offset']=qs['offset'](_0x97bc86['query'][_0xf730('0x21')]);}_0x4e1686['order']=qs[_0xf730('0x3b')](_0x97bc86[_0xf730('0x33')][_0xf730('0x3b')]);_0x4e1686[_0xf730('0x3c')]=qs[_0xf730('0x35')](_[_0xf730('0x3d')](_0x97bc86[_0xf730('0x33')],_0x4c652f[_0xf730('0x35')]));if(_0x97bc86[_0xf730('0x33')][_0xf730('0x3e')]){_0x4e1686['where']=_[_0xf730('0x3f')](_0x4e1686['where'],{'$or':_[_0xf730('0x2c')](_0x4c37e7,function(_0x13df20){if(_0x13df20[_0xf730('0x30')]!=='VIRTUAL'){var _0xf84eb5={};_0xf84eb5[_0x13df20[_0xf730('0x2a')]]={'$like':'%'+_0x97bc86['query'][_0xf730('0x3e')]+'%'};return _0xf84eb5;}})});}_0x4e1686=_['merge']({},_0x4e1686,_0x97bc86[_0xf730('0x40')]);var _0x51bd32={'where':_0x4e1686[_0xf730('0x3c')]};return db[_0xf730('0x2d')]['count'](_0x51bd32)['then'](function(_0x1b8ed2){_0x1b1beb[_0xf730('0x20')]=_0x1b8ed2;if(_0x97bc86[_0xf730('0x33')][_0xf730('0x41')]){_0x4e1686[_0xf730('0x42')]=[{'all':!![]}];}return db['FreshdeskField'][_0xf730('0x43')](_0x4e1686);})['then'](function(_0x4e326e){_0x1b1beb['rows']=_0x4e326e;return _0x1b1beb;})['then'](respondWithFilteredResult(_0x2b5b59,_0x4e1686))[_0xf730('0x44')](handleError(_0x2b5b59,null));};exports['show']=function(_0x467e71,_0x461644){var _0x38fb64={'raw':!![],'where':{'id':_0x467e71['params']['id']}},_0x569e9a={};_0x569e9a[_0xf730('0x32')]=_[_0xf730('0x34')](db['FreshdeskField'][_0xf730('0x2e')]);_0x569e9a[_0xf730('0x33')]=_[_0xf730('0x34')](_0x467e71['query']);_0x569e9a[_0xf730('0x35')]=_[_0xf730('0x36')](_0x569e9a[_0xf730('0x32')],_0x569e9a['query']);_0x38fb64[_0xf730('0x37')]=_[_0xf730('0x36')](_0x569e9a[_0xf730('0x32')],qs[_0xf730('0x38')](_0x467e71[_0xf730('0x33')][_0xf730('0x38')]));_0x38fb64[_0xf730('0x37')]=_0x38fb64[_0xf730('0x37')]['length']?_0x38fb64[_0xf730('0x37')]:_0x569e9a[_0xf730('0x32')];if(_0x467e71[_0xf730('0x33')][_0xf730('0x41')]){_0x38fb64[_0xf730('0x42')]=[{'all':!![]}];}_0x38fb64=_[_0xf730('0x3f')]({},_0x38fb64,_0x467e71['options']);return db[_0xf730('0x2d')][_0xf730('0x45')](_0x38fb64)[_0xf730('0x27')](handleEntityNotFound(_0x461644,null))[_0xf730('0x27')](respondWithResult(_0x461644,null))['catch'](handleError(_0x461644,null));};exports[_0xf730('0x46')]=function(_0x12047c,_0x1a6c17){return db[_0xf730('0x2d')]['create'](_0x12047c['body'],{})[_0xf730('0x27')](respondWithResult(_0x1a6c17,0xc9))['catch'](handleError(_0x1a6c17,null));};exports['update']=function(_0x572cf3,_0x3efddc){if(_0x572cf3[_0xf730('0x47')]['id']){delete _0x572cf3['body']['id'];}return db[_0xf730('0x2d')][_0xf730('0x45')]({'where':{'id':_0x572cf3[_0xf730('0x48')]['id']}})['then'](handleEntityNotFound(_0x3efddc,null))['then'](saveUpdates(_0x572cf3[_0xf730('0x47')],null))[_0xf730('0x27')](respondWithResult(_0x3efddc,null))[_0xf730('0x44')](handleError(_0x3efddc,null));};exports['destroy']=function(_0x4bbb63,_0x7e5cd9){return db[_0xf730('0x2d')]['find']({'where':{'id':_0x4bbb63[_0xf730('0x48')]['id']}})[_0xf730('0x27')](handleEntityNotFound(_0x7e5cd9,null))['then'](removeEntity(_0x7e5cd9,null))[_0xf730('0x44')](handleError(_0x7e5cd9,null));};