Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / intDeskField / intDeskField.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 _0xf51f=['offset','count','set','apply','save','update','then','error','stack','send','index','map','rawAttributes','fieldName','key','model','name','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','type','filter','DeskField','includeAll','findAll','rows','catch','show','include','options','find','create','body','params','destroy','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','limit'];(function(_0x238303,_0x4105e9){var _0x5cc3b5=function(_0x452021){while(--_0x452021){_0x238303['push'](_0x238303['shift']());}};_0x5cc3b5(++_0x4105e9);}(_0xf51f,0x19f));var _0xff51=function(_0x1602ef,_0x447aba){_0x1602ef=_0x1602ef-0x0;var _0x5870ee=_0xf51f[_0x1602ef];return _0x5870ee;};'use strict';var emlformat=require(_0xff51('0x0'));var rimraf=require(_0xff51('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xff51('0x2'));var rp=require(_0xff51('0x3'));var moment=require('moment');var BPromise=require(_0xff51('0x4'));var Mustache=require(_0xff51('0x5'));var util=require(_0xff51('0x6'));var path=require(_0xff51('0x7'));var sox=require(_0xff51('0x8'));var csv=require(_0xff51('0x9'));var ejs=require(_0xff51('0xa'));var fs=require('fs');var fs_extra=require(_0xff51('0xb'));var _=require(_0xff51('0xc'));var squel=require(_0xff51('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xff51('0xe'));var toCsv=require(_0xff51('0x9'));var querystring=require(_0xff51('0xf'));var Papa=require('papaparse');var Redis=require(_0xff51('0x10'));var authService=require(_0xff51('0x11'));var qs=require(_0xff51('0x12'));var as=require(_0xff51('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xff51('0x14'))('api');var utils=require(_0xff51('0x15'));var config=require(_0xff51('0x16'));var licenseUtil=require(_0xff51('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x391dc8,_0x40ecb9){_0x40ecb9=_0x40ecb9||0xcc;return function(_0x474fc4){if(_0x474fc4){return _0x391dc8[_0xff51('0x18')](_0x40ecb9);}return _0x391dc8[_0xff51('0x19')](_0x40ecb9)[_0xff51('0x1a')]();};}function respondWithResult(_0x50752e,_0x417f62){_0x417f62=_0x417f62||0xc8;return function(_0xf899eb){if(_0xf899eb){return _0x50752e[_0xff51('0x19')](_0x417f62)[_0xff51('0x1b')](_0xf899eb);}};}function respondWithFilteredResult(_0x21fe6d,_0x4404e0){return function(_0x5edc43){if(_0x5edc43){var _0x6606c2=typeof _0x4404e0['offset']==='undefined'&&typeof _0x4404e0[_0xff51('0x1c')]==='undefined';var _0x554acc=_0x5edc43['count'];var _0x22bcdc=_0x6606c2?0x0:_0x4404e0[_0xff51('0x1d')];var _0x22eacd=_0x6606c2?_0x5edc43[_0xff51('0x1e')]:_0x4404e0[_0xff51('0x1d')]+_0x4404e0[_0xff51('0x1c')];var _0x1cd4f9;if(_0x22eacd>=_0x554acc){_0x22eacd=_0x554acc;_0x1cd4f9=0xc8;}else{_0x1cd4f9=0xce;}_0x21fe6d['status'](_0x1cd4f9);return _0x21fe6d[_0xff51('0x1f')]('Content-Range',_0x22bcdc+'-'+_0x22eacd+'/'+_0x554acc)['json'](_0x5edc43);}return null;};}function patchUpdates(_0x4f2895){return function(_0x3f4999){try{jsonpatch[_0xff51('0x20')](_0x3f4999,_0x4f2895,!![]);}catch(_0xa47564){return BPromise['reject'](_0xa47564);}return _0x3f4999[_0xff51('0x21')]();};}function saveUpdates(_0x5c9515,_0x4b6bf0){return function(_0x46155f){if(_0x46155f){return _0x46155f[_0xff51('0x22')](_0x5c9515)[_0xff51('0x23')](function(_0x21fee8){return _0x21fee8;});}return null;};}function removeEntity(_0x1c4224,_0x9e2f6f){return function(_0x563301){if(_0x563301){return _0x563301['destroy']()[_0xff51('0x23')](function(){_0x1c4224[_0xff51('0x19')](0xcc)[_0xff51('0x1a')]();});}};}function handleEntityNotFound(_0x52a340,_0x58840c){return function(_0x54bb66){if(!_0x54bb66){_0x52a340[_0xff51('0x18')](0x194);}return _0x54bb66;};}function handleError(_0x3af926,_0x587d76){_0x587d76=_0x587d76||0x1f4;return function(_0x2c61bd){logger[_0xff51('0x24')](_0x2c61bd[_0xff51('0x25')]);if(_0x2c61bd['name']){delete _0x2c61bd['name'];}_0x3af926[_0xff51('0x19')](_0x587d76)[_0xff51('0x26')](_0x2c61bd);};}exports[_0xff51('0x27')]=function(_0x2e1fcb,_0x7591ae){var _0x3f6c8e={},_0xb928c5={},_0x472448={'count':0x0,'rows':[]};var _0x38e793=_[_0xff51('0x28')](db['DeskField'][_0xff51('0x29')],function(_0x2f459b){return{'name':_0x2f459b[_0xff51('0x2a')],'type':_0x2f459b['type'][_0xff51('0x2b')]};});_0xb928c5[_0xff51('0x2c')]=_[_0xff51('0x28')](_0x38e793,_0xff51('0x2d'));_0xb928c5[_0xff51('0x2e')]=_[_0xff51('0x2f')](_0x2e1fcb['query']);_0xb928c5[_0xff51('0x30')]=_[_0xff51('0x31')](_0xb928c5[_0xff51('0x2c')],_0xb928c5[_0xff51('0x2e')]);_0x3f6c8e[_0xff51('0x32')]=_[_0xff51('0x31')](_0xb928c5[_0xff51('0x2c')],qs[_0xff51('0x33')](_0x2e1fcb[_0xff51('0x2e')]['fields']));_0x3f6c8e['attributes']=_0x3f6c8e['attributes'][_0xff51('0x34')]?_0x3f6c8e[_0xff51('0x32')]:_0xb928c5['model'];if(!_0x2e1fcb[_0xff51('0x2e')][_0xff51('0x35')](_0xff51('0x36'))){_0x3f6c8e[_0xff51('0x1c')]=qs[_0xff51('0x1c')](_0x2e1fcb['query'][_0xff51('0x1c')]);_0x3f6c8e[_0xff51('0x1d')]=qs[_0xff51('0x1d')](_0x2e1fcb[_0xff51('0x2e')][_0xff51('0x1d')]);}_0x3f6c8e[_0xff51('0x37')]=qs[_0xff51('0x38')](_0x2e1fcb[_0xff51('0x2e')][_0xff51('0x38')]);_0x3f6c8e[_0xff51('0x39')]=qs[_0xff51('0x30')](_['pick'](_0x2e1fcb[_0xff51('0x2e')],_0xb928c5[_0xff51('0x30')]),_0x38e793);if(_0x2e1fcb[_0xff51('0x2e')]['filter']){_0x3f6c8e['where']=_[_0xff51('0x3a')](_0x3f6c8e['where'],{'$or':_[_0xff51('0x28')](_0x38e793,function(_0x4d2e61){if(_0x4d2e61[_0xff51('0x3b')]!=='VIRTUAL'){var _0x571470={};_0x571470[_0x4d2e61[_0xff51('0x2d')]]={'$like':'%'+_0x2e1fcb['query'][_0xff51('0x3c')]+'%'};return _0x571470;}})});}_0x3f6c8e=_[_0xff51('0x3a')]({},_0x3f6c8e,_0x2e1fcb['options']);var _0x11dd87={'where':_0x3f6c8e[_0xff51('0x39')]};return db[_0xff51('0x3d')][_0xff51('0x1e')](_0x11dd87)[_0xff51('0x23')](function(_0x140cbe){_0x472448[_0xff51('0x1e')]=_0x140cbe;if(_0x2e1fcb['query'][_0xff51('0x3e')]){_0x3f6c8e['include']=[{'all':!![]}];}return db[_0xff51('0x3d')][_0xff51('0x3f')](_0x3f6c8e);})[_0xff51('0x23')](function(_0x1d6df3){_0x472448[_0xff51('0x40')]=_0x1d6df3;return _0x472448;})[_0xff51('0x23')](respondWithFilteredResult(_0x7591ae,_0x3f6c8e))[_0xff51('0x41')](handleError(_0x7591ae,null));};exports[_0xff51('0x42')]=function(_0x4971d3,_0x341e52){var _0x223b2e={'raw':!![],'where':{'id':_0x4971d3['params']['id']}},_0x2aec14={};_0x2aec14[_0xff51('0x2c')]=_[_0xff51('0x2f')](db[_0xff51('0x3d')][_0xff51('0x29')]);_0x2aec14[_0xff51('0x2e')]=_[_0xff51('0x2f')](_0x4971d3[_0xff51('0x2e')]);_0x2aec14[_0xff51('0x30')]=_['intersection'](_0x2aec14[_0xff51('0x2c')],_0x2aec14[_0xff51('0x2e')]);_0x223b2e[_0xff51('0x32')]=_[_0xff51('0x31')](_0x2aec14[_0xff51('0x2c')],qs[_0xff51('0x33')](_0x4971d3[_0xff51('0x2e')]['fields']));_0x223b2e[_0xff51('0x32')]=_0x223b2e[_0xff51('0x32')][_0xff51('0x34')]?_0x223b2e[_0xff51('0x32')]:_0x2aec14['model'];if(_0x4971d3['query']['includeAll']){_0x223b2e[_0xff51('0x43')]=[{'all':!![]}];}_0x223b2e=_[_0xff51('0x3a')]({},_0x223b2e,_0x4971d3[_0xff51('0x44')]);return db[_0xff51('0x3d')][_0xff51('0x45')](_0x223b2e)[_0xff51('0x23')](handleEntityNotFound(_0x341e52,null))[_0xff51('0x23')](respondWithResult(_0x341e52,null))['catch'](handleError(_0x341e52,null));};exports[_0xff51('0x46')]=function(_0x5d22ee,_0x2a665d){return db[_0xff51('0x3d')][_0xff51('0x46')](_0x5d22ee[_0xff51('0x47')],{})[_0xff51('0x23')](respondWithResult(_0x2a665d,0xc9))[_0xff51('0x41')](handleError(_0x2a665d,null));};exports[_0xff51('0x22')]=function(_0x19cc90,_0x274eb8){if(_0x19cc90[_0xff51('0x47')]['id']){delete _0x19cc90['body']['id'];}return db[_0xff51('0x3d')][_0xff51('0x45')]({'where':{'id':_0x19cc90[_0xff51('0x48')]['id']}})['then'](handleEntityNotFound(_0x274eb8,null))[_0xff51('0x23')](saveUpdates(_0x19cc90[_0xff51('0x47')],null))[_0xff51('0x23')](respondWithResult(_0x274eb8,null))[_0xff51('0x41')](handleError(_0x274eb8,null));};exports[_0xff51('0x49')]=function(_0x58377f,_0x354af3){return db[_0xff51('0x3d')][_0xff51('0x45')]({'where':{'id':_0x58377f['params']['id']}})[_0xff51('0x23')](handleEntityNotFound(_0x354af3,null))[_0xff51('0x23')](removeEntity(_0x354af3,null))[_0xff51('0x41')](handleError(_0x354af3,null));};