Files
MathApp/notifications/models.py
Zareian b32194497c let a finished island quiz open the next island, and ground ask-AI in the student's book
The frontend plays node quizzes, but a node only completed once every one of its
8-13 lessons was completed separately, so students were stuck after the first
island of each unit. POST /api/nodes/{id}/quiz/complete now completes the node
(any score; score only sets stars/xp) and returns nextNodeId.

Also closes the other backend gaps found while auditing the frontend:
- /api/ai/ask without lessonId now picks the book from the user's grade instead
  of skipping retrieval, so the "ask Pi" tab is grounded in the textbook.
- guest sessions return a refreshToken; they used to go silently 401 after 1h.
- lesson_complete throttle 10/hour -> 120/hour (a lesson here is 1-2 questions).
- progressPercent is per grade, not over all 2,617 lessons of every grade.
- a one-year plan (299,000 toman) is created by migration when no plan exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 02:49:02 +03:30

32 lines
1.4 KiB
Python

from django.db import models
class Notification(models.Model):
# انواع رویدادهایی که این اپ فقط بهشون گوش می‌ده (event-listener)؛
# خودش تولیدکننده‌ی رویداد نیست. طبق سند معماری:
# LessonCompleted/XPEarned (Progress), OrderPaid (Payment),
# TicketReplied (Support), FamilyLinkAccepted/WeeklyReportReady (Family)
TYPE_CHOICES = [
('xp_earned', 'امتیاز گرفتی'),
('lesson_completed', 'درس تکمیل شد'),
('node_completed', 'جزیره تمام شد'),
('order_paid', 'پرداخت موفق'),
('ticket_replied', 'پاسخ تیکت'),
('family_link_accepted', 'اتصال خانواده تأیید شد'),
('weekly_report_ready', 'گزارش هفتگی آماده شد'),
]
user_id = models.IntegerField(db_index=True) # ارجاع سبک به accounts.User
type = models.CharField(max_length=30, choices=TYPE_CHOICES)
title = models.CharField(max_length=150)
body = models.CharField(max_length=300, blank=True)
related_id = models.IntegerField(null=True, blank=True) # id رکورد رویداد منبع، بدون FK واقعی
is_read = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return f"notif-{self.id}-{self.type}-user{self.user_id}"