Skip to content

Commit

Permalink
Aftral[premieroctet#113]: added trainees_count to block
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Aug 28, 2024
1 parent c9d838c commit 08b7eed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions backend/web/server/plugins/aftral-lms/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,15 @@ const getBlockHomeworks = async (userId, params, data) => {
return progress.homeworks
}

getBlockHomeworksSubmitted = async (userId, params, data) => {
const getBlockHomeworksSubmitted = async (userId, params, data) => {
const progress = await mongoose.models.progress.find({
block:data._id
}).populate('homeworks')
const homeworks = progress.filter(p=> p.homeworks.length>0)
return homeworks.length
}

getBlockHomeworksMissing = async (userId, params, data) => {
const getBlockHomeworksMissing = async (userId, params, data) => {
const session = await mongoose.models.session.findById(data.session)
const progress = await mongoose.models.progress.find({
block:data._id
Expand All @@ -410,12 +410,17 @@ getBlockHomeworksMissing = async (userId, params, data) => {
return result
}

const getBlockTraineesCount = async (userId, params, data) => {
const session = await mongoose.models.session.findById(data.session)
return session.trainees ? session.trainees.length : 0
}

module.exports={
getBlockStatus, getBlockName, getSessionBlocks, setParentSession,
cloneTree, getAttribute, LINKED_ATTRIBUTES, onBlockFinished, onBlockCurrent, onBlockAction,
getNextResource, getPreviousResource, getParentBlocks,LINKED_ATTRIBUTES_CONVERSION,
ChainCache, ATTRIBUTES_CACHE,getSession, getBlockLiked, getBlockDisliked, setBlockLiked, setBlockDisliked,
getAvailableCodes, getBlockHomeworks, getBlockHomeworksSubmitted, getBlockHomeworksMissing
getAvailableCodes, getBlockHomeworks, getBlockHomeworksSubmitted, getBlockHomeworksMissing, getBlockTraineesCount
}


3 changes: 2 additions & 1 deletion backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require('../../models/Chapter') //Added chapter, it was removed somehow
const { computeStatistics } = require('./statistics')
const { searchUsers, searchBlocks } = require('./search')
const { getUserHomeworks, getResourceType, getAchievementRules, getBlockSpentTime, getBlockSpentTimeStr, getResourcesCount, getFinishedResourcesCount, getRessourceSession } = require('./resources')
const { getBlockStatus, setParentSession, getAttribute, LINKED_ATTRIBUTES, onBlockAction, LINKED_ATTRIBUTES_CONVERSION, getSession, getAvailableCodes, getBlockHomeworks, getBlockHomeworksSubmitted, getBlockHomeworksMissing} = require('./block')
const { getBlockStatus, setParentSession, getAttribute, LINKED_ATTRIBUTES, onBlockAction, LINKED_ATTRIBUTES_CONVERSION, getSession, getAvailableCodes, getBlockHomeworks, getBlockHomeworksSubmitted, getBlockHomeworksMissing, getBlockTraineesCount} = require('./block')
const { getResourcesProgress } = require('./resources')
const { getResourceAnnotation } = require('./resources')
const { setResourceAnnotation } = require('./resources')
Expand Down Expand Up @@ -103,6 +103,7 @@ BLOCK_MODELS.forEach(model => {
declareVirtualField({model, field: 'can_upload_homework', type: 'Boolean', requires: 'homework_limit_date,homework_mode'})
declareComputedField({model, field: 'homeworks_submitted_count', type: 'Number', requires: 'session', getterFn: getBlockHomeworksSubmitted})
declareComputedField({model, field: 'homeworks_missing_count', type: 'Number', requires: 'session', getterFn: getBlockHomeworksMissing})
declareComputedField({model, field: 'trainees_count', type: 'Number', requires: 'session', getterFn: getBlockTraineesCount})
})

declareEnumField({model: 'homework', field: 'scale', enumValues: SCALE})
Expand Down
4 changes: 4 additions & 0 deletions backend/web/server/plugins/aftral-lms/schemas/BlockSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ const BlockSchema = new Schema({
type: Number,
required: false,
},
trainees_count: {
type: Number,
required: false,
}
}, {...schemaOptions, ...BLOCK_DISCRIMINATOR})

BlockSchema.virtual('is_template', DUMMY_REF).get(function() {
Expand Down
3 changes: 2 additions & 1 deletion backend/web/tests/aftral-lms/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ describe('User', () => {

it('must return homeworks submitted count', async() => {

const [data] = await loadFromDb({model:`block`, user:conceptor, id, fields:[`session`,`homeworks_missing_count`,`homeworks`,`homeworks_submitted_count`]})
const [data] = await loadFromDb({model:`block`, user:conceptor, id, fields:[`session`,`homeworks_missing_count`,`homeworks`,`homeworks_submitted_count`,`trainees_count`]})
expect(data.homeworks_missing_count).toEqual(0)
expect(data.homeworks_submitted_count).toEqual(2)
expect(data.trainees_count).toEqual(2)
})
})

0 comments on commit 08b7eed

Please sign in to comment.