c251d032f274589a5732846f38c9a93564c604b2
[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 _0x780f=['FreshdeskField','rawAttributes','fieldName','key','map','name','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','type','options','includeAll','include','findAll','rows','catch','show','find','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','Content-Range','apply','save','update','then','destroy','error','stack','send','index'];(function(_0x46d1f6,_0x1008b9){var _0x11ef0a=function(_0x500639){while(--_0x500639){_0x46d1f6['push'](_0x46d1f6['shift']());}};_0x11ef0a(++_0x1008b9);}(_0x780f,0x6c));var _0xf780=function(_0x56825b,_0x172b8d){_0x56825b=_0x56825b-0x0;var _0x69ce77=_0x780f[_0x56825b];return _0x69ce77;};'use strict';var emlformat=require(_0xf780('0x0'));var rimraf=require(_0xf780('0x1'));var zipdir=require(_0xf780('0x2'));var jsonpatch=require(_0xf780('0x3'));var rp=require(_0xf780('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf780('0x5'));var util=require(_0xf780('0x6'));var path=require(_0xf780('0x7'));var sox=require(_0xf780('0x8'));var csv=require('to-csv');var ejs=require(_0xf780('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf780('0xa'));var squel=require(_0xf780('0xb'));var crypto=require(_0xf780('0xc'));var jsforce=require(_0xf780('0xd'));var deskjs=require(_0xf780('0xe'));var toCsv=require(_0xf780('0xf'));var querystring=require('querystring');var Papa=require(_0xf780('0x10'));var Redis=require(_0xf780('0x11'));var authService=require(_0xf780('0x12'));var qs=require(_0xf780('0x13'));var as=require(_0xf780('0x14'));var hardwareService=require(_0xf780('0x15'));var logger=require(_0xf780('0x16'))('api');var utils=require('../../config/utils');var config=require(_0xf780('0x17'));var licenseUtil=require(_0xf780('0x18'));var db=require(_0xf780('0x19'))['db'];function respondWithStatusCode(_0x1a8520,_0x5f04e1){_0x5f04e1=_0x5f04e1||0xcc;return function(_0x24aa4f){if(_0x24aa4f){return _0x1a8520[_0xf780('0x1a')](_0x5f04e1);}return _0x1a8520[_0xf780('0x1b')](_0x5f04e1)[_0xf780('0x1c')]();};}function respondWithResult(_0x5c353b,_0x5a64bc){_0x5a64bc=_0x5a64bc||0xc8;return function(_0x4be599){if(_0x4be599){return _0x5c353b[_0xf780('0x1b')](_0x5a64bc)[_0xf780('0x1d')](_0x4be599);}};}function respondWithFilteredResult(_0xc1e872,_0x187b6d){return function(_0x206d34){if(_0x206d34){var _0x335ba6=typeof _0x187b6d[_0xf780('0x1e')]==='undefined'&&typeof _0x187b6d[_0xf780('0x1f')]===_0xf780('0x20');var _0xa78b1b=_0x206d34[_0xf780('0x21')];var _0x5d5a81=_0x335ba6?0x0:_0x187b6d[_0xf780('0x1e')];var _0x53dfee=_0x335ba6?_0x206d34[_0xf780('0x21')]:_0x187b6d[_0xf780('0x1e')]+_0x187b6d['limit'];var _0x29dae1;if(_0x53dfee>=_0xa78b1b){_0x53dfee=_0xa78b1b;_0x29dae1=0xc8;}else{_0x29dae1=0xce;}_0xc1e872[_0xf780('0x1b')](_0x29dae1);return _0xc1e872['set'](_0xf780('0x22'),_0x5d5a81+'-'+_0x53dfee+'/'+_0xa78b1b)[_0xf780('0x1d')](_0x206d34);}return null;};}function patchUpdates(_0x3c7054){return function(_0x4065bb){try{jsonpatch[_0xf780('0x23')](_0x4065bb,_0x3c7054,!![]);}catch(_0x147de9){return BPromise['reject'](_0x147de9);}return _0x4065bb[_0xf780('0x24')]();};}function saveUpdates(_0x4de546,_0x5853ea){return function(_0x45d80e){if(_0x45d80e){return _0x45d80e[_0xf780('0x25')](_0x4de546)[_0xf780('0x26')](function(_0x58bb66){return _0x58bb66;});}return null;};}function removeEntity(_0x2fcb2d,_0x373dce){return function(_0x4f59b1){if(_0x4f59b1){return _0x4f59b1[_0xf780('0x27')]()['then'](function(){_0x2fcb2d[_0xf780('0x1b')](0xcc)[_0xf780('0x1c')]();});}};}function handleEntityNotFound(_0x5d4053,_0x589208){return function(_0x3710bb){if(!_0x3710bb){_0x5d4053[_0xf780('0x1a')](0x194);}return _0x3710bb;};}function handleError(_0x462435,_0x40d9c9){_0x40d9c9=_0x40d9c9||0x1f4;return function(_0x458c76){logger[_0xf780('0x28')](_0x458c76[_0xf780('0x29')]);if(_0x458c76['name']){delete _0x458c76['name'];}_0x462435['status'](_0x40d9c9)[_0xf780('0x2a')](_0x458c76);};}exports[_0xf780('0x2b')]=function(_0x26452f,_0x4ef8c3){var _0x4ed256={},_0x36bc63={},_0x149190={'count':0x0,'rows':[]};var _0x2b832d=_['map'](db[_0xf780('0x2c')][_0xf780('0x2d')],function(_0x2368e3){return{'name':_0x2368e3[_0xf780('0x2e')],'type':_0x2368e3['type'][_0xf780('0x2f')]};});_0x36bc63['model']=_[_0xf780('0x30')](_0x2b832d,_0xf780('0x31'));_0x36bc63[_0xf780('0x32')]=_[_0xf780('0x33')](_0x26452f[_0xf780('0x32')]);_0x36bc63[_0xf780('0x34')]=_[_0xf780('0x35')](_0x36bc63[_0xf780('0x36')],_0x36bc63['query']);_0x4ed256[_0xf780('0x37')]=_[_0xf780('0x35')](_0x36bc63[_0xf780('0x36')],qs[_0xf780('0x38')](_0x26452f[_0xf780('0x32')]['fields']));_0x4ed256[_0xf780('0x37')]=_0x4ed256['attributes'][_0xf780('0x39')]?_0x4ed256[_0xf780('0x37')]:_0x36bc63[_0xf780('0x36')];if(!_0x26452f['query'][_0xf780('0x3a')](_0xf780('0x3b'))){_0x4ed256[_0xf780('0x1f')]=qs[_0xf780('0x1f')](_0x26452f['query'][_0xf780('0x1f')]);_0x4ed256['offset']=qs[_0xf780('0x1e')](_0x26452f['query']['offset']);}_0x4ed256[_0xf780('0x3c')]=qs['sort'](_0x26452f[_0xf780('0x32')][_0xf780('0x3d')]);_0x4ed256[_0xf780('0x3e')]=qs[_0xf780('0x34')](_['pick'](_0x26452f[_0xf780('0x32')],_0x36bc63[_0xf780('0x34')]),_0x2b832d);if(_0x26452f[_0xf780('0x32')][_0xf780('0x3f')]){_0x4ed256['where']=_[_0xf780('0x40')](_0x4ed256[_0xf780('0x3e')],{'$or':_[_0xf780('0x30')](_0x2b832d,function(_0xdac8ab){if(_0xdac8ab[_0xf780('0x41')]!=='VIRTUAL'){var _0x4b8a3c={};_0x4b8a3c[_0xdac8ab[_0xf780('0x31')]]={'$like':'%'+_0x26452f[_0xf780('0x32')][_0xf780('0x3f')]+'%'};return _0x4b8a3c;}})});}_0x4ed256=_[_0xf780('0x40')]({},_0x4ed256,_0x26452f[_0xf780('0x42')]);var _0x4a0efe={'where':_0x4ed256[_0xf780('0x3e')]};return db['FreshdeskField'][_0xf780('0x21')](_0x4a0efe)[_0xf780('0x26')](function(_0x28783f){_0x149190[_0xf780('0x21')]=_0x28783f;if(_0x26452f['query'][_0xf780('0x43')]){_0x4ed256[_0xf780('0x44')]=[{'all':!![]}];}return db[_0xf780('0x2c')][_0xf780('0x45')](_0x4ed256);})[_0xf780('0x26')](function(_0x12ae9a){_0x149190[_0xf780('0x46')]=_0x12ae9a;return _0x149190;})[_0xf780('0x26')](respondWithFilteredResult(_0x4ef8c3,_0x4ed256))[_0xf780('0x47')](handleError(_0x4ef8c3,null));};exports[_0xf780('0x48')]=function(_0x143118,_0x30a036){var _0x406a9e={'raw':!![],'where':{'id':_0x143118['params']['id']}},_0x42a710={};_0x42a710[_0xf780('0x36')]=_['keys'](db[_0xf780('0x2c')][_0xf780('0x2d')]);_0x42a710['query']=_['keys'](_0x143118['query']);_0x42a710['filters']=_[_0xf780('0x35')](_0x42a710['model'],_0x42a710[_0xf780('0x32')]);_0x406a9e[_0xf780('0x37')]=_[_0xf780('0x35')](_0x42a710[_0xf780('0x36')],qs[_0xf780('0x38')](_0x143118['query']['fields']));_0x406a9e['attributes']=_0x406a9e['attributes'][_0xf780('0x39')]?_0x406a9e[_0xf780('0x37')]:_0x42a710[_0xf780('0x36')];if(_0x143118[_0xf780('0x32')][_0xf780('0x43')]){_0x406a9e[_0xf780('0x44')]=[{'all':!![]}];}_0x406a9e=_['merge']({},_0x406a9e,_0x143118[_0xf780('0x42')]);return db[_0xf780('0x2c')][_0xf780('0x49')](_0x406a9e)[_0xf780('0x26')](handleEntityNotFound(_0x30a036,null))[_0xf780('0x26')](respondWithResult(_0x30a036,null))[_0xf780('0x47')](handleError(_0x30a036,null));};exports['create']=function(_0x26fe74,_0x5c4170){return db[_0xf780('0x2c')]['create'](_0x26fe74[_0xf780('0x4a')],{})['then'](respondWithResult(_0x5c4170,0xc9))['catch'](handleError(_0x5c4170,null));};exports[_0xf780('0x25')]=function(_0x72a225,_0x189717){if(_0x72a225[_0xf780('0x4a')]['id']){delete _0x72a225['body']['id'];}return db[_0xf780('0x2c')][_0xf780('0x49')]({'where':{'id':_0x72a225[_0xf780('0x4b')]['id']}})[_0xf780('0x26')](handleEntityNotFound(_0x189717,null))[_0xf780('0x26')](saveUpdates(_0x72a225['body'],null))[_0xf780('0x26')](respondWithResult(_0x189717,null))['catch'](handleError(_0x189717,null));};exports[_0xf780('0x27')]=function(_0x1b492a,_0x22c52d){return db[_0xf780('0x2c')][_0xf780('0x49')]({'where':{'id':_0x1b492a['params']['id']}})['then'](handleEntityNotFound(_0x22c52d,null))[_0xf780('0x26')](removeEntity(_0x22c52d,null))[_0xf780('0x47')](handleError(_0x22c52d,null));};