def post(self, member_id): json_data = request.get_json() member = MemberModel(member_id, **json_data) try: member.save_to_db() except ValueError: return { "message": "An error occurred inserting the item." }, 500 # Internal server error return member.json(), 201 # created status code
def post(self, name): if MemberModel.find_by_name(name): return { "message": "Member named {} is already exists.".format(name) }, 400 member = MemberModel(name, 0) try: member.save_to_db() except: return { "message": "An error occurred while registering member." }, 500 return member.json(), 201
def add_member_to_db( self, member: MemberModel, role: RoleModel ) -> Tuple[MemberModel, RoleModel]: role = self.add_role_to_db(role) member = member.save_to_db() return member, role