Skip to content

Commit

Permalink
Aftral[premieroctet#90]: fixed trainee resources
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Aug 12, 2024
1 parent 626c581 commit 2f2a00b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
1 change: 0 additions & 1 deletion backend/web/server/plugins/aftral-lms/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ const getAttribute = attName => async (userId, params, data) => {
}
return !lodash.isNil(block[attName])
})
console.log(block)
res=block[attName]
ATTRIBUTES_CACHE.set(key, res)
}
Expand Down
41 changes: 33 additions & 8 deletions backend/web/server/plugins/aftral-lms/user.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
const Session = require('../../models/Session')
const { getSessionBlocks } = require('./block')
const { loadFromDb } = require('../../utils/database')

const getTraineeResources = async (userId, params, data) => {
const sessions = await Session.find({ trainees: data._id }).populate('children')
const blocks = await Promise.all(
sessions.map(s => getSessionBlocks(s))
let sessions = await loadFromDb({model: 'session', fields:[
'trainees',
'children.children.children.children.spent_time_str',
'children.children.children.children.name',
'children.children.children.children.resource_type',
'children.children.children.children.achievement_status',
'children.children.children.children.children.spent_time_str',
'children.children.children.children.children.name',
'children.children.children.children.children.resource_type',
'children.children.children.children.children.achievement_status',
], user:data})

sessions = sessions.filter(s => s.trainees.some(t => t._id.toString() === data._id.toString()))

const resources = sessions.flatMap(session =>
session.children.flatMap(program =>
program.children.flatMap(child => {
if (child.type === 'chapter') {
return child.children.flatMap(modulee =>
modulee.children.flatMap(sequence =>
sequence.children
)
)
} else {
return child.children.flatMap(sequence =>
sequence.children
)
}
})
)
)
const resources = blocks.flat().filter(b => b.type == 'resource')
const res = await Promise.all(resources.map(b => loadFromDb({id:b._id, fields:['spent_time_str','name','resource_type','achievement_rule'], model:'resource', user:data})))
return res

console.log(resources)
return resources
}


Expand Down
4 changes: 2 additions & 2 deletions backend/web/tests/aftral-lms/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ describe('User', () => {
await addChildAction({parent: modulee1._id, child: sequence1._id}, conceptor)
await addChildAction({parent: modulee1._id, child: sequence2._id}, conceptor)
await addChildAction({parent: modulee2._id, child: sequence3._id}, conceptor)
await addChildAction({parent: sequence1._id, child: resource1._id}, conceptor)
await addChildAction({parent: sequence1._id, child: resource2._id}, conceptor)
//await addChildAction({parent: sequence1._id, child: resource1._id}, conceptor)
//await addChildAction({parent: sequence1._id, child: resource2._id}, conceptor)
await addChildAction({parent: sequence2._id, child: resource3._id}, conceptor)
await addChildAction({parent: sequence3._id, child: resource4._id}, conceptor)

Expand Down

0 comments on commit 2f2a00b

Please sign in to comment.