Built motion from commit 00bf23f6.|2.6.16
[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 _0x3d0a=['stack','name','send','index','map','ZendeskField','rawAttributes','fieldName','key','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','model','merge','find','create','body','params','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','ejs','fs-extra','lodash','jsforce','querystring','ioredis','../../components/parsers/qs','../../config/environment','../../config/license/util','end','status','json','offset','limit','undefined','count','Content-Range','reject','update','then','destroy','sendStatus'];(function(_0x56f7e2,_0x145392){var _0x36240b=function(_0x216ff7){while(--_0x216ff7){_0x56f7e2['push'](_0x56f7e2['shift']());}};_0x36240b(++_0x145392);}(_0x3d0a,0xa9));var _0xa3d0=function(_0x13e741,_0x5d3c24){_0x13e741=_0x13e741-0x0;var _0x3f8bb3=_0x3d0a[_0x13e741];return _0x3f8bb3;};'use strict';var emlformat=require(_0xa3d0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xa3d0('0x1'));var jsonpatch=require(_0xa3d0('0x2'));var rp=require(_0xa3d0('0x3'));var moment=require(_0xa3d0('0x4'));var BPromise=require(_0xa3d0('0x5'));var Mustache=require(_0xa3d0('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xa3d0('0x7'));var fs=require('fs');var fs_extra=require(_0xa3d0('0x8'));var _=require(_0xa3d0('0x9'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xa3d0('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xa3d0('0xb'));var Papa=require('papaparse');var Redis=require(_0xa3d0('0xc'));var authService=require('../../components/auth/service');var qs=require(_0xa3d0('0xd'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0xa3d0('0xe'));var licenseUtil=require(_0xa3d0('0xf'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4d75bf,_0xc67d9b){_0xc67d9b=_0xc67d9b||0xcc;return function(_0x566891){if(_0x566891){return _0x4d75bf['sendStatus'](_0xc67d9b);}return _0x4d75bf['status'](_0xc67d9b)[_0xa3d0('0x10')]();};}function respondWithResult(_0x2c87b6,_0x3b5b82){_0x3b5b82=_0x3b5b82||0xc8;return function(_0x248438){if(_0x248438){return _0x2c87b6[_0xa3d0('0x11')](_0x3b5b82)[_0xa3d0('0x12')](_0x248438);}};}function respondWithFilteredResult(_0x20ca47,_0x5e77c0){return function(_0xb8ec3e){if(_0xb8ec3e){var _0xa7d703=typeof _0x5e77c0[_0xa3d0('0x13')]==='undefined'&&typeof _0x5e77c0[_0xa3d0('0x14')]===_0xa3d0('0x15');var _0x474ff8=_0xb8ec3e[_0xa3d0('0x16')];var _0x2e138f=_0xa7d703?0x0:_0x5e77c0[_0xa3d0('0x13')];var _0x46ff69=_0xa7d703?_0xb8ec3e[_0xa3d0('0x16')]:_0x5e77c0[_0xa3d0('0x13')]+_0x5e77c0[_0xa3d0('0x14')];var _0x872f91;if(_0x46ff69>=_0x474ff8){_0x46ff69=_0x474ff8;_0x872f91=0xc8;}else{_0x872f91=0xce;}_0x20ca47[_0xa3d0('0x11')](_0x872f91);return _0x20ca47['set'](_0xa3d0('0x17'),_0x2e138f+'-'+_0x46ff69+'/'+_0x474ff8)[_0xa3d0('0x12')](_0xb8ec3e);}return null;};}function patchUpdates(_0x466155){return function(_0x210610){try{jsonpatch['apply'](_0x210610,_0x466155,!![]);}catch(_0x42d0d4){return BPromise[_0xa3d0('0x18')](_0x42d0d4);}return _0x210610['save']();};}function saveUpdates(_0x3ee373,_0x16c7c2){return function(_0x322a17){if(_0x322a17){return _0x322a17[_0xa3d0('0x19')](_0x3ee373)[_0xa3d0('0x1a')](function(_0x2865c6){return _0x2865c6;});}return null;};}function removeEntity(_0x4b6931,_0x4482af){return function(_0x457556){if(_0x457556){return _0x457556[_0xa3d0('0x1b')]()[_0xa3d0('0x1a')](function(){_0x4b6931[_0xa3d0('0x11')](0xcc)[_0xa3d0('0x10')]();});}};}function handleEntityNotFound(_0x52b62e,_0x2a1175){return function(_0x38136f){if(!_0x38136f){_0x52b62e[_0xa3d0('0x1c')](0x194);}return _0x38136f;};}function handleError(_0x4e3272,_0x57ff94){_0x57ff94=_0x57ff94||0x1f4;return function(_0x4e52d9){logger['error'](_0x4e52d9[_0xa3d0('0x1d')]);if(_0x4e52d9[_0xa3d0('0x1e')]){delete _0x4e52d9['name'];}_0x4e3272[_0xa3d0('0x11')](_0x57ff94)[_0xa3d0('0x1f')](_0x4e52d9);};}exports[_0xa3d0('0x20')]=function(_0x168677,_0x4ec6df){var _0x2990ea={},_0x265735={},_0x15bdb7={'count':0x0,'rows':[]};var _0x582f9b=_[_0xa3d0('0x21')](db[_0xa3d0('0x22')][_0xa3d0('0x23')],function(_0x56953b){return{'name':_0x56953b[_0xa3d0('0x24')],'type':_0x56953b['type'][_0xa3d0('0x25')]};});_0x265735['model']=_[_0xa3d0('0x21')](_0x582f9b,_0xa3d0('0x1e'));_0x265735[_0xa3d0('0x26')]=_[_0xa3d0('0x27')](_0x168677[_0xa3d0('0x26')]);_0x265735['filters']=_[_0xa3d0('0x28')](_0x265735['model'],_0x265735[_0xa3d0('0x26')]);_0x2990ea[_0xa3d0('0x29')]=_[_0xa3d0('0x28')](_0x265735['model'],qs[_0xa3d0('0x2a')](_0x168677['query'][_0xa3d0('0x2a')]));_0x2990ea[_0xa3d0('0x29')]=_0x2990ea['attributes'][_0xa3d0('0x2b')]?_0x2990ea[_0xa3d0('0x29')]:_0x265735['model'];if(!_0x168677[_0xa3d0('0x26')][_0xa3d0('0x2c')](_0xa3d0('0x2d'))){_0x2990ea[_0xa3d0('0x14')]=qs[_0xa3d0('0x14')](_0x168677[_0xa3d0('0x26')][_0xa3d0('0x14')]);_0x2990ea['offset']=qs['offset'](_0x168677[_0xa3d0('0x26')][_0xa3d0('0x13')]);}_0x2990ea[_0xa3d0('0x2e')]=qs[_0xa3d0('0x2f')](_0x168677[_0xa3d0('0x26')][_0xa3d0('0x2f')]);_0x2990ea['where']=qs[_0xa3d0('0x30')](_[_0xa3d0('0x31')](_0x168677[_0xa3d0('0x26')],_0x265735['filters']),_0x582f9b);if(_0x168677[_0xa3d0('0x26')][_0xa3d0('0x32')]){_0x2990ea[_0xa3d0('0x33')]=_['merge'](_0x2990ea[_0xa3d0('0x33')],{'$or':_['map'](_0x582f9b,function(_0x2d5069){if(_0x2d5069['type']!==_0xa3d0('0x34')){var _0x22c5da={};_0x22c5da[_0x2d5069[_0xa3d0('0x1e')]]={'$like':'%'+_0x168677[_0xa3d0('0x26')][_0xa3d0('0x32')]+'%'};return _0x22c5da;}})});}_0x2990ea=_['merge']({},_0x2990ea,_0x168677[_0xa3d0('0x35')]);var _0x1a1497={'where':_0x2990ea[_0xa3d0('0x33')]};return db['ZendeskField'][_0xa3d0('0x16')](_0x1a1497)[_0xa3d0('0x1a')](function(_0x499ece){_0x15bdb7[_0xa3d0('0x16')]=_0x499ece;if(_0x168677[_0xa3d0('0x26')][_0xa3d0('0x36')]){_0x2990ea[_0xa3d0('0x37')]=[{'all':!![]}];}return db[_0xa3d0('0x22')][_0xa3d0('0x38')](_0x2990ea);})[_0xa3d0('0x1a')](function(_0xd2847e){_0x15bdb7[_0xa3d0('0x39')]=_0xd2847e;return _0x15bdb7;})[_0xa3d0('0x1a')](respondWithFilteredResult(_0x4ec6df,_0x2990ea))[_0xa3d0('0x3a')](handleError(_0x4ec6df,null));};exports[_0xa3d0('0x3b')]=function(_0x14404e,_0x476f49){var _0x1df34d={'raw':!![],'where':{'id':_0x14404e['params']['id']}},_0x1df7e6={};_0x1df7e6[_0xa3d0('0x3c')]=_[_0xa3d0('0x27')](db[_0xa3d0('0x22')][_0xa3d0('0x23')]);_0x1df7e6[_0xa3d0('0x26')]=_['keys'](_0x14404e[_0xa3d0('0x26')]);_0x1df7e6[_0xa3d0('0x30')]=_['intersection'](_0x1df7e6['model'],_0x1df7e6['query']);_0x1df34d[_0xa3d0('0x29')]=_[_0xa3d0('0x28')](_0x1df7e6['model'],qs['fields'](_0x14404e['query'][_0xa3d0('0x2a')]));_0x1df34d['attributes']=_0x1df34d[_0xa3d0('0x29')][_0xa3d0('0x2b')]?_0x1df34d[_0xa3d0('0x29')]:_0x1df7e6[_0xa3d0('0x3c')];if(_0x14404e[_0xa3d0('0x26')]['includeAll']){_0x1df34d[_0xa3d0('0x37')]=[{'all':!![]}];}_0x1df34d=_[_0xa3d0('0x3d')]({},_0x1df34d,_0x14404e[_0xa3d0('0x35')]);return db[_0xa3d0('0x22')][_0xa3d0('0x3e')](_0x1df34d)[_0xa3d0('0x1a')](handleEntityNotFound(_0x476f49,null))[_0xa3d0('0x1a')](respondWithResult(_0x476f49,null))[_0xa3d0('0x3a')](handleError(_0x476f49,null));};exports[_0xa3d0('0x3f')]=function(_0x5b845c,_0x5d787e){return db[_0xa3d0('0x22')][_0xa3d0('0x3f')](_0x5b845c[_0xa3d0('0x40')],{})[_0xa3d0('0x1a')](respondWithResult(_0x5d787e,0xc9))['catch'](handleError(_0x5d787e,null));};exports[_0xa3d0('0x19')]=function(_0x3c23f1,_0x4bb1ee){if(_0x3c23f1[_0xa3d0('0x40')]['id']){delete _0x3c23f1[_0xa3d0('0x40')]['id'];}return db[_0xa3d0('0x22')]['find']({'where':{'id':_0x3c23f1[_0xa3d0('0x41')]['id']}})[_0xa3d0('0x1a')](handleEntityNotFound(_0x4bb1ee,null))[_0xa3d0('0x1a')](saveUpdates(_0x3c23f1[_0xa3d0('0x40')],null))[_0xa3d0('0x1a')](respondWithResult(_0x4bb1ee,null))['catch'](handleError(_0x4bb1ee,null));};exports[_0xa3d0('0x1b')]=function(_0x460fa3,_0x2fc568){return db[_0xa3d0('0x22')]['find']({'where':{'id':_0x460fa3[_0xa3d0('0x41')]['id']}})[_0xa3d0('0x1a')](handleEntityNotFound(_0x2fc568,null))[_0xa3d0('0x1a')](removeEntity(_0x2fc568,null))[_0xa3d0('0x3a')](handleError(_0x2fc568,null));};