update the chat

main
Kushal Dotel 6 months ago
parent bec6c10e08
commit c16cf0f216
  1. 6
      backend/blueprints/chat/__init__.py

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

Loading…
Cancel
Save