Built motion from commit (unavailable).|2.5.11
[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 _0x127f=['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','json','count','offset','limit','set','Content-Range','apply','reject','save','destroy','error','stack','name','index','map','DeskField','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','then','includeAll','include','findAll','rows','catch','show','find','create','body','update','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','sox','to-csv','lodash','squel','desk.js'];(function(_0x164eca,_0x555e28){var _0x2ce562=function(_0x148ca6){while(--_0x148ca6){_0x164eca['push'](_0x164eca['shift']());}};_0x2ce562(++_0x555e28);}(_0x127f,0xd7));var _0xf127=function(_0x4e64b7,_0x12f8fa){_0x4e64b7=_0x4e64b7-0x0;var _0x3e9500=_0x127f[_0x4e64b7];return _0x3e9500;};'use strict';var pdf=require(_0xf127('0x0'));var emlformat=require(_0xf127('0x1'));var rimraf=require(_0xf127('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf127('0x3'));var moment=require(_0xf127('0x4'));var BPromise=require(_0xf127('0x5'));var Mustache=require(_0xf127('0x6'));var util=require(_0xf127('0x7'));var path=require('path');var sox=require(_0xf127('0x8'));var csv=require(_0xf127('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xf127('0xa'));var squel=require(_0xf127('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xf127('0xc'));var toCsv=require('to-csv');var querystring=require(_0xf127('0xd'));var Papa=require(_0xf127('0xe'));var Redis=require(_0xf127('0xf'));var authService=require(_0xf127('0x10'));var qs=require(_0xf127('0x11'));var as=require(_0xf127('0x12'));var hardwareService=require(_0xf127('0x13'));var logger=require(_0xf127('0x14'))(_0xf127('0x15'));var utils=require(_0xf127('0x16'));var config=require(_0xf127('0x17'));var licenseUtil=require(_0xf127('0x18'));var db=require(_0xf127('0x19'))['db'];function respondWithStatusCode(_0x18d948,_0x2944d8){_0x2944d8=_0x2944d8||0xcc;return function(_0x3c4829){if(_0x3c4829){return _0x18d948[_0xf127('0x1a')](_0x2944d8);}return _0x18d948[_0xf127('0x1b')](_0x2944d8)[_0xf127('0x1c')]();};}function respondWithResult(_0x311419,_0x3c2ae3){_0x3c2ae3=_0x3c2ae3||0xc8;return function(_0xce36d3){if(_0xce36d3){return _0x311419[_0xf127('0x1b')](_0x3c2ae3)[_0xf127('0x1d')](_0xce36d3);}};}function respondWithFilteredResult(_0x3622d3,_0x38517a){return function(_0x51d154){if(_0x51d154){var _0x5ee098=_0x51d154[_0xf127('0x1e')],_0x1e5272=_0x38517a[_0xf127('0x1f')],_0x29c968=_0x38517a[_0xf127('0x1f')]+_0x38517a[_0xf127('0x20')],_0xfb2a22;if(_0x29c968>=_0x5ee098){_0x29c968=_0x5ee098;_0xfb2a22=0xc8;}else{_0xfb2a22=0xce;}_0x3622d3[_0xf127('0x1b')](_0xfb2a22);return _0x3622d3[_0xf127('0x21')](_0xf127('0x22'),_0x1e5272+'-'+_0x29c968+'/'+_0x5ee098)['json'](_0x51d154);}return null;};}function patchUpdates(_0x4961c0){return function(_0x1ffa22){try{jsonpatch[_0xf127('0x23')](_0x1ffa22,_0x4961c0,!![]);}catch(_0x5666fd){return BPromise[_0xf127('0x24')](_0x5666fd);}return _0x1ffa22[_0xf127('0x25')]();};}function saveUpdates(_0x45ec07,_0x1ffee0){return function(_0x3cdb46){if(_0x3cdb46){return _0x3cdb46['update'](_0x45ec07)['then'](function(_0x306405){return _0x306405;});}return null;};}function removeEntity(_0x3dd5cb,_0x3ee059){return function(_0x5ecf7e){if(_0x5ecf7e){return _0x5ecf7e[_0xf127('0x26')]()['then'](function(){_0x3dd5cb[_0xf127('0x1b')](0xcc)[_0xf127('0x1c')]();});}};}function handleEntityNotFound(_0x345d82,_0x5d1f8d){return function(_0x5ea553){if(!_0x5ea553){_0x345d82[_0xf127('0x1a')](0x194);}return _0x5ea553;};}function handleError(_0x34c7dd,_0x3dddfa){_0x3dddfa=_0x3dddfa||0x1f4;return function(_0x2b1437){logger[_0xf127('0x27')](_0x2b1437[_0xf127('0x28')]);if(_0x2b1437[_0xf127('0x29')]){delete _0x2b1437['name'];}_0x34c7dd[_0xf127('0x1b')](_0x3dddfa)['send'](_0x2b1437);};}exports[_0xf127('0x2a')]=function(_0x3f70d5,_0x1b1b24){var _0x56c100={},_0x41668c={},_0x380540={'count':0x0,'rows':[]};var _0xb488a=_[_0xf127('0x2b')](db[_0xf127('0x2c')][_0xf127('0x2d')],function(_0x3c2967){return{'name':_0x3c2967[_0xf127('0x2e')],'type':_0x3c2967[_0xf127('0x2f')][_0xf127('0x30')]};});_0x41668c[_0xf127('0x31')]=_[_0xf127('0x2b')](_0xb488a,'name');_0x41668c[_0xf127('0x32')]=_[_0xf127('0x33')](_0x3f70d5['query']);_0x41668c[_0xf127('0x34')]=_[_0xf127('0x35')](_0x41668c[_0xf127('0x31')],_0x41668c[_0xf127('0x32')]);_0x56c100[_0xf127('0x36')]=_['intersection'](_0x41668c['model'],qs[_0xf127('0x37')](_0x3f70d5['query'][_0xf127('0x37')]));_0x56c100[_0xf127('0x36')]=_0x56c100[_0xf127('0x36')][_0xf127('0x38')]?_0x56c100['attributes']:_0x41668c[_0xf127('0x31')];if(!_0x3f70d5[_0xf127('0x32')][_0xf127('0x39')](_0xf127('0x3a'))){_0x56c100[_0xf127('0x20')]=qs['limit'](_0x3f70d5[_0xf127('0x32')]['limit']);_0x56c100['offset']=qs[_0xf127('0x1f')](_0x3f70d5[_0xf127('0x32')]['offset']);}_0x56c100['order']=qs['sort'](_0x3f70d5[_0xf127('0x32')][_0xf127('0x3b')]);_0x56c100[_0xf127('0x3c')]=qs[_0xf127('0x34')](_['pick'](_0x3f70d5[_0xf127('0x32')],_0x41668c[_0xf127('0x34')]),_0xb488a);if(_0x3f70d5[_0xf127('0x32')][_0xf127('0x3d')]){_0x56c100[_0xf127('0x3c')]=_[_0xf127('0x3e')](_0x56c100[_0xf127('0x3c')],{'$or':_[_0xf127('0x2b')](_0xb488a,function(_0x56cecc){if(_0x56cecc[_0xf127('0x2f')]!==_0xf127('0x3f')){var _0x5d5fc0={};_0x5d5fc0[_0x56cecc['name']]={'$like':'%'+_0x3f70d5[_0xf127('0x32')]['filter']+'%'};return _0x5d5fc0;}})});}_0x56c100=_['merge']({},_0x56c100,_0x3f70d5[_0xf127('0x40')]);var _0x1ed17a={'where':_0x56c100['where']};return db[_0xf127('0x2c')][_0xf127('0x1e')](_0x1ed17a)[_0xf127('0x41')](function(_0x96628c){_0x380540[_0xf127('0x1e')]=_0x96628c;if(_0x3f70d5['query'][_0xf127('0x42')]){_0x56c100[_0xf127('0x43')]=[{'all':!![]}];}return db[_0xf127('0x2c')][_0xf127('0x44')](_0x56c100);})['then'](function(_0x5e5386){_0x380540[_0xf127('0x45')]=_0x5e5386;return _0x380540;})['then'](respondWithFilteredResult(_0x1b1b24,_0x56c100))[_0xf127('0x46')](handleError(_0x1b1b24,null));};exports[_0xf127('0x47')]=function(_0xe8195a,_0xf08190){var _0x26c7fe={'raw':!![],'where':{'id':_0xe8195a['params']['id']}},_0x35bc21={};_0x35bc21[_0xf127('0x31')]=_[_0xf127('0x33')](db[_0xf127('0x2c')][_0xf127('0x2d')]);_0x35bc21['query']=_[_0xf127('0x33')](_0xe8195a[_0xf127('0x32')]);_0x35bc21['filters']=_['intersection'](_0x35bc21[_0xf127('0x31')],_0x35bc21[_0xf127('0x32')]);_0x26c7fe[_0xf127('0x36')]=_[_0xf127('0x35')](_0x35bc21['model'],qs[_0xf127('0x37')](_0xe8195a[_0xf127('0x32')][_0xf127('0x37')]));_0x26c7fe[_0xf127('0x36')]=_0x26c7fe[_0xf127('0x36')][_0xf127('0x38')]?_0x26c7fe['attributes']:_0x35bc21[_0xf127('0x31')];if(_0xe8195a[_0xf127('0x32')]['includeAll']){_0x26c7fe[_0xf127('0x43')]=[{'all':!![]}];}_0x26c7fe=_[_0xf127('0x3e')]({},_0x26c7fe,_0xe8195a[_0xf127('0x40')]);return db[_0xf127('0x2c')][_0xf127('0x48')](_0x26c7fe)['then'](handleEntityNotFound(_0xf08190,null))[_0xf127('0x41')](respondWithResult(_0xf08190,null))[_0xf127('0x46')](handleError(_0xf08190,null));};exports[_0xf127('0x49')]=function(_0x1f8901,_0xc08a09){return db[_0xf127('0x2c')][_0xf127('0x49')](_0x1f8901[_0xf127('0x4a')],{})[_0xf127('0x41')](respondWithResult(_0xc08a09,0xc9))[_0xf127('0x46')](handleError(_0xc08a09,null));};exports[_0xf127('0x4b')]=function(_0xecabac,_0x35acba){if(_0xecabac[_0xf127('0x4a')]['id']){delete _0xecabac[_0xf127('0x4a')]['id'];}return db[_0xf127('0x2c')][_0xf127('0x48')]({'where':{'id':_0xecabac['params']['id']}})[_0xf127('0x41')](handleEntityNotFound(_0x35acba,null))[_0xf127('0x41')](saveUpdates(_0xecabac[_0xf127('0x4a')],null))['then'](respondWithResult(_0x35acba,null))[_0xf127('0x46')](handleError(_0x35acba,null));};exports[_0xf127('0x26')]=function(_0x3c168d,_0xc2739c){return db[_0xf127('0x2c')]['find']({'where':{'id':_0x3c168d['params']['id']}})[_0xf127('0x41')](handleEntityNotFound(_0xc2739c,null))[_0xf127('0x41')](removeEntity(_0xc2739c,null))['catch'](handleError(_0xc2739c,null));};