Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L&E - change lesson interval #579

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -215,6 +215,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