Built motion from commit a134ab58.|2.6.29
[motion2.git] / server / api / contactItemType / contactItemType.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 _0x28f2=['api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','Content-Range','apply','reject','save','update','then','destroy','get','ContactItemTypes','UserProfileResource','error','stack','name','send','index','map','rawAttributes','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','where','merge','ContactItemType','count','include','findAll','rows','catch','show','keys','includeAll','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','params','CmContactHasItem','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger'];(function(_0xfc2d2b,_0x3d6dd9){var _0x483807=function(_0x22a5a0){while(--_0x22a5a0){_0xfc2d2b['push'](_0xfc2d2b['shift']());}};_0x483807(++_0x3d6dd9);}(_0x28f2,0x193));var _0x228f=function(_0x1de01b,_0xacbbbe){_0x1de01b=_0x1de01b-0x0;var _0x4402c8=_0x28f2[_0x1de01b];return _0x4402c8;};'use strict';var emlformat=require(_0x228f('0x0'));var rimraf=require(_0x228f('0x1'));var zipdir=require(_0x228f('0x2'));var jsonpatch=require(_0x228f('0x3'));var rp=require(_0x228f('0x4'));var moment=require('moment');var BPromise=require(_0x228f('0x5'));var Mustache=require(_0x228f('0x6'));var util=require(_0x228f('0x7'));var path=require(_0x228f('0x8'));var sox=require(_0x228f('0x9'));var csv=require(_0x228f('0xa'));var ejs=require(_0x228f('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x228f('0xc'));var squel=require('squel');var crypto=require(_0x228f('0xd'));var jsforce=require(_0x228f('0xe'));var deskjs=require(_0x228f('0xf'));var toCsv=require('to-csv');var querystring=require(_0x228f('0x10'));var Papa=require('papaparse');var Redis=require(_0x228f('0x11'));var authService=require(_0x228f('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x228f('0x13'));var hardwareService=require(_0x228f('0x14'));var logger=require(_0x228f('0x15'))(_0x228f('0x16'));var utils=require(_0x228f('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x228f('0x18'));var db=require(_0x228f('0x19'))['db'];function respondWithStatusCode(_0x24f69c,_0x14073a){_0x14073a=_0x14073a||0xcc;return function(_0x2e1a43){if(_0x2e1a43){return _0x24f69c[_0x228f('0x1a')](_0x14073a);}return _0x24f69c[_0x228f('0x1b')](_0x14073a)[_0x228f('0x1c')]();};}function respondWithResult(_0x572535,_0x2fab95){_0x2fab95=_0x2fab95||0xc8;return function(_0xfb6aff){if(_0xfb6aff){return _0x572535[_0x228f('0x1b')](_0x2fab95)[_0x228f('0x1d')](_0xfb6aff);}};}function respondWithFilteredResult(_0x2a4d87,_0x21a913){return function(_0x272723){if(_0x272723){var _0x5b5abb=typeof _0x21a913[_0x228f('0x1e')]==='undefined'&&typeof _0x21a913[_0x228f('0x1f')]===_0x228f('0x20');var _0x195e65=_0x272723['count'];var _0x2d4819=_0x5b5abb?0x0:_0x21a913['offset'];var _0x33e32e=_0x5b5abb?_0x272723['count']:_0x21a913[_0x228f('0x1e')]+_0x21a913['limit'];var _0x5aa203;if(_0x33e32e>=_0x195e65){_0x33e32e=_0x195e65;_0x5aa203=0xc8;}else{_0x5aa203=0xce;}_0x2a4d87[_0x228f('0x1b')](_0x5aa203);return _0x2a4d87['set'](_0x228f('0x21'),_0x2d4819+'-'+_0x33e32e+'/'+_0x195e65)[_0x228f('0x1d')](_0x272723);}return null;};}function patchUpdates(_0x1294a8){return function(_0x3a623a){try{jsonpatch[_0x228f('0x22')](_0x3a623a,_0x1294a8,!![]);}catch(_0x313cf2){return BPromise[_0x228f('0x23')](_0x313cf2);}return _0x3a623a[_0x228f('0x24')]();};}function saveUpdates(_0x15d54f,_0x4ee0c9){return function(_0x1e96d4){if(_0x1e96d4){return _0x1e96d4[_0x228f('0x25')](_0x15d54f)[_0x228f('0x26')](function(_0x3c00ad){return _0x3c00ad;});}return null;};}function removeEntity(_0x1dad27,_0x194d1a){return function(_0x33e882){if(_0x33e882){return _0x33e882[_0x228f('0x27')]()[_0x228f('0x26')](function(){var _0x56fbc2=_0x33e882[_0x228f('0x28')]({'plain':!![]});var _0x306928=_0x228f('0x29');return db[_0x228f('0x2a')][_0x228f('0x27')]({'where':{'type':_0x306928,'resourceId':_0x56fbc2['id']}})['then'](function(){return _0x33e882;});})[_0x228f('0x26')](function(){_0x1dad27['status'](0xcc)[_0x228f('0x1c')]();});}};}function handleEntityNotFound(_0x5afa52,_0x58a151){return function(_0x2b9802){if(!_0x2b9802){_0x5afa52[_0x228f('0x1a')](0x194);}return _0x2b9802;};}function handleError(_0x2a7842,_0x3ab339){_0x3ab339=_0x3ab339||0x1f4;return function(_0x34c735){logger[_0x228f('0x2b')](_0x34c735[_0x228f('0x2c')]);if(_0x34c735[_0x228f('0x2d')]){delete _0x34c735[_0x228f('0x2d')];}_0x2a7842[_0x228f('0x1b')](_0x3ab339)[_0x228f('0x2e')](_0x34c735);};}exports[_0x228f('0x2f')]=function(_0xc25917,_0xc6921f){var _0x2a3677={},_0x4e9ca8={},_0x4148ff={'count':0x0,'rows':[]};var _0x40bf17=_[_0x228f('0x30')](db['ContactItemType'][_0x228f('0x31')],function(_0x41be2d){return{'name':_0x41be2d['fieldName'],'type':_0x41be2d[_0x228f('0x32')][_0x228f('0x33')]};});_0x4e9ca8[_0x228f('0x34')]=_[_0x228f('0x30')](_0x40bf17,'name');_0x4e9ca8[_0x228f('0x35')]=_['keys'](_0xc25917[_0x228f('0x35')]);_0x4e9ca8[_0x228f('0x36')]=_[_0x228f('0x37')](_0x4e9ca8[_0x228f('0x34')],_0x4e9ca8['query']);_0x2a3677[_0x228f('0x38')]=_[_0x228f('0x37')](_0x4e9ca8['model'],qs['fields'](_0xc25917['query'][_0x228f('0x39')]));_0x2a3677[_0x228f('0x38')]=_0x2a3677[_0x228f('0x38')][_0x228f('0x3a')]?_0x2a3677[_0x228f('0x38')]:_0x4e9ca8[_0x228f('0x34')];if(!_0xc25917[_0x228f('0x35')][_0x228f('0x3b')](_0x228f('0x3c'))){_0x2a3677['limit']=qs['limit'](_0xc25917[_0x228f('0x35')][_0x228f('0x1f')]);_0x2a3677[_0x228f('0x1e')]=qs[_0x228f('0x1e')](_0xc25917[_0x228f('0x35')][_0x228f('0x1e')]);}_0x2a3677[_0x228f('0x3d')]=qs[_0x228f('0x3e')](_0xc25917[_0x228f('0x35')][_0x228f('0x3e')]);_0x2a3677['where']=qs['filters'](_[_0x228f('0x3f')](_0xc25917[_0x228f('0x35')],_0x4e9ca8[_0x228f('0x36')]),_0x40bf17);if(_0xc25917[_0x228f('0x35')]['filter']){_0x2a3677[_0x228f('0x40')]=_[_0x228f('0x41')](_0x2a3677['where'],{'$or':_['map'](_0x40bf17,function(_0x3da115){if(_0x3da115[_0x228f('0x32')]!=='VIRTUAL'){var _0x12a750={};_0x12a750[_0x3da115[_0x228f('0x2d')]]={'$like':'%'+_0xc25917['query']['filter']+'%'};return _0x12a750;}})});}_0x2a3677=_[_0x228f('0x41')]({},_0x2a3677,_0xc25917['options']);var _0x323d68={'where':_0x2a3677[_0x228f('0x40')]};return db[_0x228f('0x42')][_0x228f('0x43')](_0x323d68)[_0x228f('0x26')](function(_0x20c178){_0x4148ff['count']=_0x20c178;if(_0xc25917[_0x228f('0x35')]['includeAll']){_0x2a3677[_0x228f('0x44')]=[{'all':!![]}];}return db[_0x228f('0x42')][_0x228f('0x45')](_0x2a3677);})[_0x228f('0x26')](function(_0x41cba5){_0x4148ff[_0x228f('0x46')]=_0x41cba5;return _0x4148ff;})[_0x228f('0x26')](respondWithFilteredResult(_0xc6921f,_0x2a3677))[_0x228f('0x47')](handleError(_0xc6921f,null));};exports[_0x228f('0x48')]=function(_0x2592a1,_0x788e8b){var _0x345114={'raw':!![],'where':{'id':_0x2592a1['params']['id']}},_0x19839d={};_0x19839d['model']=_[_0x228f('0x49')](db[_0x228f('0x42')][_0x228f('0x31')]);_0x19839d[_0x228f('0x35')]=_[_0x228f('0x49')](_0x2592a1[_0x228f('0x35')]);_0x19839d[_0x228f('0x36')]=_[_0x228f('0x37')](_0x19839d[_0x228f('0x34')],_0x19839d[_0x228f('0x35')]);_0x345114['attributes']=_[_0x228f('0x37')](_0x19839d[_0x228f('0x34')],qs['fields'](_0x2592a1[_0x228f('0x35')]['fields']));_0x345114[_0x228f('0x38')]=_0x345114['attributes'][_0x228f('0x3a')]?_0x345114['attributes']:_0x19839d[_0x228f('0x34')];if(_0x2592a1[_0x228f('0x35')][_0x228f('0x4a')]){_0x345114[_0x228f('0x44')]=[{'all':!![]}];}_0x345114=_[_0x228f('0x41')]({},_0x345114,_0x2592a1[_0x228f('0x4b')]);return db[_0x228f('0x42')][_0x228f('0x4c')](_0x345114)[_0x228f('0x26')](handleEntityNotFound(_0x788e8b,null))[_0x228f('0x26')](respondWithResult(_0x788e8b,null))[_0x228f('0x47')](handleError(_0x788e8b,null));};exports[_0x228f('0x4d')]=function(_0x4099d4,_0x250345){return db[_0x228f('0x42')][_0x228f('0x4d')](_0x4099d4[_0x228f('0x4e')],{})[_0x228f('0x26')](function(_0x1872e2){var _0x55e140=_0x4099d4['user'][_0x228f('0x28')]({'plain':!![]});if(!_0x55e140)throw new Error(_0x228f('0x4f'));if(_0x55e140[_0x228f('0x50')]==='user'){var _0x17bcd9=_0x1872e2[_0x228f('0x28')]({'plain':!![]});var _0x28f91e='ContactItemTypes';return db['UserProfileSection']['find']({'where':{'name':_0x28f91e,'userProfileId':_0x55e140[_0x228f('0x51')]},'raw':!![]})[_0x228f('0x26')](function(_0x208397){if(_0x208397&&_0x208397[_0x228f('0x52')]===0x0){return db[_0x228f('0x2a')][_0x228f('0x4d')]({'name':_0x17bcd9[_0x228f('0x2d')],'resourceId':_0x17bcd9['id'],'type':_0x208397[_0x228f('0x2d')],'sectionId':_0x208397['id']},{})[_0x228f('0x26')](function(){return _0x1872e2;});}else{return _0x1872e2;}})[_0x228f('0x47')](function(_0x43bbd2){logger[_0x228f('0x2b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x43bbd2);throw _0x43bbd2;});}return _0x1872e2;})[_0x228f('0x26')](respondWithResult(_0x250345,0xc9))[_0x228f('0x47')](handleError(_0x250345,null));};exports[_0x228f('0x25')]=function(_0x561144,_0x3e9f76){if(_0x561144[_0x228f('0x4e')]['id']){delete _0x561144[_0x228f('0x4e')]['id'];}return db[_0x228f('0x42')]['find']({'where':{'id':_0x561144[_0x228f('0x53')]['id']}})[_0x228f('0x26')](handleEntityNotFound(_0x3e9f76,null))[_0x228f('0x26')](saveUpdates(_0x561144[_0x228f('0x4e')],null))['then'](respondWithResult(_0x3e9f76,null))[_0x228f('0x47')](handleError(_0x3e9f76,null));};exports[_0x228f('0x27')]=function(_0x4b516e,_0x32787c){return db[_0x228f('0x42')][_0x228f('0x4c')]({'where':{'id':_0x4b516e[_0x228f('0x53')]['id']}})[_0x228f('0x26')](handleEntityNotFound(_0x32787c,null))[_0x228f('0x26')](db[_0x228f('0x54')][_0x228f('0x25')]({'ItemTypeId':null},{'where':{'ItemTypeId':_0x4b516e[_0x228f('0x53')]['id']}}))[_0x228f('0x26')](removeEntity(_0x32787c,null))['catch'](handleError(_0x32787c,null));};