From 76922cf942a04bca8138e971a038b6db94bc9aa5 Mon Sep 17 00:00:00 2001 From: Lutfian Rhdn Date: Sat, 26 Aug 2023 01:26:33 +0700 Subject: [PATCH] refactor:change eo registation notification to admin :recycle: --- src/repositories/UserRepository.py | 3 ++- src/services/AuthService.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/repositories/UserRepository.py b/src/repositories/UserRepository.py index b3b1a4d..63d9be9 100644 --- a/src/repositories/UserRepository.py +++ b/src/repositories/UserRepository.py @@ -4,7 +4,8 @@ class UserRepository: def getAllUser(self): return User.query.all() - + def getUserByRole(self,role): + return User.query.filter_by(role=role).all() def getUserByEmail(self,email): return User.query.filter_by(email=email).first() def createNewUser(self,data): diff --git a/src/services/AuthService.py b/src/services/AuthService.py index 80926c4..e2d2fba 100644 --- a/src/services/AuthService.py +++ b/src/services/AuthService.py @@ -16,7 +16,7 @@ def failedOrSuccessRequest(status, code, data): "code": code, 'data': data, } - def _sendNotification(self,data): + def _sendNotification(self,data,to): templates = render_template( 'html/registeredEoNotification.html', name=data.name, @@ -25,7 +25,7 @@ def _sendNotification(self,data): sendMail( templates=templates, subject="Ticket Event", - to=data.email + to=to ) return True @@ -40,7 +40,8 @@ def registerUser(self, data): return self.failedOrSuccessRequest('failed', 400, 'Validation failed') newUser = user_repository.createNewUser(data) if(newUser.role == 'EVENT_ORGANIZER'): - self._sendNotification(newUser) + userAdmin = user_repository.getUserByRole('ADMIN') + self._sendNotification(newUser,userAdmin[0].email) return self.failedOrSuccessRequest('success', 201, queryResultToDict([newUser])[0]) except ValueError as e: