1+ import { DocType , DocTypePrefixes } from '@db/core' ;
12import { getCardHistoryID } from '@db/core/util' ;
23import { CourseElo , Status } from '@vue-skuilder/common' ;
34import moment , { Moment } from 'moment' ;
@@ -23,7 +24,6 @@ import type { SyncStrategy } from './SyncStrategy';
2324import {
2425 filterAllDocsByPrefix ,
2526 getStartAndEndKeys ,
26- REVIEW_PREFIX ,
2727 REVIEW_TIME_FORMAT ,
2828 getLocalUserDB ,
2929 scheduleCardReviewLocal ,
@@ -38,8 +38,6 @@ const log = (s: any) => {
3838 logger . info ( s ) ;
3939} ;
4040
41- const cardHistoryPrefix = 'cardH-' ;
42-
4341// console.log(`Connecting to remote: ${remoteStr}`);
4442
4543interface DesignDoc {
@@ -174,8 +172,8 @@ Currently logged-in as ${this._username}.`
174172 const id = row . id ;
175173 // Delete user progress data but preserve core user documents
176174 return (
177- id . startsWith ( cardHistoryPrefix ) || // Card interaction history
178- id . startsWith ( REVIEW_PREFIX ) || // Scheduled reviews
175+ id . startsWith ( DocTypePrefixes [ DocType . CARDRECORD ] ) || // Card interaction history
176+ id . startsWith ( DocTypePrefixes [ DocType . SCHEDULED_CARD ] ) || // Scheduled reviews
179177 id === BaseUser . DOC_IDS . COURSE_REGISTRATIONS || // Course registrations
180178 id === BaseUser . DOC_IDS . CLASSROOM_REGISTRATIONS || // Classroom registrations
181179 id === BaseUser . DOC_IDS . CONFIG // User config
@@ -264,7 +262,7 @@ Currently logged-in as ${this._username}.`
264262 *
265263 */
266264 public async getActiveCards ( ) {
267- const keys = getStartAndEndKeys ( REVIEW_PREFIX ) ;
265+ const keys = getStartAndEndKeys ( DocTypePrefixes [ DocType . SCHEDULED_CARD ] ) ;
268266
269267 const reviews = await this . remoteDB . allDocs < ScheduledCard > ( {
270268 startkey : keys . startkey ,
@@ -359,7 +357,7 @@ Currently logged-in as ${this._username}.`
359357 }
360358
361359 private async getReviewstoDate ( targetDate : Moment , course_id ?: string ) {
362- const keys = getStartAndEndKeys ( REVIEW_PREFIX ) ;
360+ const keys = getStartAndEndKeys ( DocTypePrefixes [ DocType . SCHEDULED_CARD ] ) ;
363361
364362 const reviews = await this . remoteDB . allDocs < ScheduledCard > ( {
365363 startkey : keys . startkey ,
@@ -374,8 +372,11 @@ Currently logged-in as ${this._username}.`
374372 ) ;
375373 return reviews . rows
376374 . filter ( ( r ) => {
377- if ( r . id . startsWith ( REVIEW_PREFIX ) ) {
378- const date = moment . utc ( r . id . substr ( REVIEW_PREFIX . length ) , REVIEW_TIME_FORMAT ) ;
375+ if ( r . id . startsWith ( DocTypePrefixes [ DocType . SCHEDULED_CARD ] ) ) {
376+ const date = moment . utc (
377+ r . id . substr ( DocTypePrefixes [ DocType . SCHEDULED_CARD ] . length ) ,
378+ REVIEW_TIME_FORMAT
379+ ) ;
379380 if ( targetDate . isAfter ( date ) ) {
380381 if ( course_id === undefined || r . doc ! . courseId === course_id ) {
381382 return true ;
@@ -816,7 +817,7 @@ Currently logged-in as ${this._username}.`
816817 * @param course_id optional specification of individual course
817818 */
818819 async getSeenCards ( course_id ?: string ) {
819- let prefix = cardHistoryPrefix ;
820+ let prefix = DocTypePrefixes [ DocType . CARDRECORD ] ;
820821 if ( course_id ) {
821822 prefix += course_id ;
822823 }
@@ -826,8 +827,8 @@ Currently logged-in as ${this._username}.`
826827 // const docs = await this.localDB.allDocs({});
827828 const ret : PouchDB . Core . DocumentId [ ] = [ ] ;
828829 docs . rows . forEach ( ( row ) => {
829- if ( row . id . startsWith ( cardHistoryPrefix ) ) {
830- ret . push ( row . id . substr ( cardHistoryPrefix . length ) ) ;
830+ if ( row . id . startsWith ( DocTypePrefixes [ DocType . CARDRECORD ] ) ) {
831+ ret . push ( row . id . substr ( DocTypePrefixes [ DocType . CARDRECORD ] . length ) ) ;
831832 }
832833 } ) ;
833834 return ret ;
@@ -840,7 +841,7 @@ Currently logged-in as ${this._username}.`
840841 async getHistory ( ) {
841842 const cards = await filterAllDocsByPrefix < CardHistory < CardRecord > > (
842843 this . remoteDB ,
843- cardHistoryPrefix ,
844+ DocTypePrefixes [ DocType . CARDRECORD ] ,
844845 {
845846 include_docs : true ,
846847 attachments : false ,
0 commit comments