Built motion from commit 20e1a16.|0.0.54
[motion.git] / server / api / service / service.controller.js
1 var _0x29f4=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x6C\x6F\x64\x61\x73\x68","\x75\x74\x69\x6C","\x55\x73\x65\x72","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x53\x65\x72\x76\x69\x63\x65","\x55\x73\x65\x72\x48\x61\x73\x53\x65\x72\x76\x69\x63\x65","\x43\x75\x73\x74\x6F\x6D\x46\x69\x65\x6C\x64","\x43\x6F\x6E\x74\x61\x63\x74","\x2E\x2E\x2F\x2E\x2E\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x75\x74\x69\x6C","\x69\x6E\x64\x65\x78","\x63\x61\x74\x63\x68","\x73\x65\x6E\x64","\x73\x74\x61\x74\x75\x73","\x74\x68\x65\x6E","\x71\x75\x65\x72\x79","\x67\x65\x74\x51\x75\x65\x72\x79","\x66\x69\x6E\x64\x41\x6E\x64\x43\x6F\x75\x6E\x74\x41\x6C\x6C","\x67\x65\x74\x43\x75\x73\x74\x6F\x6D\x46\x69\x65\x6C\x64\x73","\x6C\x6F\x67","\x69\x64","\x70\x61\x72\x61\x6D\x73","\x66\x69\x6E\x64\x41\x6C\x6C","\x73\x68\x6F\x77\x43\x75\x73\x74\x6F\x6D\x46\x69\x65\x6C\x64","\x73\x65\x6E\x64\x53\x74\x61\x74\x75\x73","\x66\x69\x6E\x64\x42\x79\x49\x64","\x75\x70\x64\x61\x74\x65\x43\x75\x73\x74\x6F\x6D\x46\x69\x65\x6C\x64","\x6C\x65\x6E\x67\x74\x68","\x4D\x45\x53\x53\x41\x47\x45\x5F\x45\x58\x49\x53\x54\x5F\x43\x55\x53\x54\x4F\x4D\x5F\x46\x49\x45\x4C\x44","\x62\x6F\x64\x79","\x6D\x65\x72\x67\x65","\x73\x61\x76\x65","\x6E\x61\x6D\x65","\x63\x72\x65\x61\x74\x65\x43\x75\x73\x74\x6F\x6D\x46\x69\x65\x6C\x64","\x53\x65\x72\x76\x69\x63\x65\x49\x64","\x63\x72\x65\x61\x74\x65","\x73\x68\x6F\x77","\x73\x65\x72\x76\x69\x63\x65\x56\x61\x6C\x69\x64\x61\x74\x69\x6F\x6E","\x46\x69\x6E\x64\x69\x6E\x67\x20\x61\x70\x70\x20\x72\x6F\x77\x2E\x2E\x2E\x2E\x2E","\x4D\x45\x53\x53\x41\x47\x45\x5F\x45\x58\x49\x53\x54\x5F\x53\x45\x52\x56\x49\x43\x45","\x75\x70\x64\x61\x74\x65","\x61\x64\x64\x41\x67\x65\x6E\x74\x73","\x6D\x61\x70","\x62\x75\x6C\x6B\x43\x72\x65\x61\x74\x65","\x61\x67\x65\x6E\x74\x73","\x72\x65\x6D\x6F\x76\x65\x41\x67\x65\x6E\x74\x73","\x72\x65\x6D\x6F\x76\x65\x55\x73\x65\x72\x73","\x6E\x6F\x20\x73\x65\x72\x76\x69\x63\x65\x20\x66\x6F\x75\x6E\x64","\x66\x69\x6E\x64","\x64\x65\x73\x74\x72\x6F\x79","\x62\x75\x6C\x6B\x44\x65\x73\x74\x72\x6F\x79","\x61\x6C\x6C","\x43\x6F\x6E\x74\x61\x63\x74\x73","\x70\x75\x73\x68","\x66\x6F\x72\x45\x61\x63\x68","\x64\x65\x61\x63\x74\x69\x76\x61\x74\x65\x43\x75\x73\x74\x6F\x6D\x46\x69\x65\x6C\x64"];_0x29f4[0];var _=require(_0x29f4[1]);var util=require(_0x29f4[2]);var User=require(_0x29f4[4])[_0x29f4[3]];var Service=require(_0x29f4[4])[_0x29f4[5]];var UserHasService=require(_0x29f4[4])[_0x29f4[6]];var CustomField=require(_0x29f4[4])[_0x29f4[7]];var Contact=require(_0x29f4[4])[_0x29f4[8]];var Util=require(_0x29f4[9]);exports[_0x29f4[10]]=function(_0x3426x9,_0x3426xa,_0x3426xb){return Service[_0x29f4[17]](Util[_0x29f4[16]](_0x3426x9[_0x29f4[15]]))[_0x29f4[14]](function(_0x3426xd){_0x3426xa[_0x29f4[13]](200)[_0x29f4[12]](_0x3426xd)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[18]]=function(_0x3426x9,_0x3426xa){CustomField[_0x29f4[22]]({where:{ServiceId:_0x3426x9[_0x29f4[21]][_0x29f4[20]],active:true}})[_0x29f4[14]](function(_0x3426xe){return _0x3426xa[_0x29f4[13]](200)[_0x29f4[12]](_0x3426xe)})[_0x29f4[11]](function(_0x3426xc){console[_0x29f4[19]](_0x3426xc);return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[23]]=function(_0x3426x9,_0x3426xa){CustomField[_0x29f4[25]](_0x3426x9[_0x29f4[21]][_0x29f4[20]])[_0x29f4[14]](function(_0x3426xf){if(!_0x3426xf){return _0x3426xa[_0x29f4[24]](404)};return _0x3426xa[_0x29f4[12]](_0x3426xf)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[26]]=function(_0x3426x9,_0x3426xa){CustomField[_0x29f4[22]]({where:{name:_0x3426x9[_0x29f4[29]][_0x29f4[32]],id:{$ne:_0x3426x9[_0x29f4[29]][_0x29f4[20]]}}})[_0x29f4[14]](function(_0x3426xe){if(!_0x3426xe){return _0x3426xa[_0x29f4[24]](404)};if(_0x3426xe[_0x29f4[27]]>0){return _0x3426xa[_0x29f4[13]](500)[_0x29f4[12]]({message:_0x29f4[28]})};if(_0x3426x9[_0x29f4[29]][_0x29f4[20]]){delete _0x3426x9[_0x29f4[29]][_0x29f4[20]]};CustomField[_0x29f4[25]](_0x3426x9[_0x29f4[21]][_0x29f4[20]])[_0x29f4[14]](function(_0x3426xf){if(!_0x3426xf){return _0x3426xa[_0x29f4[24]](404)};var _0x3426x10=_[_0x29f4[30]](_0x3426xf,_0x3426x9[_0x29f4[29]]);_0x3426x10[_0x29f4[31]]()[_0x29f4[14]](function(){return _0x3426xa[_0x29f4[13]](200)[_0x29f4[12]](_0x3426xf)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[33]]=function(_0x3426x9,_0x3426xa){_0x3426x9[_0x29f4[29]][_0x29f4[34]]=_0x3426x9[_0x29f4[21]][_0x29f4[20]];CustomField[_0x29f4[35]](_0x3426x9[_0x29f4[29]])[_0x29f4[14]](function(_0x3426xf){return _0x3426xa[_0x29f4[13]](201)[_0x29f4[12]](_0x3426xf)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[36]]=function(_0x3426x9,_0x3426xa){Service[_0x29f4[25]](_0x3426x9[_0x29f4[21]][_0x29f4[20]])[_0x29f4[14]](function(_0x3426x11){if(!_0x3426x11){return _0x3426xa[_0x29f4[24]](404)};return _0x3426xa[_0x29f4[12]](_0x3426x11)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[37]]=function(_0x3426x9,_0x3426xa){console[_0x29f4[19]](_0x3426x9[_0x29f4[29]]);Service[_0x29f4[22]]({where:{id:_0x3426x9[_0x29f4[29]][_0x29f4[20]]}})[_0x29f4[14]](function(_0x3426x11){if(!_0x3426x11){return _0x3426xa[_0x29f4[24]](404)};return _0x3426xa[_0x29f4[12]](_0x3426x11)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[35]]=function(_0x3426x9,_0x3426xa){Service[_0x29f4[22]]({where:{name:_0x3426x9[_0x29f4[29]][_0x29f4[32]]}})[_0x29f4[14]](function(_0x3426x12){console[_0x29f4[19]](_0x3426x12);console[_0x29f4[19]](_0x29f4[38]);if(!_0x3426x12){return _0x3426xa[_0x29f4[24]](404)};if(_0x3426x12[_0x29f4[27]]>0){return _0x3426xa[_0x29f4[13]](500)[_0x29f4[12]]({message:_0x29f4[39]})};Service[_0x29f4[35]](_0x3426x9[_0x29f4[29]])[_0x29f4[14]](function(_0x3426x11){return _0x3426xa[_0x29f4[13]](201)[_0x29f4[12]](_0x3426x11)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[40]]=function(_0x3426x9,_0x3426xa){Service[_0x29f4[22]]({where:{name:_0x3426x9[_0x29f4[29]][_0x29f4[32]]}})[_0x29f4[14]](function(_0x3426x12){console[_0x29f4[19]](_0x3426x12);console[_0x29f4[19]](_0x29f4[38]);if(!_0x3426x12){return _0x3426xa[_0x29f4[24]](404)};if(_0x3426x12[_0x29f4[27]]>0){return _0x3426xa[_0x29f4[13]](500)[_0x29f4[12]]({message:_0x29f4[39]})};return Service[_0x29f4[25]](_0x3426x9[_0x29f4[21]][_0x29f4[20]])})[_0x29f4[14]](function(_0x3426x11){if(!_0x3426x11){return _0x3426xa[_0x29f4[24]](404)};if(_0x3426x9[_0x29f4[29]][_0x29f4[20]]){delete _0x3426x9[_0x29f4[29]][_0x29f4[20]]};var _0x3426x10=_[_0x29f4[30]](_0x3426x11,_0x3426x9[_0x29f4[29]]);return _0x3426x10[_0x29f4[31]]()})[_0x29f4[14]](function(_0x3426x11){return _0x3426xa[_0x29f4[13]](200)[_0x29f4[12]](_0x3426x11)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};exports[_0x29f4[41]]=function(_0x3426x9,_0x3426xa,_0x3426xb){console[_0x29f4[19]](_0x29f4[41]);console[_0x29f4[19]](_0x3426x9[_0x29f4[21]]);console[_0x29f4[19]](_0x3426x9[_0x29f4[29]]);User[_0x29f4[22]]({where:{id:{$in:_0x3426x9[_0x29f4[29]][_0x29f4[44]]}}})[_0x29f4[14]](function(_0x3426x13){var _0x3426x14=_[_0x29f4[42]](_0x3426x13,function(_0x3426x15){return {service:_0x3426x9[_0x29f4[21]][_0x29f4[20]],membername:_0x3426x15[_0x29f4[32]],UserId:_0x3426x15[_0x29f4[20]]}});UserHasService[_0x29f4[43]](_0x3426x14,{individualHooks:true})[_0x29f4[14]](function(){return _0x3426xa[_0x29f4[24]](200)})[_0x29f4[11]](function(_0x3426xc){return _0x3426xb(_0x3426xc)})})[_0x29f4[11]](function(_0x3426xc){return _0x3426xb(_0x3426xc)})};exports[_0x29f4[45]]=function(_0x3426x9,_0x3426xa,_0x3426xb){Service[_0x29f4[48]]({where:{id:_0x3426x9[_0x29f4[21]][_0x29f4[20]]}})[_0x29f4[14]](function(_0x3426x11){if(_0x3426x11){_0x3426x11[_0x29f4[46]](_0x3426x9[_0x29f4[29]][_0x29f4[44]],{individualHooks:true})[_0x29f4[14]](function(){return _0x3426xa[_0x29f4[24]](200)})[_0x29f4[11]](function(_0x3426xc){return _0x3426xb(_0x3426xc)})}else {return _0x3426xb( new Error(_0x29f4[47]))}})[_0x29f4[11]](function(_0x3426xc){return _0x3426xb(_0x3426xc)})};exports[_0x29f4[49]]=function(_0x3426x9,_0x3426xa){destroyService(_0x3426x9[_0x29f4[21]][_0x29f4[20]],_0x3426xa)};exports[_0x29f4[50]]=function(_0x3426x9,_0x3426xa){destroyService(_0x3426x9[_0x29f4[15]][_0x29f4[20]],_0x3426xa)};function destroyService(_0x3426x17,_0x3426xa){return delOrUpdateCf(_0x3426x17)[_0x29f4[51]]()[_0x29f4[14]](function(){return Service[_0x29f4[49]]({where:{id:_0x3426x17},individualHooks:true})})[_0x29f4[14]](function(){return _0x3426xa[_0x29f4[24]](204)})[_0x29f4[11]](function(_0x3426xc){console[_0x29f4[19]](_0x3426xc);return handleError(_0x3426xa,_0x3426xc)})}function delOrUpdateCf(_0x3426x17){return CustomField[_0x29f4[22]]({where:{ServiceId:_0x3426x17},include:[{model:Contact}]})[_0x29f4[14]](function(_0x3426xe){console[_0x29f4[19]](_0x3426xe[_0x29f4[27]]);var _0x3426x19=[];_[_0x29f4[54]](_0x3426xe,function(_0x3426x1a){if(_0x3426x1a[_0x29f4[52]][_0x29f4[27]]){_0x3426x19[_0x29f4[53]](_0x3426x1a[_0x29f4[40]]({active:false}))}else {_0x3426x19[_0x29f4[53]](_0x3426x1a[_0x29f4[49]]())}});return _0x3426x19})}exports[_0x29f4[55]]=function(_0x3426x9,_0x3426xa){CustomField[_0x29f4[25]](_0x3426x9[_0x29f4[21]][_0x29f4[20]],{include:[{model:Contact}]})[_0x29f4[14]](function(_0x3426xf){if(!_0x3426xf){return _0x3426xa[_0x29f4[24]](404)};if(_0x3426xf[_0x29f4[52]][_0x29f4[27]]){return _0x3426xf[_0x29f4[40]]({active:false})}else {return _0x3426xf[_0x29f4[49]]()}})[_0x29f4[14]](function(){return _0x3426xa[_0x29f4[24]](204)})[_0x29f4[11]](function(_0x3426xc){return handleError(_0x3426xa,_0x3426xc)})};function handleError(_0x3426xa,_0x3426xc){return _0x3426xa[_0x29f4[13]](500)[_0x29f4[12]](_0x3426xc)}