Skip to content

Commit bde6157

Browse files
committed
expose more files, add more fixes
1 parent 769b0d5 commit bde6157

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

packages/db/src/pouch/classroomDB.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ENV } from '@vue-skuilder/common';
2-
import { ClassroomConfig } from '../server/types';
2+
import { ClassroomConfig } from '@vue-skuilder/common';
33
import moment from 'moment';
44
import pouch from 'pouchdb-browser';
55
import {
@@ -10,8 +10,7 @@ import {
1010
} from '.';
1111
import { StudyContentSource, StudySessionNewItem, StudySessionReviewItem } from './contentSource';
1212
import { CourseDB, getTag } from './courseDB';
13-
import { ScheduledCard } from './userDB';
14-
import { getCurrentUser } from '@/stores/useAuthStore';
13+
import { ScheduledCard, User } from './userDB';
1514

1615
const classroomLookupDBTitle = 'classdb-lookup';
1716
export const CLASSROOM_CONFIG = 'ClassroomConfig';
@@ -52,9 +51,9 @@ interface ContentBase {
5251
}
5352

5453
abstract 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

101100
export 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
*/
214215
export default class TeacherClassroomDB extends ClassroomDBBase {
215-
private _stuDb: PouchDB.Database;
216+
private _stuDb!: PouchDB.Database;
216217

217218
private constructor(classID: string) {
218219
super();

packages/db/src/pouch/contentSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function getStudySource(
5353
user: User
5454
): Promise<StudyContentSource> {
5555
if (source.type === 'classroom') {
56-
return await StudentClassroomDB.factory(source.id);
56+
return await StudentClassroomDB.factory(source.id, user);
5757
} else {
5858
// if (source.type === 'course') - removed so tsc is certain something returns
5959
return new CourseDB(source.id, async () => {

packages/db/src/pouch/courseAPI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import pouch from 'pouchdb-browser';
22
import { pouchDBincludeCredentialsConfig } from '.';
3-
import ENV from '@vue-skuilder/common';
3+
import { ENV } from '@vue-skuilder/common';
44
// import { DataShape } from '../base-course/Interfaces/DataShape';
55
import { NameSpacer, ShapeDescriptor } from '@vue-skuilder/common';
66
import { CourseConfig, DataShape } from '@vue-skuilder/common';
77
import { CourseElo, blankCourseElo, toCourseElo } from '@vue-skuilder/common';
88
import { CourseDB, createTag, updateCardElo } from './courseDB';
99
import { CardData, DisplayableData, DocType, Tag } from '../core/types-legacy';
1010
import { prepareNote55 } from '@vue-skuilder/common';
11-
11+
import { User } from './userDB';
1212
/**
1313
*
1414
* @param courseID id of the course (quilt) being added to
@@ -162,7 +162,7 @@ export async function addTagToCard(
162162
// In this case, should be converted to a server-request
163163
const prefixedTagID = getTagID(tagID);
164164
const courseDB = getCourseDB(courseID);
165-
const courseApi = new CourseDB(courseID);
165+
const courseApi = new CourseDB(courseID, async () => User.Dummy());
166166
try {
167167
console.log(`Applying tag ${tagID} to card ${courseID + '-' + cardID}...`);
168168
const tag = await courseDB.get<Tag>(prefixedTagID);

packages/db/src/pouch/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,6 @@ export function getStartAndEndKeys(key: string) {
232232

233233
export * from './userDB';
234234
export * from './courseDB';
235+
export * from './courseAPI';
236+
export * from './classroomDB';
237+
export * from './contentSource';

packages/db/src/pouch/userDB.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ export interface ScheduledCard {
106106
export class User {
107107
private static _instance: User;
108108
private static _initialized: boolean = false;
109+
110+
public static Dummy(): User {
111+
return new User('DummyUser');
112+
}
113+
109114
static readonly DOC_IDS = {
110115
CONFIG: 'CONFIG',
111116
COURSE_REGISTRATIONS: 'CourseRegistrations',

0 commit comments

Comments
 (0)