Built motion from commit 1fd437e9.|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 _0x5c55=['query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','rows','catch','params','includeAll','find','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','agi','production','lodash','ioredis','../../config/logger','api','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./squareProject.socket','json','offset','limit','undefined','count','status','set','Content-Range','then','destroy','get','UserProfileResource','publish','stringify','end','sendStatus','error','stack','name','send','index','SquareProject','rawAttributes','fieldName','type','key','model','map'];(function(_0x123e7a,_0x557878){var _0x398c86=function(_0x69aba4){while(--_0x69aba4){_0x123e7a['push'](_0x123e7a['shift']());}};_0x398c86(++_0x557878);}(_0x5c55,0x6a));var _0x55c5=function(_0xd5a842,_0x3bef1f){_0xd5a842=_0xd5a842-0x0;var _0xcedd84=_0x5c55[_0xd5a842];return _0xcedd84;};'use strict';var _=require(_0x55c5('0x0'));var Redis=require(_0x55c5('0x1'));var qs=require('../../components/parsers/qs');var logger=require(_0x55c5('0x2'))(_0x55c5('0x3'));var config=require('../../config/environment');var db=require(_0x55c5('0x4'))['db'];config['redis']=_[_0x55c5('0x5')](config[_0x55c5('0x6')],{'host':_0x55c5('0x7'),'port':0x18eb});var socket=require(_0x55c5('0x8'))(new Redis(config['redis']));require(_0x55c5('0x9'))['register'](socket);function respondWithResult(_0x36e7a0,_0x50f201){_0x50f201=_0x50f201||0xc8;return function(_0x54f80a){if(_0x54f80a){return _0x36e7a0['status'](_0x50f201)[_0x55c5('0xa')](_0x54f80a);}};}function respondWithFilteredResult(_0x241e95,_0x3a1569){return function(_0x526f31){if(_0x526f31){var _0x1848d3=typeof _0x3a1569[_0x55c5('0xb')]==='undefined'&&typeof _0x3a1569[_0x55c5('0xc')]===_0x55c5('0xd');var _0x3628b7=_0x526f31[_0x55c5('0xe')];var _0x4aff35=_0x1848d3?0x0:_0x3a1569[_0x55c5('0xb')];var _0x3c7266=_0x1848d3?_0x526f31[_0x55c5('0xe')]:_0x3a1569[_0x55c5('0xb')]+_0x3a1569[_0x55c5('0xc')];var _0x58b8f8;if(_0x3c7266>=_0x3628b7){_0x3c7266=_0x3628b7;_0x58b8f8=0xc8;}else{_0x58b8f8=0xce;}_0x241e95[_0x55c5('0xf')](_0x58b8f8);return _0x241e95[_0x55c5('0x10')](_0x55c5('0x11'),_0x4aff35+'-'+_0x3c7266+'/'+_0x3628b7)[_0x55c5('0xa')](_0x526f31);}return null;};}function saveUpdates(_0xa91378){return function(_0x29e726){if(_0x29e726){return _0x29e726['update'](_0xa91378)[_0x55c5('0x12')](function(_0x557f1b){return _0x557f1b;});}return null;};}function removeEntity(_0x44fadb){return function(_0x5b8145){if(_0x5b8145){return _0x5b8145[_0x55c5('0x13')]()[_0x55c5('0x12')](function(){var _0x4154e5=_0x5b8145[_0x55c5('0x14')]({'plain':!![]});var _0xd2fdde='SquareProjects';return db[_0x55c5('0x15')]['destroy']({'where':{'type':_0xd2fdde,'resourceId':_0x4154e5['id']}})[_0x55c5('0x12')](function(){return _0x5b8145;});})[_0x55c5('0x12')](function(){var _0x1141e4=new Redis(config[_0x55c5('0x6')]);_0x1141e4[_0x55c5('0x16')]('agi',JSON[_0x55c5('0x17')]({'id':_0x5b8145['id'],'deleted':!![]}));})[_0x55c5('0x12')](function(){_0x44fadb[_0x55c5('0xf')](0xcc)[_0x55c5('0x18')]();});}};}function handleEntityNotFound(_0x577643){return function(_0x5c22c3){if(!_0x5c22c3){_0x577643[_0x55c5('0x19')](0x194);}return _0x5c22c3;};}function handleError(_0x33bee6,_0xf56c65){_0xf56c65=_0xf56c65||0x1f4;return function(_0x48274e){logger[_0x55c5('0x1a')](_0x48274e[_0x55c5('0x1b')]);if(_0x48274e[_0x55c5('0x1c')]){delete _0x48274e[_0x55c5('0x1c')];}_0x33bee6[_0x55c5('0xf')](_0xf56c65)[_0x55c5('0x1d')](_0x48274e);};}exports[_0x55c5('0x1e')]=function(_0x267ca6,_0x21a8bc){var _0x3d9d3b={},_0x1f3d5f={},_0x2d9db5={'count':0x0,'rows':[]};var _0x38a8b7=_['map'](db[_0x55c5('0x1f')][_0x55c5('0x20')],function(_0x18f404){return{'name':_0x18f404[_0x55c5('0x21')],'type':_0x18f404[_0x55c5('0x22')][_0x55c5('0x23')]};});_0x1f3d5f[_0x55c5('0x24')]=_[_0x55c5('0x25')](_0x38a8b7,'name');_0x1f3d5f[_0x55c5('0x26')]=_[_0x55c5('0x27')](_0x267ca6[_0x55c5('0x26')]);_0x1f3d5f[_0x55c5('0x28')]=_[_0x55c5('0x29')](_0x1f3d5f['model'],_0x1f3d5f['query']);_0x3d9d3b[_0x55c5('0x2a')]=_['intersection'](_0x1f3d5f[_0x55c5('0x24')],qs[_0x55c5('0x2b')](_0x267ca6['query'][_0x55c5('0x2b')]));_0x3d9d3b['attributes']=_0x3d9d3b['attributes'][_0x55c5('0x2c')]?_0x3d9d3b[_0x55c5('0x2a')]:_0x1f3d5f[_0x55c5('0x24')];if(!_0x267ca6[_0x55c5('0x26')][_0x55c5('0x2d')](_0x55c5('0x2e'))){_0x3d9d3b[_0x55c5('0xc')]=qs[_0x55c5('0xc')](_0x267ca6[_0x55c5('0x26')][_0x55c5('0xc')]);_0x3d9d3b['offset']=qs[_0x55c5('0xb')](_0x267ca6[_0x55c5('0x26')][_0x55c5('0xb')]);}_0x3d9d3b[_0x55c5('0x2f')]=qs[_0x55c5('0x30')](_0x267ca6[_0x55c5('0x26')][_0x55c5('0x30')]);_0x3d9d3b[_0x55c5('0x31')]=qs[_0x55c5('0x28')](_[_0x55c5('0x32')](_0x267ca6['query'],_0x1f3d5f[_0x55c5('0x28')]),_0x38a8b7);if(_0x267ca6[_0x55c5('0x26')][_0x55c5('0x33')]){_0x3d9d3b[_0x55c5('0x31')]=_[_0x55c5('0x34')](_0x3d9d3b[_0x55c5('0x31')],{'$or':_['map'](_0x38a8b7,function(_0x51ae49){if(_0x51ae49[_0x55c5('0x22')]!==_0x55c5('0x35')){var _0x2fa854={};_0x2fa854[_0x51ae49[_0x55c5('0x1c')]]={'$like':'%'+_0x267ca6[_0x55c5('0x26')]['filter']+'%'};return _0x2fa854;}})});}_0x3d9d3b=_[_0x55c5('0x34')]({},_0x3d9d3b,_0x267ca6[_0x55c5('0x36')]);var _0x199fb6={'where':_0x3d9d3b[_0x55c5('0x31')]};return db[_0x55c5('0x1f')]['count'](_0x199fb6)[_0x55c5('0x12')](function(_0x28c26d){_0x2d9db5['count']=_0x28c26d;if(_0x267ca6[_0x55c5('0x26')]['includeAll']){_0x3d9d3b[_0x55c5('0x37')]=[{'all':!![]}];}return db[_0x55c5('0x1f')][_0x55c5('0x38')](_0x3d9d3b);})['then'](function(_0x2ea152){_0x2d9db5[_0x55c5('0x39')]=_0x2ea152;return _0x2d9db5;})[_0x55c5('0x12')](respondWithFilteredResult(_0x21a8bc,_0x3d9d3b))[_0x55c5('0x3a')](handleError(_0x21a8bc,null));};exports['show']=function(_0x58e843,_0x520617){var _0x15a3b4={'raw':![],'where':{'id':_0x58e843[_0x55c5('0x3b')]['id']}},_0x577e8d={};_0x577e8d[_0x55c5('0x24')]=_[_0x55c5('0x27')](db[_0x55c5('0x1f')][_0x55c5('0x20')]);_0x577e8d[_0x55c5('0x26')]=_[_0x55c5('0x27')](_0x58e843[_0x55c5('0x26')]);_0x577e8d['filters']=_['intersection'](_0x577e8d[_0x55c5('0x24')],_0x577e8d[_0x55c5('0x26')]);_0x15a3b4[_0x55c5('0x2a')]=_[_0x55c5('0x29')](_0x577e8d[_0x55c5('0x24')],qs['fields'](_0x58e843[_0x55c5('0x26')][_0x55c5('0x2b')]));_0x15a3b4['attributes']=_0x15a3b4[_0x55c5('0x2a')]['length']?_0x15a3b4[_0x55c5('0x2a')]:_0x577e8d['model'];if(_0x58e843[_0x55c5('0x26')][_0x55c5('0x3c')]){_0x15a3b4[_0x55c5('0x37')]=[{'all':!![]}];}_0x15a3b4=_[_0x55c5('0x34')]({},_0x15a3b4,_0x58e843[_0x55c5('0x36')]);return db[_0x55c5('0x1f')][_0x55c5('0x3d')](_0x15a3b4)[_0x55c5('0x12')](handleEntityNotFound(_0x520617,null))['then'](respondWithResult(_0x520617,null))[_0x55c5('0x3a')](handleError(_0x520617,null));};exports['create']=function(_0xb598c0,_0x1f300c){return db['SquareProject']['create'](_0xb598c0[_0x55c5('0x3e')],{})[_0x55c5('0x12')](function(_0x178f20){var _0x42a311=_0xb598c0[_0x55c5('0x3f')][_0x55c5('0x14')]({'plain':!![]});if(!_0x42a311)throw new Error(_0x55c5('0x40'));if(_0x42a311['role']===_0x55c5('0x3f')){var _0x1b4c22=_0x178f20[_0x55c5('0x14')]({'plain':!![]});var _0x2ce6a8='SquareProjects';return db[_0x55c5('0x41')][_0x55c5('0x3d')]({'where':{'name':_0x2ce6a8,'userProfileId':_0x42a311[_0x55c5('0x42')]},'raw':!![]})['then'](function(_0x30fbef){if(_0x30fbef&&_0x30fbef[_0x55c5('0x43')]===0x0){return db[_0x55c5('0x15')][_0x55c5('0x44')]({'name':_0x1b4c22[_0x55c5('0x1c')],'resourceId':_0x1b4c22['id'],'type':_0x30fbef[_0x55c5('0x1c')],'sectionId':_0x30fbef['id']},{})[_0x55c5('0x12')](function(){return _0x178f20;});}else{return _0x178f20;}})['catch'](function(_0x2069c4){logger[_0x55c5('0x1a')](_0x55c5('0x45'),_0x2069c4);throw _0x2069c4;});}return _0x178f20;})[_0x55c5('0x12')](respondWithResult(_0x1f300c,0xc9))[_0x55c5('0x3a')](handleError(_0x1f300c,null));};exports['update']=function(_0x1cbec0,_0x4e20f7){if(_0x1cbec0[_0x55c5('0x3e')]['id']){delete _0x1cbec0[_0x55c5('0x3e')]['id'];}return db['SquareProject'][_0x55c5('0x3d')]({'where':{'id':_0x1cbec0[_0x55c5('0x3b')]['id']}})[_0x55c5('0x12')](handleEntityNotFound(_0x4e20f7,null))[_0x55c5('0x12')](saveUpdates(_0x1cbec0[_0x55c5('0x3e')],null))['then'](function(_0xa81fc6){if(!_0xa81fc6)return;var _0x41db20=_0xa81fc6[_0x55c5('0x14')]({'plain':!![]});return _0x41db20;})[_0x55c5('0x12')](function(_0x363a84){var _0x19ba77=new Redis(config['redis']);_0x19ba77[_0x55c5('0x16')](_0x55c5('0x46'),JSON[_0x55c5('0x17')](_[_0x55c5('0x32')](_0x363a84,['id',_0x55c5('0x1c'),_0x55c5('0x47')])));return _0x363a84;})[_0x55c5('0x12')](respondWithResult(_0x4e20f7,null))[_0x55c5('0x3a')](handleError(_0x4e20f7,null));};exports[_0x55c5('0x13')]=function(_0x1a87a6,_0x24f281){return db[_0x55c5('0x1f')][_0x55c5('0x3d')]({'where':{'id':_0x1a87a6[_0x55c5('0x3b')]['id']}})[_0x55c5('0x12')](handleEntityNotFound(_0x24f281,null))[_0x55c5('0x12')](removeEntity(_0x24f281,null))['catch'](handleError(_0x24f281,null));};