Skip to content
Merged
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
19 changes: 17 additions & 2 deletions packages/server/src/tag/services/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export class TagService {
study: study._id,
complete: false,
order,
enabled: enabled
enabled: enabled,
training: false
});
}
}
Expand All @@ -222,7 +223,21 @@ export class TagService {
}

private async getIncomplete(study: Study, user: string): Promise<Tag | null> {
return this.tagModel.findOne({ study: study._id, user, complete: false, enabled: true });
const incomplete = await this.tagModel.findOne({ study: study._id, user, complete: false });

// If no incomplete tag, return null
if (!incomplete) {
return incomplete;
}

// Make sure the tag is still enabled, otherwise remove the user association and return null
if (!incomplete.enabled) {
await this.tagModel.updateOne({ _id: incomplete._id }, { $unset: { user: '' } });
return null;
}

// Otherwise, there is a tag that the user should complete
return incomplete;
}

private async removeByStudy(study: Study): Promise<void> {
Expand Down