11import { ENV } from '@vue-skuilder/common' ;
2- import { ClassroomConfig } from '../server/types ' ;
2+ import { ClassroomConfig } from '@vue-skuilder/common ' ;
33import moment from 'moment' ;
44import pouch from 'pouchdb-browser' ;
55import {
@@ -10,8 +10,7 @@ import {
1010} from '.' ;
1111import { StudyContentSource , StudySessionNewItem , StudySessionReviewItem } from './contentSource' ;
1212import { CourseDB , getTag } from './courseDB' ;
13- import { ScheduledCard } from './userDB' ;
14- import { getCurrentUser } from '@/stores/useAuthStore' ;
13+ import { ScheduledCard , User } from './userDB' ;
1514
1615const classroomLookupDBTitle = 'classdb-lookup' ;
1716export const CLASSROOM_CONFIG = 'ClassroomConfig' ;
@@ -52,9 +51,9 @@ interface ContentBase {
5251}
5352
5453abstract class ClassroomDBBase {
55- public _id : string ;
56- protected _db : PouchDB . Database ;
57- protected _cfg : ClassroomConfig ;
54+ public _id ! : string ;
55+ protected _db ! : PouchDB . Database ;
56+ protected _cfg ! : ClassroomConfig ;
5857 protected _initComplete : boolean = false ;
5958
6059 protected readonly _content_prefix : string = 'content' ;
@@ -99,12 +98,14 @@ abstract class ClassroomDBBase {
9998}
10099
101100export class StudentClassroomDB extends ClassroomDBBase implements StudyContentSource {
102- private readonly _prefix : string = 'content' ;
103- private userMessages : PouchDB . Core . Changes < object > ;
101+ // private readonly _prefix: string = 'content';
102+ private userMessages ! : PouchDB . Core . Changes < object > ;
103+ private _user : User ;
104104
105- private constructor ( classID : string ) {
105+ private constructor ( classID : string , user : User ) {
106106 super ( ) ;
107107 this . _id = classID ;
108+ this . _user = user ;
108109 this . init ( ) ;
109110 }
110111
@@ -129,8 +130,8 @@ export class StudentClassroomDB extends ClassroomDBBase implements StudyContentS
129130 }
130131 }
131132
132- public static async factory ( classID : string ) : Promise < StudentClassroomDB > {
133- const ret = new StudentClassroomDB ( classID ) ;
133+ public static async factory ( classID : string , user : User ) : Promise < StudentClassroomDB > {
134+ const ret = new StudentClassroomDB ( classID , user ) ;
134135 await ret . init ( ) ;
135136 return ret ;
136137 }
@@ -142,7 +143,7 @@ export class StudentClassroomDB extends ClassroomDBBase implements StudyContentS
142143 }
143144
144145 public async getPendingReviews ( ) : Promise < ( StudySessionReviewItem & ScheduledCard ) [ ] > {
145- const u = await getCurrentUser ( ) ;
146+ const u = this . _user ;
146147 return ( await u . getPendingReviews ( ) )
147148 . filter ( ( r ) => r . scheduledFor === 'classroom' && r . schedulingAgentId === this . _id )
148149 . map ( ( r ) => {
@@ -160,7 +161,7 @@ export class StudentClassroomDB extends ClassroomDBBase implements StudyContentS
160161 }
161162
162163 public async getNewCards ( ) : Promise < StudySessionNewItem [ ] > {
163- const activeCards = await ( await getCurrentUser ( ) ) . getActiveCards ( ) ;
164+ const activeCards = await this . _user . getActiveCards ( ) ;
164165 const now = moment . utc ( ) ;
165166 const assigned = await this . getAssignedContent ( ) ;
166167 const due = assigned . filter ( ( c ) => now . isAfter ( moment . utc ( c . activeOn , REVIEW_TIME_FORMAT ) ) ) ;
@@ -173,7 +174,7 @@ export class StudentClassroomDB extends ClassroomDBBase implements StudyContentS
173174 const content = due [ i ] ;
174175
175176 if ( content . type === 'course' ) {
176- const db = new CourseDB ( content . courseID ) ;
177+ const db = new CourseDB ( content . courseID , async ( ) => this . _user ) ;
177178 ret = ret . concat ( await db . getNewCards ( ) ) ;
178179 } else if ( content . type === 'tag' ) {
179180 const tagDoc = await getTag ( content . courseID , content . tagID ) ;
@@ -212,7 +213,7 @@ export class StudentClassroomDB extends ClassroomDBBase implements StudyContentS
212213 * Interface for managing a classroom.
213214 */
214215export default class TeacherClassroomDB extends ClassroomDBBase {
215- private _stuDb : PouchDB . Database ;
216+ private _stuDb ! : PouchDB . Database ;
216217
217218 private constructor ( classID : string ) {
218219 super ( ) ;
0 commit comments