czapp-shared 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -151,10 +151,10 @@ interface ILexemePair {
151
151
  dateAdded: MySQLDate;
152
152
  englishLexeme: ILexeme;
153
153
  familiarity: Familiarity;
154
- firstKnownSessionDigit: number | null;
155
- lastFlashcardReview: MySQLDate | null;
156
- lastModified: MySQLDate;
157
- lastTested: MySQLDate | null;
154
+ firstKnownSessionDigit?: number;
155
+ lastFlashcardReview?: MySQLDate;
156
+ lastModified?: MySQLDate;
157
+ lastTested?: MySQLDate;
158
158
  learningStage: LearningStage;
159
159
  notes: string;
160
160
  userId: string;
@@ -193,10 +193,10 @@ declare class LexemePair implements ILexemePair {
193
193
  dateAdded: MySQLDate;
194
194
  englishLexeme: ILexeme;
195
195
  familiarity: Familiarity;
196
- firstKnownSessionDigit: number | null;
197
- lastFlashcardReview: MySQLDate;
198
- lastModified: MySQLDate;
199
- lastTested: MySQLDate;
196
+ firstKnownSessionDigit?: number;
197
+ lastFlashcardReview?: MySQLDate;
198
+ lastModified?: MySQLDate;
199
+ lastTested?: MySQLDate;
200
200
  learningStage: LearningStage;
201
201
  notes: string;
202
202
  userId: string;
package/dist/index.d.ts CHANGED
@@ -151,10 +151,10 @@ interface ILexemePair {
151
151
  dateAdded: MySQLDate;
152
152
  englishLexeme: ILexeme;
153
153
  familiarity: Familiarity;
154
- firstKnownSessionDigit: number | null;
155
- lastFlashcardReview: MySQLDate | null;
156
- lastModified: MySQLDate;
157
- lastTested: MySQLDate | null;
154
+ firstKnownSessionDigit?: number;
155
+ lastFlashcardReview?: MySQLDate;
156
+ lastModified?: MySQLDate;
157
+ lastTested?: MySQLDate;
158
158
  learningStage: LearningStage;
159
159
  notes: string;
160
160
  userId: string;
@@ -193,10 +193,10 @@ declare class LexemePair implements ILexemePair {
193
193
  dateAdded: MySQLDate;
194
194
  englishLexeme: ILexeme;
195
195
  familiarity: Familiarity;
196
- firstKnownSessionDigit: number | null;
197
- lastFlashcardReview: MySQLDate;
198
- lastModified: MySQLDate;
199
- lastTested: MySQLDate;
196
+ firstKnownSessionDigit?: number;
197
+ lastFlashcardReview?: MySQLDate;
198
+ lastModified?: MySQLDate;
199
+ lastTested?: MySQLDate;
200
200
  learningStage: LearningStage;
201
201
  notes: string;
202
202
  userId: string;
package/dist/index.js CHANGED
@@ -208,6 +208,7 @@ var LexemePair = class {
208
208
  this.userId = userId;
209
209
  this.czechLexeme = czechLexeme;
210
210
  this.englishLexeme = englishLexeme;
211
+ this.dateAdded = getMysqlDateIgnoreTZ(/* @__PURE__ */ new Date());
211
212
  }
212
213
  };
213
214
 
@@ -227,7 +228,10 @@ var deriveStreakFromVocabCheckActivity = (activity, today) => {
227
228
  let flashcardStreak = 0;
228
229
  let testStreak = 0;
229
230
  const sortedActivity = activity.sort((a, b) => a.testDate < b.testDate ? 1 : -1);
230
- let currentDate = today;
231
+ const todayRecord = sortedActivity.find((record) => record.testDate === today);
232
+ const yesterdaysDateObj = new Date(today);
233
+ yesterdaysDateObj.setDate(yesterdaysDateObj.getDate() - 1);
234
+ let currentDate = yesterdaysDateObj.toISOString().split("T")[0];
231
235
  for (const record of sortedActivity) {
232
236
  if (record.flashcardCount > 0) {
233
237
  if (record.testDate === currentDate) {
@@ -240,7 +244,10 @@ var deriveStreakFromVocabCheckActivity = (activity, today) => {
240
244
  }
241
245
  }
242
246
  }
243
- currentDate = today;
247
+ if (todayRecord && todayRecord.flashcardCount > 0) {
248
+ flashcardStreak++;
249
+ }
250
+ currentDate = yesterdaysDateObj.toISOString().split("T")[0];
244
251
  for (const record of sortedActivity) {
245
252
  if (record.testQuestionCount > 0) {
246
253
  if (record.testDate === currentDate) {
@@ -253,6 +260,9 @@ var deriveStreakFromVocabCheckActivity = (activity, today) => {
253
260
  }
254
261
  }
255
262
  }
263
+ if (todayRecord && todayRecord.testQuestionCount > 0) {
264
+ testStreak++;
265
+ }
256
266
  return { flashcardStreak, testStreak };
257
267
  };
258
268
 
package/dist/index.mjs CHANGED
@@ -157,6 +157,7 @@ var LexemePair = class {
157
157
  this.userId = userId;
158
158
  this.czechLexeme = czechLexeme;
159
159
  this.englishLexeme = englishLexeme;
160
+ this.dateAdded = getMysqlDateIgnoreTZ(/* @__PURE__ */ new Date());
160
161
  }
161
162
  };
162
163
 
@@ -176,7 +177,10 @@ var deriveStreakFromVocabCheckActivity = (activity, today) => {
176
177
  let flashcardStreak = 0;
177
178
  let testStreak = 0;
178
179
  const sortedActivity = activity.sort((a, b) => a.testDate < b.testDate ? 1 : -1);
179
- let currentDate = today;
180
+ const todayRecord = sortedActivity.find((record) => record.testDate === today);
181
+ const yesterdaysDateObj = new Date(today);
182
+ yesterdaysDateObj.setDate(yesterdaysDateObj.getDate() - 1);
183
+ let currentDate = yesterdaysDateObj.toISOString().split("T")[0];
180
184
  for (const record of sortedActivity) {
181
185
  if (record.flashcardCount > 0) {
182
186
  if (record.testDate === currentDate) {
@@ -189,7 +193,10 @@ var deriveStreakFromVocabCheckActivity = (activity, today) => {
189
193
  }
190
194
  }
191
195
  }
192
- currentDate = today;
196
+ if (todayRecord && todayRecord.flashcardCount > 0) {
197
+ flashcardStreak++;
198
+ }
199
+ currentDate = yesterdaysDateObj.toISOString().split("T")[0];
193
200
  for (const record of sortedActivity) {
194
201
  if (record.testQuestionCount > 0) {
195
202
  if (record.testDate === currentDate) {
@@ -202,6 +209,9 @@ var deriveStreakFromVocabCheckActivity = (activity, today) => {
202
209
  }
203
210
  }
204
211
  }
212
+ if (todayRecord && todayRecord.testQuestionCount > 0) {
213
+ testStreak++;
214
+ }
205
215
  return { flashcardStreak, testStreak };
206
216
  };
207
217
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "czapp-shared",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "This is a shared library for Czapp projects. It contains common code that is used across multiple projects.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -18,10 +18,10 @@ export class LexemePair implements ILexemePair {
18
18
  dateAdded: MySQLDate;
19
19
  englishLexeme: ILexeme;
20
20
  familiarity: Familiarity = Familiarity.UNKNOWN;
21
- firstKnownSessionDigit: number | null;
22
- lastFlashcardReview: MySQLDate;
23
- lastModified: MySQLDate;
24
- lastTested: MySQLDate;
21
+ firstKnownSessionDigit?: number;
22
+ lastFlashcardReview?: MySQLDate;
23
+ lastModified?: MySQLDate;
24
+ lastTested?: MySQLDate;
25
25
  learningStage: LearningStage = LearningStage.NEW;
26
26
  notes: string = "";
27
27
  userId: string = "";
@@ -30,5 +30,6 @@ export class LexemePair implements ILexemePair {
30
30
  this.userId = userId;
31
31
  this.czechLexeme = czechLexeme;
32
32
  this.englishLexeme = englishLexeme;
33
+ this.dateAdded = getMysqlDateIgnoreTZ(new Date())!;
33
34
  }
34
35
  }
@@ -12,9 +12,13 @@ export const deriveStreakFromVocabCheckActivity = (activity: IVocabCheckActivity
12
12
 
13
13
  // Sort activity by date descending
14
14
  const sortedActivity = activity.sort((a, b) => (a.testDate < b.testDate ? 1 : -1));
15
+ const todayRecord = sortedActivity.find(record => record.testDate === today);
15
16
 
16
17
  // Derive flashcard streak
17
- let currentDate = today;
18
+ // starting from yesterday, check each day if there was activity
19
+ const yesterdaysDateObj = new Date(today);
20
+ yesterdaysDateObj.setDate(yesterdaysDateObj.getDate() - 1);
21
+ let currentDate = yesterdaysDateObj.toISOString().split('T')[0] as DateString;
18
22
  for (const record of sortedActivity) {
19
23
  if (record.flashcardCount > 0) {
20
24
  if (record.testDate === currentDate) {
@@ -29,9 +33,15 @@ export const deriveStreakFromVocabCheckActivity = (activity: IVocabCheckActivity
29
33
  }
30
34
  }
31
35
  }
36
+ // finally, if there were flashcards done today, add one to the streak
37
+ if (todayRecord && todayRecord.flashcardCount > 0) {
38
+ flashcardStreak++;
39
+ }
40
+
41
+ // Derive test streak
32
42
 
33
- // Reset currentDate for test streak calculation
34
- currentDate = today;
43
+ // Reset currentDate for test streak calculation to yesterday
44
+ currentDate = yesterdaysDateObj.toISOString().split('T')[0] as DateString;
35
45
  for (const record of sortedActivity) {
36
46
  if (record.testQuestionCount > 0) {
37
47
  if (record.testDate === currentDate) {
@@ -46,6 +56,10 @@ export const deriveStreakFromVocabCheckActivity = (activity: IVocabCheckActivity
46
56
  }
47
57
  }
48
58
  }
59
+ // finally, if there were flashcards done today, add one to the streak
60
+ if (todayRecord && todayRecord.testQuestionCount > 0) {
61
+ testStreak++;
62
+ }
49
63
 
50
64
  return { flashcardStreak, testStreak };
51
65
 
@@ -12,10 +12,10 @@ export interface ILexemePair {
12
12
  dateAdded: MySQLDate;
13
13
  englishLexeme: ILexeme;
14
14
  familiarity: Familiarity;
15
- firstKnownSessionDigit: number | null,
16
- lastFlashcardReview: MySQLDate | null,
17
- lastModified: MySQLDate;
18
- lastTested: MySQLDate | null;
15
+ firstKnownSessionDigit?: number,
16
+ lastFlashcardReview?: MySQLDate,
17
+ lastModified?: MySQLDate;
18
+ lastTested?: MySQLDate;
19
19
  learningStage: LearningStage,
20
20
  notes: string;
21
21
  userId: string;