File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
academy/[courseSlug]/[lessonSlug] Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -51,12 +51,15 @@ export default function LessonPage({ params }: LessonPageProps) {
5151 ? exerciseComplete
5252 : quizComplete )
5353
54- // Video lessons are considered complete once visited — no interactive gate required.
54+ const isUngatedLesson =
55+ lesson ?. lessonType === 'video' ||
56+ ( lesson ?. lessonType === 'mixed' && ! lesson . exerciseConfig && ! lesson . quizConfig )
57+
5558 useEffect ( ( ) => {
56- if ( lesson ?. lessonType === 'video' ) {
59+ if ( isUngatedLesson && lesson ) {
5760 markLessonComplete ( lesson . id )
5861 }
59- } , [ lesson ?. id , lesson ?. lessonType ] )
62+ } , [ lesson ?. id , isUngatedLesson ] )
6063
6164 if ( ! course || ! lesson ) {
6265 return (
Original file line number Diff line number Diff line change @@ -113,9 +113,29 @@ export async function POST(req: NextRequest) {
113113 certificateNumber,
114114 metadata,
115115 } )
116+ . onConflictDoNothing ( )
116117 . returning ( )
117118
118119 if ( ! certificate ) {
120+ const [ race ] = await db
121+ . select ( )
122+ . from ( academyCertificate )
123+ . where (
124+ and (
125+ eq ( academyCertificate . userId , session . user . id ) ,
126+ eq ( academyCertificate . courseId , courseId )
127+ )
128+ )
129+ . limit ( 1 )
130+ if ( race ?. status === 'active' ) {
131+ return NextResponse . json ( { certificate : race } )
132+ }
133+ if ( race ) {
134+ return NextResponse . json (
135+ { error : 'A certificate for this course already exists but is not active.' } ,
136+ { status : 409 }
137+ )
138+ }
119139 return NextResponse . json ( { error : 'Failed to issue certificate' } , { status : 500 } )
120140 }
121141
You can’t perform that action at this time.
0 commit comments