Built motion from commit b5996064.|2.6.21
[motion2.git] / server / api / cmContactHasItem / cmContactHasItem.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 _0x56f3=['../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','apply','reject','then','get','CmContactHasItems','destroy','end','error','stack','name','send','index','map','CmContactHasItem','rawAttributes','fieldName','type','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','rows','show','params','keys','options','find','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','update','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs'];(function(_0x5dc75b,_0x5b00c4){var _0x47de00=function(_0x3e6eba){while(--_0x3e6eba){_0x5dc75b['push'](_0x5dc75b['shift']());}};_0x47de00(++_0x5b00c4);}(_0x56f3,0x18c));var _0x356f=function(_0x3c240f,_0x377ec1){_0x3c240f=_0x3c240f-0x0;var _0x5a148a=_0x56f3[_0x3c240f];return _0x5a148a;};'use strict';var emlformat=require(_0x356f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x356f('0x1'));var jsonpatch=require(_0x356f('0x2'));var rp=require(_0x356f('0x3'));var moment=require(_0x356f('0x4'));var BPromise=require(_0x356f('0x5'));var Mustache=require(_0x356f('0x6'));var util=require('util');var path=require('path');var sox=require(_0x356f('0x7'));var csv=require(_0x356f('0x8'));var ejs=require(_0x356f('0x9'));var fs=require('fs');var fs_extra=require(_0x356f('0xa'));var _=require(_0x356f('0xb'));var squel=require('squel');var crypto=require(_0x356f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x356f('0xd'));var toCsv=require(_0x356f('0x8'));var querystring=require(_0x356f('0xe'));var Papa=require(_0x356f('0xf'));var Redis=require(_0x356f('0x10'));var authService=require(_0x356f('0x11'));var qs=require(_0x356f('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x356f('0x13'));var logger=require(_0x356f('0x14'))(_0x356f('0x15'));var utils=require(_0x356f('0x16'));var config=require(_0x356f('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x356f('0x18'))['db'];function respondWithStatusCode(_0xb5c504,_0x5a85bd){_0x5a85bd=_0x5a85bd||0xcc;return function(_0x1b4136){if(_0x1b4136){return _0xb5c504[_0x356f('0x19')](_0x5a85bd);}return _0xb5c504['status'](_0x5a85bd)['end']();};}function respondWithResult(_0x452aac,_0x2393ae){_0x2393ae=_0x2393ae||0xc8;return function(_0x1a9e07){if(_0x1a9e07){return _0x452aac[_0x356f('0x1a')](_0x2393ae)[_0x356f('0x1b')](_0x1a9e07);}};}function respondWithFilteredResult(_0x34113e,_0x5ab745){return function(_0x39b5ce){if(_0x39b5ce){var _0x45fd80=typeof _0x5ab745[_0x356f('0x1c')]===_0x356f('0x1d')&&typeof _0x5ab745[_0x356f('0x1e')]===_0x356f('0x1d');var _0x57ea21=_0x39b5ce[_0x356f('0x1f')];var _0x4471c9=_0x45fd80?0x0:_0x5ab745[_0x356f('0x1c')];var _0x5a9f02=_0x45fd80?_0x39b5ce[_0x356f('0x1f')]:_0x5ab745[_0x356f('0x1c')]+_0x5ab745[_0x356f('0x1e')];var _0x41a610;if(_0x5a9f02>=_0x57ea21){_0x5a9f02=_0x57ea21;_0x41a610=0xc8;}else{_0x41a610=0xce;}_0x34113e[_0x356f('0x1a')](_0x41a610);return _0x34113e['set']('Content-Range',_0x4471c9+'-'+_0x5a9f02+'/'+_0x57ea21)[_0x356f('0x1b')](_0x39b5ce);}return null;};}function patchUpdates(_0x4379de){return function(_0x33af65){try{jsonpatch[_0x356f('0x20')](_0x33af65,_0x4379de,!![]);}catch(_0x24512b){return BPromise[_0x356f('0x21')](_0x24512b);}return _0x33af65['save']();};}function saveUpdates(_0x3eb84e,_0x1ec7de){return function(_0x3be0c1){if(_0x3be0c1){return _0x3be0c1['update'](_0x3eb84e)[_0x356f('0x22')](function(_0x386787){return _0x386787;});}return null;};}function removeEntity(_0x12fc18,_0x329f99){return function(_0x57d2ff){if(_0x57d2ff){return _0x57d2ff['destroy']()['then'](function(){var _0x529d32=_0x57d2ff[_0x356f('0x23')]({'plain':!![]});var _0x48f38e=_0x356f('0x24');return db['UserProfileResource'][_0x356f('0x25')]({'where':{'type':_0x48f38e,'resourceId':_0x529d32['id']}})['then'](function(){return _0x57d2ff;});})[_0x356f('0x22')](function(){_0x12fc18[_0x356f('0x1a')](0xcc)[_0x356f('0x26')]();});}};}function handleEntityNotFound(_0x9e0a1d,_0x4414de){return function(_0x255c4d){if(!_0x255c4d){_0x9e0a1d['sendStatus'](0x194);}return _0x255c4d;};}function handleError(_0x3bdf67,_0x4e91bd){_0x4e91bd=_0x4e91bd||0x1f4;return function(_0x25db3f){logger[_0x356f('0x27')](_0x25db3f[_0x356f('0x28')]);if(_0x25db3f[_0x356f('0x29')]){delete _0x25db3f[_0x356f('0x29')];}_0x3bdf67['status'](_0x4e91bd)[_0x356f('0x2a')](_0x25db3f);};}exports[_0x356f('0x2b')]=function(_0x3edab9,_0x3489cf){var _0x554480={},_0x1204ba={},_0x338a9c={'count':0x0,'rows':[]};var _0x16dd03=_[_0x356f('0x2c')](db[_0x356f('0x2d')][_0x356f('0x2e')],function(_0x3b43f6){return{'name':_0x3b43f6[_0x356f('0x2f')],'type':_0x3b43f6[_0x356f('0x30')]['key']};});_0x1204ba[_0x356f('0x31')]=_[_0x356f('0x2c')](_0x16dd03,_0x356f('0x29'));_0x1204ba[_0x356f('0x32')]=_['keys'](_0x3edab9['query']);_0x1204ba[_0x356f('0x33')]=_[_0x356f('0x34')](_0x1204ba['model'],_0x1204ba[_0x356f('0x32')]);_0x554480['attributes']=_['intersection'](_0x1204ba[_0x356f('0x31')],qs[_0x356f('0x35')](_0x3edab9[_0x356f('0x32')][_0x356f('0x35')]));_0x554480['attributes']=_0x554480[_0x356f('0x36')][_0x356f('0x37')]?_0x554480[_0x356f('0x36')]:_0x1204ba['model'];if(!_0x3edab9[_0x356f('0x32')][_0x356f('0x38')](_0x356f('0x39'))){_0x554480[_0x356f('0x1e')]=qs['limit'](_0x3edab9[_0x356f('0x32')][_0x356f('0x1e')]);_0x554480[_0x356f('0x1c')]=qs[_0x356f('0x1c')](_0x3edab9[_0x356f('0x32')]['offset']);}_0x554480['order']=qs[_0x356f('0x3a')](_0x3edab9['query'][_0x356f('0x3a')]);_0x554480[_0x356f('0x3b')]=qs['filters'](_[_0x356f('0x3c')](_0x3edab9['query'],_0x1204ba[_0x356f('0x33')]),_0x16dd03);if(_0x3edab9['query'][_0x356f('0x3d')]){_0x554480[_0x356f('0x3b')]=_[_0x356f('0x3e')](_0x554480[_0x356f('0x3b')],{'$or':_[_0x356f('0x2c')](_0x16dd03,function(_0x5d6485){if(_0x5d6485['type']!==_0x356f('0x3f')){var _0xba0751={};_0xba0751[_0x5d6485['name']]={'$like':'%'+_0x3edab9[_0x356f('0x32')]['filter']+'%'};return _0xba0751;}})});}_0x554480=_[_0x356f('0x3e')]({},_0x554480,_0x3edab9['options']);var _0x13d610={'where':_0x554480[_0x356f('0x3b')]};return db[_0x356f('0x2d')]['count'](_0x13d610)[_0x356f('0x22')](function(_0x328d0b){_0x338a9c[_0x356f('0x1f')]=_0x328d0b;if(_0x3edab9[_0x356f('0x32')][_0x356f('0x40')]){_0x554480[_0x356f('0x41')]=[{'all':!![]}];}return db['CmContactHasItem']['findAll'](_0x554480);})[_0x356f('0x22')](function(_0x4ba786){_0x338a9c[_0x356f('0x42')]=_0x4ba786;return _0x338a9c;})['then'](respondWithFilteredResult(_0x3489cf,_0x554480))['catch'](handleError(_0x3489cf,null));};exports[_0x356f('0x43')]=function(_0x37d607,_0x308ead){var _0x2ceab9={'raw':!![],'where':{'id':_0x37d607[_0x356f('0x44')]['id']}},_0x5880f2={};_0x5880f2[_0x356f('0x31')]=_[_0x356f('0x45')](db[_0x356f('0x2d')][_0x356f('0x2e')]);_0x5880f2[_0x356f('0x32')]=_[_0x356f('0x45')](_0x37d607['query']);_0x5880f2['filters']=_['intersection'](_0x5880f2[_0x356f('0x31')],_0x5880f2[_0x356f('0x32')]);_0x2ceab9[_0x356f('0x36')]=_[_0x356f('0x34')](_0x5880f2[_0x356f('0x31')],qs['fields'](_0x37d607['query'][_0x356f('0x35')]));_0x2ceab9['attributes']=_0x2ceab9[_0x356f('0x36')][_0x356f('0x37')]?_0x2ceab9['attributes']:_0x5880f2[_0x356f('0x31')];if(_0x37d607[_0x356f('0x32')][_0x356f('0x40')]){_0x2ceab9[_0x356f('0x41')]=[{'all':!![]}];}_0x2ceab9=_['merge']({},_0x2ceab9,_0x37d607[_0x356f('0x46')]);return db[_0x356f('0x2d')][_0x356f('0x47')](_0x2ceab9)[_0x356f('0x22')](handleEntityNotFound(_0x308ead,null))['then'](respondWithResult(_0x308ead,null))[_0x356f('0x48')](handleError(_0x308ead,null));};exports[_0x356f('0x49')]=function(_0x46aa26,_0x531d72){return db[_0x356f('0x2d')][_0x356f('0x49')](_0x46aa26[_0x356f('0x4a')],{})[_0x356f('0x22')](function(_0x2a35f2){var _0xe5d33=_0x46aa26[_0x356f('0x4b')][_0x356f('0x23')]({'plain':!![]});if(!_0xe5d33)throw new Error(_0x356f('0x4c'));if(_0xe5d33[_0x356f('0x4d')]===_0x356f('0x4b')){var _0x314a15=_0x2a35f2[_0x356f('0x23')]({'plain':!![]});var _0x38703e='CmContactHasItems';return db[_0x356f('0x4e')]['find']({'where':{'name':_0x38703e,'userProfileId':_0xe5d33[_0x356f('0x4f')]},'raw':!![]})[_0x356f('0x22')](function(_0x56d674){if(_0x56d674&&_0x56d674[_0x356f('0x50')]===0x0){return db[_0x356f('0x51')][_0x356f('0x49')]({'name':_0x314a15[_0x356f('0x29')],'resourceId':_0x314a15['id'],'type':_0x56d674[_0x356f('0x29')],'sectionId':_0x56d674['id']},{})[_0x356f('0x22')](function(){return _0x2a35f2;});}else{return _0x2a35f2;}})[_0x356f('0x48')](function(_0x2fbd20){logger[_0x356f('0x27')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2fbd20);throw _0x2fbd20;});}return _0x2a35f2;})['then'](respondWithResult(_0x531d72,0xc9))[_0x356f('0x48')](handleError(_0x531d72,null));};exports[_0x356f('0x52')]=function(_0x419672,_0x19b101){if(_0x419672[_0x356f('0x4a')]['id']){delete _0x419672[_0x356f('0x4a')]['id'];}return db[_0x356f('0x2d')][_0x356f('0x47')]({'where':{'id':_0x419672[_0x356f('0x44')]['id']}})[_0x356f('0x22')](handleEntityNotFound(_0x19b101,null))[_0x356f('0x22')](saveUpdates(_0x419672[_0x356f('0x4a')],null))['then'](respondWithResult(_0x19b101,null))[_0x356f('0x48')](handleError(_0x19b101,null));};exports[_0x356f('0x25')]=function(_0x39b499,_0x4c526a){return db[_0x356f('0x2d')]['find']({'where':{'id':_0x39b499[_0x356f('0x44')]['id']}})[_0x356f('0x22')](handleEntityNotFound(_0x4c526a,null))[_0x356f('0x22')](removeEntity(_0x4c526a,null))[_0x356f('0x48')](handleError(_0x4c526a,null));};