Built motion from commit 639a1a7f.|2.6.19
[motion2.git] / server / api / squareProject / squareProject.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 _0xf485=['includeAll','include','findAll','rows','catch','show','keys','rawAttributes','intersection','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','update','body','params','production','lodash','../../components/parsers/qs','../../config/logger','api','../../config/environment','redis','defaults','localhost','./squareProject.socket','register','status','json','offset','limit','undefined','count','set','Content-Range','then','destroy','get','SquareProjects','UserProfileResource','publish','agi','stringify','sendStatus','error','stack','name','send','index','map','fieldName','key','model','query','filters','fields','attributes','length','nolimit','sort','where','pick','merge','VIRTUAL','options','SquareProject'];(function(_0x4408f6,_0x597ade){var _0x31f8fd=function(_0x384b2a){while(--_0x384b2a){_0x4408f6['push'](_0x4408f6['shift']());}};_0x31f8fd(++_0x597ade);}(_0xf485,0xe7));var _0x5f48=function(_0x3b8597,_0x57ce17){_0x3b8597=_0x3b8597-0x0;var _0x2089dc=_0xf485[_0x3b8597];return _0x2089dc;};'use strict';var _=require(_0x5f48('0x0'));var Redis=require('ioredis');var qs=require(_0x5f48('0x1'));var logger=require(_0x5f48('0x2'))(_0x5f48('0x3'));var config=require(_0x5f48('0x4'));var db=require('../../mysqldb')['db'];config[_0x5f48('0x5')]=_[_0x5f48('0x6')](config[_0x5f48('0x5')],{'host':_0x5f48('0x7'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x5f48('0x8'))[_0x5f48('0x9')](socket);function respondWithResult(_0x5ad1f6,_0x3a23ce){_0x3a23ce=_0x3a23ce||0xc8;return function(_0x47e52f){if(_0x47e52f){return _0x5ad1f6[_0x5f48('0xa')](_0x3a23ce)[_0x5f48('0xb')](_0x47e52f);}};}function respondWithFilteredResult(_0x2ae04f,_0x4991e9){return function(_0x20b040){if(_0x20b040){var _0x62d41e=typeof _0x4991e9[_0x5f48('0xc')]==='undefined'&&typeof _0x4991e9[_0x5f48('0xd')]===_0x5f48('0xe');var _0x43cc94=_0x20b040[_0x5f48('0xf')];var _0x586228=_0x62d41e?0x0:_0x4991e9[_0x5f48('0xc')];var _0x149b4c=_0x62d41e?_0x20b040[_0x5f48('0xf')]:_0x4991e9['offset']+_0x4991e9[_0x5f48('0xd')];var _0x1bf082;if(_0x149b4c>=_0x43cc94){_0x149b4c=_0x43cc94;_0x1bf082=0xc8;}else{_0x1bf082=0xce;}_0x2ae04f[_0x5f48('0xa')](_0x1bf082);return _0x2ae04f[_0x5f48('0x10')](_0x5f48('0x11'),_0x586228+'-'+_0x149b4c+'/'+_0x43cc94)[_0x5f48('0xb')](_0x20b040);}return null;};}function saveUpdates(_0x402c29){return function(_0x24fcbc){if(_0x24fcbc){return _0x24fcbc['update'](_0x402c29)[_0x5f48('0x12')](function(_0x545e3c){return _0x545e3c;});}return null;};}function removeEntity(_0x546d78){return function(_0x4d2c10){if(_0x4d2c10){return _0x4d2c10[_0x5f48('0x13')]()['then'](function(){var _0x3a3c54=_0x4d2c10[_0x5f48('0x14')]({'plain':!![]});var _0x3624a4=_0x5f48('0x15');return db[_0x5f48('0x16')][_0x5f48('0x13')]({'where':{'type':_0x3624a4,'resourceId':_0x3a3c54['id']}})[_0x5f48('0x12')](function(){return _0x4d2c10;});})['then'](function(){var _0x58a07f=new Redis(config[_0x5f48('0x5')]);_0x58a07f[_0x5f48('0x17')](_0x5f48('0x18'),JSON[_0x5f48('0x19')]({'id':_0x4d2c10['id'],'deleted':!![]}));})[_0x5f48('0x12')](function(){_0x546d78['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x315393){return function(_0x1c8048){if(!_0x1c8048){_0x315393[_0x5f48('0x1a')](0x194);}return _0x1c8048;};}function handleError(_0x376592,_0x4440e8){_0x4440e8=_0x4440e8||0x1f4;return function(_0x6e307b){logger[_0x5f48('0x1b')](_0x6e307b[_0x5f48('0x1c')]);if(_0x6e307b[_0x5f48('0x1d')]){delete _0x6e307b['name'];}_0x376592[_0x5f48('0xa')](_0x4440e8)[_0x5f48('0x1e')](_0x6e307b);};}exports[_0x5f48('0x1f')]=function(_0x46dd83,_0x192816){var _0x1992a1={},_0x3cb5c7={},_0x1f72d9={'count':0x0,'rows':[]};var _0x45ac33=_[_0x5f48('0x20')](db['SquareProject']['rawAttributes'],function(_0x228f21){return{'name':_0x228f21[_0x5f48('0x21')],'type':_0x228f21['type'][_0x5f48('0x22')]};});_0x3cb5c7[_0x5f48('0x23')]=_[_0x5f48('0x20')](_0x45ac33,_0x5f48('0x1d'));_0x3cb5c7[_0x5f48('0x24')]=_['keys'](_0x46dd83['query']);_0x3cb5c7[_0x5f48('0x25')]=_['intersection'](_0x3cb5c7['model'],_0x3cb5c7[_0x5f48('0x24')]);_0x1992a1['attributes']=_['intersection'](_0x3cb5c7[_0x5f48('0x23')],qs[_0x5f48('0x26')](_0x46dd83[_0x5f48('0x24')][_0x5f48('0x26')]));_0x1992a1[_0x5f48('0x27')]=_0x1992a1['attributes'][_0x5f48('0x28')]?_0x1992a1['attributes']:_0x3cb5c7[_0x5f48('0x23')];if(!_0x46dd83[_0x5f48('0x24')]['hasOwnProperty'](_0x5f48('0x29'))){_0x1992a1[_0x5f48('0xd')]=qs['limit'](_0x46dd83[_0x5f48('0x24')]['limit']);_0x1992a1[_0x5f48('0xc')]=qs[_0x5f48('0xc')](_0x46dd83[_0x5f48('0x24')]['offset']);}_0x1992a1['order']=qs[_0x5f48('0x2a')](_0x46dd83[_0x5f48('0x24')][_0x5f48('0x2a')]);_0x1992a1[_0x5f48('0x2b')]=qs['filters'](_[_0x5f48('0x2c')](_0x46dd83[_0x5f48('0x24')],_0x3cb5c7[_0x5f48('0x25')]),_0x45ac33);if(_0x46dd83[_0x5f48('0x24')]['filter']){_0x1992a1['where']=_[_0x5f48('0x2d')](_0x1992a1['where'],{'$or':_[_0x5f48('0x20')](_0x45ac33,function(_0x3e7345){if(_0x3e7345['type']!==_0x5f48('0x2e')){var _0x5ec385={};_0x5ec385[_0x3e7345[_0x5f48('0x1d')]]={'$like':'%'+_0x46dd83[_0x5f48('0x24')]['filter']+'%'};return _0x5ec385;}})});}_0x1992a1=_[_0x5f48('0x2d')]({},_0x1992a1,_0x46dd83[_0x5f48('0x2f')]);var _0x120084={'where':_0x1992a1[_0x5f48('0x2b')]};return db[_0x5f48('0x30')]['count'](_0x120084)[_0x5f48('0x12')](function(_0x3cfba9){_0x1f72d9['count']=_0x3cfba9;if(_0x46dd83['query'][_0x5f48('0x31')]){_0x1992a1[_0x5f48('0x32')]=[{'all':!![]}];}return db['SquareProject'][_0x5f48('0x33')](_0x1992a1);})[_0x5f48('0x12')](function(_0x3f9ce1){_0x1f72d9[_0x5f48('0x34')]=_0x3f9ce1;return _0x1f72d9;})[_0x5f48('0x12')](respondWithFilteredResult(_0x192816,_0x1992a1))[_0x5f48('0x35')](handleError(_0x192816,null));};exports[_0x5f48('0x36')]=function(_0x444bb8,_0x547a22){var _0xc91b01={'raw':![],'where':{'id':_0x444bb8['params']['id']}},_0x373149={};_0x373149[_0x5f48('0x23')]=_[_0x5f48('0x37')](db[_0x5f48('0x30')][_0x5f48('0x38')]);_0x373149['query']=_[_0x5f48('0x37')](_0x444bb8[_0x5f48('0x24')]);_0x373149[_0x5f48('0x25')]=_[_0x5f48('0x39')](_0x373149[_0x5f48('0x23')],_0x373149[_0x5f48('0x24')]);_0xc91b01[_0x5f48('0x27')]=_[_0x5f48('0x39')](_0x373149[_0x5f48('0x23')],qs['fields'](_0x444bb8[_0x5f48('0x24')][_0x5f48('0x26')]));_0xc91b01[_0x5f48('0x27')]=_0xc91b01[_0x5f48('0x27')][_0x5f48('0x28')]?_0xc91b01[_0x5f48('0x27')]:_0x373149[_0x5f48('0x23')];if(_0x444bb8[_0x5f48('0x24')][_0x5f48('0x31')]){_0xc91b01[_0x5f48('0x32')]=[{'all':!![]}];}_0xc91b01=_[_0x5f48('0x2d')]({},_0xc91b01,_0x444bb8['options']);return db[_0x5f48('0x30')][_0x5f48('0x3a')](_0xc91b01)[_0x5f48('0x12')](handleEntityNotFound(_0x547a22,null))[_0x5f48('0x12')](respondWithResult(_0x547a22,null))[_0x5f48('0x35')](handleError(_0x547a22,null));};exports[_0x5f48('0x3b')]=function(_0x5ae128,_0x338354){return db[_0x5f48('0x30')][_0x5f48('0x3b')](_0x5ae128['body'],{})[_0x5f48('0x12')](function(_0x220e34){var _0x23f6bc=_0x5ae128[_0x5f48('0x3c')]['get']({'plain':!![]});if(!_0x23f6bc)throw new Error(_0x5f48('0x3d'));if(_0x23f6bc[_0x5f48('0x3e')]===_0x5f48('0x3c')){var _0x518efb=_0x220e34[_0x5f48('0x14')]({'plain':!![]});var _0x38c8b4=_0x5f48('0x15');return db[_0x5f48('0x3f')]['find']({'where':{'name':_0x38c8b4,'userProfileId':_0x23f6bc[_0x5f48('0x40')]},'raw':!![]})[_0x5f48('0x12')](function(_0x3ebaf2){if(_0x3ebaf2&&_0x3ebaf2[_0x5f48('0x41')]===0x0){return db[_0x5f48('0x16')]['create']({'name':_0x518efb['name'],'resourceId':_0x518efb['id'],'type':_0x3ebaf2[_0x5f48('0x1d')],'sectionId':_0x3ebaf2['id']},{})[_0x5f48('0x12')](function(){return _0x220e34;});}else{return _0x220e34;}})['catch'](function(_0x19953a){logger[_0x5f48('0x1b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x19953a);throw _0x19953a;});}return _0x220e34;})[_0x5f48('0x12')](respondWithResult(_0x338354,0xc9))[_0x5f48('0x35')](handleError(_0x338354,null));};exports[_0x5f48('0x42')]=function(_0x13f9fc,_0x5ab9ed){if(_0x13f9fc['body']['id']){delete _0x13f9fc[_0x5f48('0x43')]['id'];}return db[_0x5f48('0x30')][_0x5f48('0x3a')]({'where':{'id':_0x13f9fc[_0x5f48('0x44')]['id']}})[_0x5f48('0x12')](handleEntityNotFound(_0x5ab9ed,null))[_0x5f48('0x12')](saveUpdates(_0x13f9fc[_0x5f48('0x43')],null))[_0x5f48('0x12')](function(_0x416e59){if(!_0x416e59)return;var _0x9e1f82=_0x416e59['get']({'plain':!![]});return _0x9e1f82;})[_0x5f48('0x12')](function(_0x1dc33c){var _0x4a45d2=new Redis(config[_0x5f48('0x5')]);_0x4a45d2[_0x5f48('0x17')](_0x5f48('0x18'),JSON[_0x5f48('0x19')](_[_0x5f48('0x2c')](_0x1dc33c,['id',_0x5f48('0x1d'),_0x5f48('0x45')])));return _0x1dc33c;})[_0x5f48('0x12')](respondWithResult(_0x5ab9ed,null))[_0x5f48('0x35')](handleError(_0x5ab9ed,null));};exports[_0x5f48('0x13')]=function(_0x58af4c,_0x3d9fb0){return db[_0x5f48('0x30')]['find']({'where':{'id':_0x58af4c[_0x5f48('0x44')]['id']}})[_0x5f48('0x12')](handleEntityNotFound(_0x3d9fb0,null))['then'](removeEntity(_0x3d9fb0,null))[_0x5f48('0x35')](handleError(_0x3d9fb0,null));};