Built motion from commit (unavailable).|2.5.26
[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 _0xfc73=['fields','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','map','type','VIRTUAL','merge','options','count','include','findAll','rows','show','params','rawAttributes','length','includeAll','find','catch','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','fs-extra','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','set','Content-Range','json','apply','reject','save','update','then','destroy','name','send','index','ZendeskField','fieldName','model','query','keys','filters','intersection','attributes'];(function(_0x1fbd7f,_0xb760d3){var _0x3ed290=function(_0x431303){while(--_0x431303){_0x1fbd7f['push'](_0x1fbd7f['shift']());}};_0x3ed290(++_0xb760d3);}(_0xfc73,0x153));var _0x3fc7=function(_0x411017,_0x4a8117){_0x411017=_0x411017-0x0;var _0x2adeea=_0xfc73[_0x411017];return _0x2adeea;};'use strict';var emlformat=require(_0x3fc7('0x0'));var rimraf=require(_0x3fc7('0x1'));var zipdir=require(_0x3fc7('0x2'));var jsonpatch=require(_0x3fc7('0x3'));var rp=require(_0x3fc7('0x4'));var moment=require(_0x3fc7('0x5'));var BPromise=require(_0x3fc7('0x6'));var Mustache=require(_0x3fc7('0x7'));var util=require(_0x3fc7('0x8'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3fc7('0x9'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x3fc7('0xa'));var jsforce=require(_0x3fc7('0xb'));var deskjs=require(_0x3fc7('0xc'));var toCsv=require(_0x3fc7('0xd'));var querystring=require(_0x3fc7('0xe'));var Papa=require(_0x3fc7('0xf'));var Redis=require(_0x3fc7('0x10'));var authService=require(_0x3fc7('0x11'));var qs=require(_0x3fc7('0x12'));var as=require(_0x3fc7('0x13'));var hardwareService=require(_0x3fc7('0x14'));var logger=require(_0x3fc7('0x15'))(_0x3fc7('0x16'));var utils=require(_0x3fc7('0x17'));var config=require(_0x3fc7('0x18'));var licenseUtil=require(_0x3fc7('0x19'));var db=require(_0x3fc7('0x1a'))['db'];function respondWithStatusCode(_0xaa1e5e,_0x50e6cb){_0x50e6cb=_0x50e6cb||0xcc;return function(_0x11b300){if(_0x11b300){return _0xaa1e5e[_0x3fc7('0x1b')](_0x50e6cb);}return _0xaa1e5e[_0x3fc7('0x1c')](_0x50e6cb)[_0x3fc7('0x1d')]();};}function respondWithResult(_0x2bdc84,_0x548649){_0x548649=_0x548649||0xc8;return function(_0x592433){if(_0x592433){return _0x2bdc84['status'](_0x548649)['json'](_0x592433);}};}function respondWithFilteredResult(_0x285302,_0x16d139){return function(_0x5c5d23){if(_0x5c5d23){var _0x35c273=_0x5c5d23['count'],_0xef2df2=_0x16d139[_0x3fc7('0x1e')],_0x2798d1=_0x16d139[_0x3fc7('0x1e')]+_0x16d139['limit'],_0x4c3c6d;if(_0x2798d1>=_0x35c273){_0x2798d1=_0x35c273;_0x4c3c6d=0xc8;}else{_0x4c3c6d=0xce;}_0x285302[_0x3fc7('0x1c')](_0x4c3c6d);return _0x285302[_0x3fc7('0x1f')](_0x3fc7('0x20'),_0xef2df2+'-'+_0x2798d1+'/'+_0x35c273)[_0x3fc7('0x21')](_0x5c5d23);}return null;};}function patchUpdates(_0x33f10f){return function(_0xeaff){try{jsonpatch[_0x3fc7('0x22')](_0xeaff,_0x33f10f,!![]);}catch(_0x1ab33d){return BPromise[_0x3fc7('0x23')](_0x1ab33d);}return _0xeaff[_0x3fc7('0x24')]();};}function saveUpdates(_0x328ee1,_0x55da0b){return function(_0x190907){if(_0x190907){return _0x190907[_0x3fc7('0x25')](_0x328ee1)[_0x3fc7('0x26')](function(_0x4a7b47){return _0x4a7b47;});}return null;};}function removeEntity(_0x18f7f0,_0x3769bc){return function(_0x51e097){if(_0x51e097){return _0x51e097[_0x3fc7('0x27')]()[_0x3fc7('0x26')](function(){_0x18f7f0[_0x3fc7('0x1c')](0xcc)[_0x3fc7('0x1d')]();});}};}function handleEntityNotFound(_0x1d31ec,_0x208b78){return function(_0x118dc1){if(!_0x118dc1){_0x1d31ec[_0x3fc7('0x1b')](0x194);}return _0x118dc1;};}function handleError(_0x31cc0b,_0x1e9930){_0x1e9930=_0x1e9930||0x1f4;return function(_0x2de965){logger['error'](_0x2de965['stack']);if(_0x2de965['name']){delete _0x2de965[_0x3fc7('0x28')];}_0x31cc0b[_0x3fc7('0x1c')](_0x1e9930)[_0x3fc7('0x29')](_0x2de965);};}exports[_0x3fc7('0x2a')]=function(_0x231450,_0x292f4d){var _0x18abd4={},_0x3e2497={},_0x4f34fe={'count':0x0,'rows':[]};var _0x388be5=_['map'](db[_0x3fc7('0x2b')]['rawAttributes'],function(_0x1f7302){return{'name':_0x1f7302[_0x3fc7('0x2c')],'type':_0x1f7302['type']['key']};});_0x3e2497[_0x3fc7('0x2d')]=_['map'](_0x388be5,_0x3fc7('0x28'));_0x3e2497[_0x3fc7('0x2e')]=_[_0x3fc7('0x2f')](_0x231450['query']);_0x3e2497[_0x3fc7('0x30')]=_[_0x3fc7('0x31')](_0x3e2497['model'],_0x3e2497[_0x3fc7('0x2e')]);_0x18abd4[_0x3fc7('0x32')]=_[_0x3fc7('0x31')](_0x3e2497[_0x3fc7('0x2d')],qs[_0x3fc7('0x33')](_0x231450['query'][_0x3fc7('0x33')]));_0x18abd4[_0x3fc7('0x32')]=_0x18abd4['attributes']['length']?_0x18abd4[_0x3fc7('0x32')]:_0x3e2497[_0x3fc7('0x2d')];if(!_0x231450[_0x3fc7('0x2e')][_0x3fc7('0x34')](_0x3fc7('0x35'))){_0x18abd4['limit']=qs[_0x3fc7('0x36')](_0x231450['query'][_0x3fc7('0x36')]);_0x18abd4[_0x3fc7('0x1e')]=qs[_0x3fc7('0x1e')](_0x231450['query'][_0x3fc7('0x1e')]);}_0x18abd4[_0x3fc7('0x37')]=qs['sort'](_0x231450[_0x3fc7('0x2e')][_0x3fc7('0x38')]);_0x18abd4[_0x3fc7('0x39')]=qs[_0x3fc7('0x30')](_[_0x3fc7('0x3a')](_0x231450[_0x3fc7('0x2e')],_0x3e2497['filters']),_0x388be5);if(_0x231450[_0x3fc7('0x2e')][_0x3fc7('0x3b')]){_0x18abd4[_0x3fc7('0x39')]=_['merge'](_0x18abd4['where'],{'$or':_[_0x3fc7('0x3c')](_0x388be5,function(_0x49157c){if(_0x49157c[_0x3fc7('0x3d')]!==_0x3fc7('0x3e')){var _0x2f62f6={};_0x2f62f6[_0x49157c[_0x3fc7('0x28')]]={'$like':'%'+_0x231450[_0x3fc7('0x2e')][_0x3fc7('0x3b')]+'%'};return _0x2f62f6;}})});}_0x18abd4=_[_0x3fc7('0x3f')]({},_0x18abd4,_0x231450[_0x3fc7('0x40')]);var _0x4688a6={'where':_0x18abd4[_0x3fc7('0x39')]};return db['ZendeskField'][_0x3fc7('0x41')](_0x4688a6)['then'](function(_0x43b165){_0x4f34fe[_0x3fc7('0x41')]=_0x43b165;if(_0x231450[_0x3fc7('0x2e')]['includeAll']){_0x18abd4[_0x3fc7('0x42')]=[{'all':!![]}];}return db[_0x3fc7('0x2b')][_0x3fc7('0x43')](_0x18abd4);})[_0x3fc7('0x26')](function(_0x3fee5d){_0x4f34fe[_0x3fc7('0x44')]=_0x3fee5d;return _0x4f34fe;})[_0x3fc7('0x26')](respondWithFilteredResult(_0x292f4d,_0x18abd4))['catch'](handleError(_0x292f4d,null));};exports[_0x3fc7('0x45')]=function(_0x14d4e7,_0x3ff3d5){var _0x250174={'raw':!![],'where':{'id':_0x14d4e7[_0x3fc7('0x46')]['id']}},_0x333300={};_0x333300['model']=_[_0x3fc7('0x2f')](db[_0x3fc7('0x2b')][_0x3fc7('0x47')]);_0x333300['query']=_[_0x3fc7('0x2f')](_0x14d4e7[_0x3fc7('0x2e')]);_0x333300[_0x3fc7('0x30')]=_[_0x3fc7('0x31')](_0x333300[_0x3fc7('0x2d')],_0x333300[_0x3fc7('0x2e')]);_0x250174[_0x3fc7('0x32')]=_[_0x3fc7('0x31')](_0x333300[_0x3fc7('0x2d')],qs[_0x3fc7('0x33')](_0x14d4e7[_0x3fc7('0x2e')][_0x3fc7('0x33')]));_0x250174[_0x3fc7('0x32')]=_0x250174[_0x3fc7('0x32')][_0x3fc7('0x48')]?_0x250174['attributes']:_0x333300[_0x3fc7('0x2d')];if(_0x14d4e7[_0x3fc7('0x2e')][_0x3fc7('0x49')]){_0x250174[_0x3fc7('0x42')]=[{'all':!![]}];}_0x250174=_[_0x3fc7('0x3f')]({},_0x250174,_0x14d4e7[_0x3fc7('0x40')]);return db[_0x3fc7('0x2b')][_0x3fc7('0x4a')](_0x250174)[_0x3fc7('0x26')](handleEntityNotFound(_0x3ff3d5,null))[_0x3fc7('0x26')](respondWithResult(_0x3ff3d5,null))[_0x3fc7('0x4b')](handleError(_0x3ff3d5,null));};exports['create']=function(_0x496fbb,_0x178401){return db[_0x3fc7('0x2b')][_0x3fc7('0x4c')](_0x496fbb[_0x3fc7('0x4d')],{})[_0x3fc7('0x26')](respondWithResult(_0x178401,0xc9))[_0x3fc7('0x4b')](handleError(_0x178401,null));};exports['update']=function(_0x2b3c5c,_0x574f58){if(_0x2b3c5c[_0x3fc7('0x4d')]['id']){delete _0x2b3c5c[_0x3fc7('0x4d')]['id'];}return db[_0x3fc7('0x2b')][_0x3fc7('0x4a')]({'where':{'id':_0x2b3c5c[_0x3fc7('0x46')]['id']}})['then'](handleEntityNotFound(_0x574f58,null))[_0x3fc7('0x26')](saveUpdates(_0x2b3c5c['body'],null))[_0x3fc7('0x26')](respondWithResult(_0x574f58,null))['catch'](handleError(_0x574f58,null));};exports['destroy']=function(_0x4d4017,_0x2efa91){return db[_0x3fc7('0x2b')][_0x3fc7('0x4a')]({'where':{'id':_0x4d4017[_0x3fc7('0x46')]['id']}})[_0x3fc7('0x26')](handleEntityNotFound(_0x2efa91,null))[_0x3fc7('0x26')](removeEntity(_0x2efa91,null))[_0x3fc7('0x4b')](handleError(_0x2efa91,null));};