|
|
|
@ -14,7 +14,7 @@ chat = Blueprint('chat', __name__) |
|
|
|
|
@auth_required() |
|
|
|
|
def create_chat(): |
|
|
|
|
current_user: User = g.current_user # Fetch the logged-in user |
|
|
|
|
data = request.args |
|
|
|
|
data = request.form |
|
|
|
|
if not data.get("course_id"): |
|
|
|
|
return jsonify({"error": "Unknown Course"}), 400 |
|
|
|
|
if not data.get("message", "").strip(): |
|
|
|
@ -26,7 +26,7 @@ def create_chat(): |
|
|
|
|
Enrollment.courseID == data.get("course_id"), |
|
|
|
|
Enrollment.userID == current_user.id) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
).scalar() |
|
|
|
|
if not enrollment_record: |
|
|
|
|
return jsonify({"error": "You are not enrolled in this course."}), 403 |
|
|
|
|
if enrollment_record.currentPage < enrollment_record.course.pageForCommunity: |
|
|
|
@ -43,6 +43,8 @@ def create_chat(): |
|
|
|
|
new_chat = Chat( |
|
|
|
|
textContent=data.get("message").strip(), |
|
|
|
|
userID=current_user.id, |
|
|
|
|
user=g.current_user, |
|
|
|
|
course=enrollment_record.course, |
|
|
|
|
courseID=data.get("course_id"), |
|
|
|
|
) |
|
|
|
|
db.session.add(new_chat) |
|
|
|
|