Built motion from commit 775e2a94.|2.6.3
[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 _0x8dbd=['status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','then','error','stack','name','index','map','DeskField','rawAttributes','type','model','keys','query','filters','intersection','fields','attributes','hasOwnProperty','order','where','pick','filter','merge','options','includeAll','findAll','rows','catch','include','find','create','body','params','destroy','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus'];(function(_0x3c962c,_0x59b73a){var _0x5e1ccb=function(_0x3eaa21){while(--_0x3eaa21){_0x3c962c['push'](_0x3c962c['shift']());}};_0x5e1ccb(++_0x59b73a);}(_0x8dbd,0x159));var _0xd8db=function(_0x47678c,_0x4af096){_0x47678c=_0x47678c-0x0;var _0xee9b9a=_0x8dbd[_0x47678c];return _0xee9b9a;};'use strict';var emlformat=require(_0xd8db('0x0'));var rimraf=require(_0xd8db('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xd8db('0x2'));var rp=require(_0xd8db('0x3'));var moment=require(_0xd8db('0x4'));var BPromise=require(_0xd8db('0x5'));var Mustache=require(_0xd8db('0x6'));var util=require(_0xd8db('0x7'));var path=require(_0xd8db('0x8'));var sox=require(_0xd8db('0x9'));var csv=require(_0xd8db('0xa'));var ejs=require(_0xd8db('0xb'));var fs=require('fs');var fs_extra=require(_0xd8db('0xc'));var _=require(_0xd8db('0xd'));var squel=require(_0xd8db('0xe'));var crypto=require(_0xd8db('0xf'));var jsforce=require(_0xd8db('0x10'));var deskjs=require(_0xd8db('0x11'));var toCsv=require(_0xd8db('0xa'));var querystring=require('querystring');var Papa=require(_0xd8db('0x12'));var Redis=require(_0xd8db('0x13'));var authService=require(_0xd8db('0x14'));var qs=require(_0xd8db('0x15'));var as=require(_0xd8db('0x16'));var hardwareService=require(_0xd8db('0x17'));var logger=require(_0xd8db('0x18'))(_0xd8db('0x19'));var utils=require(_0xd8db('0x1a'));var config=require(_0xd8db('0x1b'));var licenseUtil=require('../../config/license/util');var db=require(_0xd8db('0x1c'))['db'];function respondWithStatusCode(_0x23b404,_0x300fbd){_0x300fbd=_0x300fbd||0xcc;return function(_0xbfeb55){if(_0xbfeb55){return _0x23b404[_0xd8db('0x1d')](_0x300fbd);}return _0x23b404[_0xd8db('0x1e')](_0x300fbd)[_0xd8db('0x1f')]();};}function respondWithResult(_0x1eaa93,_0x491503){_0x491503=_0x491503||0xc8;return function(_0x5c0512){if(_0x5c0512){return _0x1eaa93[_0xd8db('0x1e')](_0x491503)[_0xd8db('0x20')](_0x5c0512);}};}function respondWithFilteredResult(_0x4c10a6,_0x221681){return function(_0x2eeed7){if(_0x2eeed7){var _0x54ad20=typeof _0x221681[_0xd8db('0x21')]===_0xd8db('0x22')&&typeof _0x221681[_0xd8db('0x23')]===_0xd8db('0x22');var _0x29d0b8=_0x2eeed7[_0xd8db('0x24')];var _0x2d0a0c=_0x54ad20?0x0:_0x221681[_0xd8db('0x21')];var _0x29026e=_0x54ad20?_0x2eeed7[_0xd8db('0x24')]:_0x221681[_0xd8db('0x21')]+_0x221681['limit'];var _0x4b5c1e;if(_0x29026e>=_0x29d0b8){_0x29026e=_0x29d0b8;_0x4b5c1e=0xc8;}else{_0x4b5c1e=0xce;}_0x4c10a6[_0xd8db('0x1e')](_0x4b5c1e);return _0x4c10a6[_0xd8db('0x25')](_0xd8db('0x26'),_0x2d0a0c+'-'+_0x29026e+'/'+_0x29d0b8)[_0xd8db('0x20')](_0x2eeed7);}return null;};}function patchUpdates(_0x2207bd){return function(_0xe8a2f){try{jsonpatch[_0xd8db('0x27')](_0xe8a2f,_0x2207bd,!![]);}catch(_0x44041c){return BPromise[_0xd8db('0x28')](_0x44041c);}return _0xe8a2f[_0xd8db('0x29')]();};}function saveUpdates(_0xf901a5,_0x1b32d9){return function(_0x11db7a){if(_0x11db7a){return _0x11db7a['update'](_0xf901a5)[_0xd8db('0x2a')](function(_0xd540b){return _0xd540b;});}return null;};}function removeEntity(_0x312024,_0x107292){return function(_0x2524ea){if(_0x2524ea){return _0x2524ea['destroy']()['then'](function(){_0x312024[_0xd8db('0x1e')](0xcc)[_0xd8db('0x1f')]();});}};}function handleEntityNotFound(_0x269f42,_0x65940e){return function(_0x6fae60){if(!_0x6fae60){_0x269f42[_0xd8db('0x1d')](0x194);}return _0x6fae60;};}function handleError(_0x595257,_0x1bbefe){_0x1bbefe=_0x1bbefe||0x1f4;return function(_0x5bbb91){logger[_0xd8db('0x2b')](_0x5bbb91[_0xd8db('0x2c')]);if(_0x5bbb91[_0xd8db('0x2d')]){delete _0x5bbb91['name'];}_0x595257[_0xd8db('0x1e')](_0x1bbefe)['send'](_0x5bbb91);};}exports[_0xd8db('0x2e')]=function(_0x3249f3,_0x90e6b6){var _0x45bfbe={},_0x1f0e11={},_0x4a866f={'count':0x0,'rows':[]};var _0x23020b=_[_0xd8db('0x2f')](db[_0xd8db('0x30')][_0xd8db('0x31')],function(_0x4f0024){return{'name':_0x4f0024['fieldName'],'type':_0x4f0024[_0xd8db('0x32')]['key']};});_0x1f0e11[_0xd8db('0x33')]=_[_0xd8db('0x2f')](_0x23020b,'name');_0x1f0e11['query']=_[_0xd8db('0x34')](_0x3249f3[_0xd8db('0x35')]);_0x1f0e11[_0xd8db('0x36')]=_['intersection'](_0x1f0e11[_0xd8db('0x33')],_0x1f0e11[_0xd8db('0x35')]);_0x45bfbe['attributes']=_[_0xd8db('0x37')](_0x1f0e11[_0xd8db('0x33')],qs[_0xd8db('0x38')](_0x3249f3[_0xd8db('0x35')][_0xd8db('0x38')]));_0x45bfbe[_0xd8db('0x39')]=_0x45bfbe[_0xd8db('0x39')]['length']?_0x45bfbe[_0xd8db('0x39')]:_0x1f0e11[_0xd8db('0x33')];if(!_0x3249f3['query'][_0xd8db('0x3a')]('nolimit')){_0x45bfbe[_0xd8db('0x23')]=qs['limit'](_0x3249f3[_0xd8db('0x35')][_0xd8db('0x23')]);_0x45bfbe[_0xd8db('0x21')]=qs[_0xd8db('0x21')](_0x3249f3[_0xd8db('0x35')][_0xd8db('0x21')]);}_0x45bfbe[_0xd8db('0x3b')]=qs['sort'](_0x3249f3['query']['sort']);_0x45bfbe[_0xd8db('0x3c')]=qs[_0xd8db('0x36')](_[_0xd8db('0x3d')](_0x3249f3['query'],_0x1f0e11['filters']),_0x23020b);if(_0x3249f3[_0xd8db('0x35')][_0xd8db('0x3e')]){_0x45bfbe[_0xd8db('0x3c')]=_[_0xd8db('0x3f')](_0x45bfbe[_0xd8db('0x3c')],{'$or':_[_0xd8db('0x2f')](_0x23020b,function(_0x2db4e7){if(_0x2db4e7[_0xd8db('0x32')]!=='VIRTUAL'){var _0x265010={};_0x265010[_0x2db4e7[_0xd8db('0x2d')]]={'$like':'%'+_0x3249f3[_0xd8db('0x35')][_0xd8db('0x3e')]+'%'};return _0x265010;}})});}_0x45bfbe=_[_0xd8db('0x3f')]({},_0x45bfbe,_0x3249f3[_0xd8db('0x40')]);var _0x51f06c={'where':_0x45bfbe['where']};return db[_0xd8db('0x30')][_0xd8db('0x24')](_0x51f06c)[_0xd8db('0x2a')](function(_0x52ef63){_0x4a866f[_0xd8db('0x24')]=_0x52ef63;if(_0x3249f3[_0xd8db('0x35')][_0xd8db('0x41')]){_0x45bfbe['include']=[{'all':!![]}];}return db[_0xd8db('0x30')][_0xd8db('0x42')](_0x45bfbe);})[_0xd8db('0x2a')](function(_0x2f7a0c){_0x4a866f[_0xd8db('0x43')]=_0x2f7a0c;return _0x4a866f;})['then'](respondWithFilteredResult(_0x90e6b6,_0x45bfbe))[_0xd8db('0x44')](handleError(_0x90e6b6,null));};exports['show']=function(_0x3e9565,_0x48e63d){var _0x5d69b8={'raw':!![],'where':{'id':_0x3e9565['params']['id']}},_0x1e7dd8={};_0x1e7dd8[_0xd8db('0x33')]=_[_0xd8db('0x34')](db[_0xd8db('0x30')][_0xd8db('0x31')]);_0x1e7dd8['query']=_[_0xd8db('0x34')](_0x3e9565[_0xd8db('0x35')]);_0x1e7dd8[_0xd8db('0x36')]=_[_0xd8db('0x37')](_0x1e7dd8[_0xd8db('0x33')],_0x1e7dd8[_0xd8db('0x35')]);_0x5d69b8[_0xd8db('0x39')]=_['intersection'](_0x1e7dd8[_0xd8db('0x33')],qs[_0xd8db('0x38')](_0x3e9565['query'][_0xd8db('0x38')]));_0x5d69b8[_0xd8db('0x39')]=_0x5d69b8[_0xd8db('0x39')]['length']?_0x5d69b8[_0xd8db('0x39')]:_0x1e7dd8['model'];if(_0x3e9565[_0xd8db('0x35')][_0xd8db('0x41')]){_0x5d69b8[_0xd8db('0x45')]=[{'all':!![]}];}_0x5d69b8=_[_0xd8db('0x3f')]({},_0x5d69b8,_0x3e9565['options']);return db[_0xd8db('0x30')][_0xd8db('0x46')](_0x5d69b8)[_0xd8db('0x2a')](handleEntityNotFound(_0x48e63d,null))[_0xd8db('0x2a')](respondWithResult(_0x48e63d,null))['catch'](handleError(_0x48e63d,null));};exports[_0xd8db('0x47')]=function(_0x10f700,_0x3be9c3){return db['DeskField']['create'](_0x10f700[_0xd8db('0x48')],{})[_0xd8db('0x2a')](respondWithResult(_0x3be9c3,0xc9))[_0xd8db('0x44')](handleError(_0x3be9c3,null));};exports['update']=function(_0x215907,_0x57cd75){if(_0x215907['body']['id']){delete _0x215907[_0xd8db('0x48')]['id'];}return db['DeskField'][_0xd8db('0x46')]({'where':{'id':_0x215907[_0xd8db('0x49')]['id']}})[_0xd8db('0x2a')](handleEntityNotFound(_0x57cd75,null))[_0xd8db('0x2a')](saveUpdates(_0x215907[_0xd8db('0x48')],null))[_0xd8db('0x2a')](respondWithResult(_0x57cd75,null))[_0xd8db('0x44')](handleError(_0x57cd75,null));};exports[_0xd8db('0x4a')]=function(_0x206f34,_0x14bef4){return db[_0xd8db('0x30')][_0xd8db('0x46')]({'where':{'id':_0x206f34[_0xd8db('0x49')]['id']}})[_0xd8db('0x2a')](handleEntityNotFound(_0x14bef4,null))[_0xd8db('0x2a')](removeEntity(_0x14bef4,null))['catch'](handleError(_0x14bef4,null));};