Skip to content

Commit

Permalink
L&E - change lesson interval (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Pedro da Silva committed May 8, 2023
1 parent 9dab93d commit 27ddbf4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/core/src/services/learnAndEarn/answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,33 @@ export async function answer(
try {
const daysAgo = new Date();
daysAgo.setDate(daysAgo.getDate() - config.intervalBetweenLessons);

const lessonRegistry = await models.learnAndEarnLesson.findOne({
attributes: ['levelId'],
where: {
id: lessonId,
},
});

if (!lessonRegistry) {
throw new BaseError(
'LESSON_NOT_FOUND',
'lesson not found for the given id'
);
}

// check if already completed a lesson today
const concludedLessons = await models.learnAndEarnUserLesson.count({
include: [
{
model: models.learnAndEarnLesson,
as: 'lesson',
required: true,
where: {
levelId: lessonRegistry.levelId,
},
},
],
where: {
completionDate: {
[Op.gte]: daysAgo.setHours(0, 0, 0, 0),
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/services/learnAndEarn/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ export async function listLessons(userId: number, levelId: number) {
const daysAgo = new Date();
daysAgo.setDate(daysAgo.getDate() - config.intervalBetweenLessons);
const completedToday = await models.learnAndEarnUserLesson.count({
include: [
{
model: models.learnAndEarnLesson,
as: 'lesson',
required: true,
where: {
levelId,
},
},
],
where: {
completionDate: {
[Op.gte]: daysAgo.setHours(0, 0, 0, 0),
Expand Down

0 comments on commit 27ddbf4

Please sign in to comment.