af06a5dc9b1e311b0c24cef3ce58f0d71bdc466e
[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 _0x2c5f=['where','pick','filter','type','VIRTUAL','options','includeAll','include','findAll','show','keys','merge','find','catch','create','body','params','eml-format','rimraf','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/util','../../mysqldb','sendStatus','status','end','json','limit','undefined','count','offset','Content-Range','apply','reject','save','update','destroy','then','error','stack','name','send','index','map','ZendeskField','rawAttributes','fieldName','model','query','intersection','attributes','fields','length','nolimit','order','sort'];(function(_0x5c351c,_0x2046d8){var _0x26f3b3=function(_0x47ac18){while(--_0x47ac18){_0x5c351c['push'](_0x5c351c['shift']());}};_0x26f3b3(++_0x2046d8);}(_0x2c5f,0x139));var _0xf2c5=function(_0x32f7d7,_0x54231b){_0x32f7d7=_0x32f7d7-0x0;var _0x133d09=_0x2c5f[_0x32f7d7];return _0x133d09;};'use strict';var emlformat=require(_0xf2c5('0x0'));var rimraf=require(_0xf2c5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf2c5('0x2'));var rp=require('request-promise');var moment=require(_0xf2c5('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xf2c5('0x4'));var util=require(_0xf2c5('0x5'));var path=require(_0xf2c5('0x6'));var sox=require(_0xf2c5('0x7'));var csv=require(_0xf2c5('0x8'));var ejs=require(_0xf2c5('0x9'));var fs=require('fs');var fs_extra=require(_0xf2c5('0xa'));var _=require(_0xf2c5('0xb'));var squel=require(_0xf2c5('0xc'));var crypto=require(_0xf2c5('0xd'));var jsforce=require(_0xf2c5('0xe'));var deskjs=require(_0xf2c5('0xf'));var toCsv=require(_0xf2c5('0x8'));var querystring=require(_0xf2c5('0x10'));var Papa=require(_0xf2c5('0x11'));var Redis=require(_0xf2c5('0x12'));var authService=require(_0xf2c5('0x13'));var qs=require(_0xf2c5('0x14'));var as=require(_0xf2c5('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xf2c5('0x16'));var db=require(_0xf2c5('0x17'))['db'];function respondWithStatusCode(_0x17584d,_0x4eb01c){_0x4eb01c=_0x4eb01c||0xcc;return function(_0xa658a){if(_0xa658a){return _0x17584d[_0xf2c5('0x18')](_0x4eb01c);}return _0x17584d[_0xf2c5('0x19')](_0x4eb01c)[_0xf2c5('0x1a')]();};}function respondWithResult(_0x58c39a,_0x5e2f41){_0x5e2f41=_0x5e2f41||0xc8;return function(_0x2b360a){if(_0x2b360a){return _0x58c39a[_0xf2c5('0x19')](_0x5e2f41)[_0xf2c5('0x1b')](_0x2b360a);}};}function respondWithFilteredResult(_0x527c40,_0xfef83a){return function(_0x3ad188){if(_0x3ad188){var _0x14a696=typeof _0xfef83a['offset']==='undefined'&&typeof _0xfef83a[_0xf2c5('0x1c')]===_0xf2c5('0x1d');var _0x1fefb8=_0x3ad188[_0xf2c5('0x1e')];var _0x225f1d=_0x14a696?0x0:_0xfef83a[_0xf2c5('0x1f')];var _0x5c7e68=_0x14a696?_0x3ad188[_0xf2c5('0x1e')]:_0xfef83a['offset']+_0xfef83a[_0xf2c5('0x1c')];var _0x27b22f;if(_0x5c7e68>=_0x1fefb8){_0x5c7e68=_0x1fefb8;_0x27b22f=0xc8;}else{_0x27b22f=0xce;}_0x527c40[_0xf2c5('0x19')](_0x27b22f);return _0x527c40['set'](_0xf2c5('0x20'),_0x225f1d+'-'+_0x5c7e68+'/'+_0x1fefb8)['json'](_0x3ad188);}return null;};}function patchUpdates(_0x1bd38a){return function(_0x1fcf71){try{jsonpatch[_0xf2c5('0x21')](_0x1fcf71,_0x1bd38a,!![]);}catch(_0x9b6932){return BPromise[_0xf2c5('0x22')](_0x9b6932);}return _0x1fcf71[_0xf2c5('0x23')]();};}function saveUpdates(_0xf08496,_0x1c4dbc){return function(_0x1ad5e5){if(_0x1ad5e5){return _0x1ad5e5[_0xf2c5('0x24')](_0xf08496)['then'](function(_0x5395df){return _0x5395df;});}return null;};}function removeEntity(_0x7a2a8a,_0x64a560){return function(_0x1a3619){if(_0x1a3619){return _0x1a3619[_0xf2c5('0x25')]()[_0xf2c5('0x26')](function(){_0x7a2a8a[_0xf2c5('0x19')](0xcc)[_0xf2c5('0x1a')]();});}};}function handleEntityNotFound(_0x530469,_0x224886){return function(_0xed4da6){if(!_0xed4da6){_0x530469[_0xf2c5('0x18')](0x194);}return _0xed4da6;};}function handleError(_0x224cf1,_0x375090){_0x375090=_0x375090||0x1f4;return function(_0x133330){logger[_0xf2c5('0x27')](_0x133330[_0xf2c5('0x28')]);if(_0x133330['name']){delete _0x133330[_0xf2c5('0x29')];}_0x224cf1['status'](_0x375090)[_0xf2c5('0x2a')](_0x133330);};}exports[_0xf2c5('0x2b')]=function(_0x55968c,_0x4af1ad){var _0x19c377={},_0x5e0ecc={},_0x4f89f0={'count':0x0,'rows':[]};var _0x3ee102=_[_0xf2c5('0x2c')](db[_0xf2c5('0x2d')][_0xf2c5('0x2e')],function(_0x2f43f5){return{'name':_0x2f43f5[_0xf2c5('0x2f')],'type':_0x2f43f5['type']['key']};});_0x5e0ecc[_0xf2c5('0x30')]=_['map'](_0x3ee102,_0xf2c5('0x29'));_0x5e0ecc[_0xf2c5('0x31')]=_['keys'](_0x55968c[_0xf2c5('0x31')]);_0x5e0ecc['filters']=_[_0xf2c5('0x32')](_0x5e0ecc[_0xf2c5('0x30')],_0x5e0ecc[_0xf2c5('0x31')]);_0x19c377[_0xf2c5('0x33')]=_[_0xf2c5('0x32')](_0x5e0ecc[_0xf2c5('0x30')],qs[_0xf2c5('0x34')](_0x55968c[_0xf2c5('0x31')][_0xf2c5('0x34')]));_0x19c377[_0xf2c5('0x33')]=_0x19c377[_0xf2c5('0x33')][_0xf2c5('0x35')]?_0x19c377[_0xf2c5('0x33')]:_0x5e0ecc[_0xf2c5('0x30')];if(!_0x55968c[_0xf2c5('0x31')]['hasOwnProperty'](_0xf2c5('0x36'))){_0x19c377[_0xf2c5('0x1c')]=qs[_0xf2c5('0x1c')](_0x55968c[_0xf2c5('0x31')][_0xf2c5('0x1c')]);_0x19c377['offset']=qs['offset'](_0x55968c[_0xf2c5('0x31')][_0xf2c5('0x1f')]);}_0x19c377[_0xf2c5('0x37')]=qs[_0xf2c5('0x38')](_0x55968c[_0xf2c5('0x31')][_0xf2c5('0x38')]);_0x19c377[_0xf2c5('0x39')]=qs['filters'](_[_0xf2c5('0x3a')](_0x55968c['query'],_0x5e0ecc['filters']),_0x3ee102);if(_0x55968c[_0xf2c5('0x31')][_0xf2c5('0x3b')]){_0x19c377[_0xf2c5('0x39')]=_['merge'](_0x19c377[_0xf2c5('0x39')],{'$or':_['map'](_0x3ee102,function(_0x2e462e){if(_0x2e462e[_0xf2c5('0x3c')]!==_0xf2c5('0x3d')){var _0x76ed51={};_0x76ed51[_0x2e462e[_0xf2c5('0x29')]]={'$like':'%'+_0x55968c[_0xf2c5('0x31')][_0xf2c5('0x3b')]+'%'};return _0x76ed51;}})});}_0x19c377=_['merge']({},_0x19c377,_0x55968c[_0xf2c5('0x3e')]);var _0xafeb99={'where':_0x19c377['where']};return db[_0xf2c5('0x2d')]['count'](_0xafeb99)['then'](function(_0x52fd1b){_0x4f89f0[_0xf2c5('0x1e')]=_0x52fd1b;if(_0x55968c['query'][_0xf2c5('0x3f')]){_0x19c377[_0xf2c5('0x40')]=[{'all':!![]}];}return db[_0xf2c5('0x2d')][_0xf2c5('0x41')](_0x19c377);})[_0xf2c5('0x26')](function(_0x3cd702){_0x4f89f0['rows']=_0x3cd702;return _0x4f89f0;})['then'](respondWithFilteredResult(_0x4af1ad,_0x19c377))['catch'](handleError(_0x4af1ad,null));};exports[_0xf2c5('0x42')]=function(_0x14cc34,_0x2bcf86){var _0x4a3f61={'raw':!![],'where':{'id':_0x14cc34['params']['id']}},_0x81ade1={};_0x81ade1[_0xf2c5('0x30')]=_['keys'](db['ZendeskField'][_0xf2c5('0x2e')]);_0x81ade1['query']=_[_0xf2c5('0x43')](_0x14cc34[_0xf2c5('0x31')]);_0x81ade1['filters']=_[_0xf2c5('0x32')](_0x81ade1[_0xf2c5('0x30')],_0x81ade1['query']);_0x4a3f61[_0xf2c5('0x33')]=_[_0xf2c5('0x32')](_0x81ade1['model'],qs[_0xf2c5('0x34')](_0x14cc34[_0xf2c5('0x31')]['fields']));_0x4a3f61[_0xf2c5('0x33')]=_0x4a3f61[_0xf2c5('0x33')][_0xf2c5('0x35')]?_0x4a3f61[_0xf2c5('0x33')]:_0x81ade1[_0xf2c5('0x30')];if(_0x14cc34['query'][_0xf2c5('0x3f')]){_0x4a3f61[_0xf2c5('0x40')]=[{'all':!![]}];}_0x4a3f61=_[_0xf2c5('0x44')]({},_0x4a3f61,_0x14cc34['options']);return db['ZendeskField'][_0xf2c5('0x45')](_0x4a3f61)['then'](handleEntityNotFound(_0x2bcf86,null))[_0xf2c5('0x26')](respondWithResult(_0x2bcf86,null))[_0xf2c5('0x46')](handleError(_0x2bcf86,null));};exports[_0xf2c5('0x47')]=function(_0x1b80c2,_0xc62128){return db[_0xf2c5('0x2d')][_0xf2c5('0x47')](_0x1b80c2[_0xf2c5('0x48')],{})[_0xf2c5('0x26')](respondWithResult(_0xc62128,0xc9))['catch'](handleError(_0xc62128,null));};exports['update']=function(_0x23ef79,_0x52303d){if(_0x23ef79[_0xf2c5('0x48')]['id']){delete _0x23ef79[_0xf2c5('0x48')]['id'];}return db[_0xf2c5('0x2d')]['find']({'where':{'id':_0x23ef79['params']['id']}})[_0xf2c5('0x26')](handleEntityNotFound(_0x52303d,null))[_0xf2c5('0x26')](saveUpdates(_0x23ef79['body'],null))[_0xf2c5('0x26')](respondWithResult(_0x52303d,null))[_0xf2c5('0x46')](handleError(_0x52303d,null));};exports[_0xf2c5('0x25')]=function(_0x1b7543,_0x127d09){return db[_0xf2c5('0x2d')][_0xf2c5('0x45')]({'where':{'id':_0x1b7543[_0xf2c5('0x49')]['id']}})[_0xf2c5('0x26')](handleEntityNotFound(_0x127d09,null))['then'](removeEntity(_0x127d09,null))['catch'](handleError(_0x127d09,null));};