Skip to content

Commit

Permalink
Aftral[premieroctet#90]: filter resources by achievement status
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Aug 9, 2024
1 parent 94eefb5 commit a8e03ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/web/server/plugins/aftral-lms/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Program = require('../../models/Program')
const Chapter = require('../../models/Chapter')
const Module = require('../../models/Module')
const Sequence = require('../../models/Sequence')
const { BLOCK_STATUS_CURRENT } = require('./consts')

const getRelatedDocuments = async (Model, ids) => {
return await Model.find({ _id: { $in: ids } }).populate('children')
Expand Down Expand Up @@ -39,8 +40,7 @@ const getTraineeResources = async (userId, params, data) => {
const sequences = await getRelatedDocuments(Sequence, sequenceIds)

const resourceIds = getIdsFromChildren(sequences)
const resources = await Resource.find({ _id: { $in: resourceIds } })

const resources = await Resource.find({ _id: { $in: resourceIds }, achievement_status: BLOCK_STATUS_CURRENT })
return resources
}

Expand Down
18 changes: 11 additions & 7 deletions backend/web/tests/aftral-lms/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Sequence = require('../../server/models/Sequence')
const Module = require('../../server/models/Module')
const Program = require('../../server/models/Program')
const Session = require('../../server/models/Session')
const { ROLE_APPRENANT, ROLE_FORMATEUR, RESOURCE_TYPE_PDF, ACHIEVEMENT_RULE_CHECK, ACHIEVEMENT_RULE_SUCCESS, ACHIEVEMENT_RULE_CONSULT, RESOURCE_TYPE_VIDEO, ACHIEVEMENT_RULE_DOWNLOAD, ROLE_CONCEPTEUR } = require('../../server/plugins/aftral-lms/consts')
const { ROLE_APPRENANT, ROLE_FORMATEUR, RESOURCE_TYPE_PDF, ACHIEVEMENT_RULE_CHECK, ACHIEVEMENT_RULE_SUCCESS, ACHIEVEMENT_RULE_CONSULT, RESOURCE_TYPE_VIDEO, ACHIEVEMENT_RULE_DOWNLOAD, ROLE_CONCEPTEUR, BLOCK_STATUS_CURRENT, BLOCK_STATUS_FINISHED, BLOCK_STATUS_UNAVAILABLE } = require('../../server/plugins/aftral-lms/consts')
const ProductCode = require('../../server/models/ProductCode')
const { addChildAction } = require('../../server/plugins/aftral-lms/actions')
const { getBlockResources } = require('../../server/plugins/aftral-lms/resources')
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('User', () => {
creator: trainer._id,
start_date: new Date(),
end_date: new Date('2025-07-07'),
trainees:[trainee._id]
trainees:[trainee._id],
})

productCode = await ProductCode.create({code: 'Product Code Test'})
Expand Down Expand Up @@ -98,7 +98,8 @@ describe('User', () => {
resource_type: RESOURCE_TYPE_VIDEO,
creator: trainer._id,
url: `hi.pdf`,
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD,
achievement_status: BLOCK_STATUS_UNAVAILABLE
})

resource2 = await Block.create({
Expand All @@ -107,7 +108,8 @@ describe('User', () => {
resource_type: RESOURCE_TYPE_VIDEO,
creator: trainer._id,
url: `hi.pdf`,
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD,
achievement_status: BLOCK_STATUS_CURRENT
})

resource3 = await Block.create({
Expand All @@ -116,7 +118,8 @@ describe('User', () => {
resource_type: RESOURCE_TYPE_VIDEO,
creator: trainer._id,
url: `hi.pdf`,
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD,
achievement_status: BLOCK_STATUS_CURRENT
})

resource4 = await Block.create({
Expand All @@ -125,7 +128,8 @@ describe('User', () => {
resource_type: RESOURCE_TYPE_VIDEO,
creator: trainer._id,
url: `hi.pdf`,
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD
achievement_rule: ACHIEVEMENT_RULE_DOWNLOAD,
achievement_status: BLOCK_STATUS_FINISHED
})

await addChildAction({parent: session._id, child: program._id}, conceptor)
Expand Down Expand Up @@ -156,6 +160,6 @@ describe('User', () => {

it(`it must user's resources`, async () => {
const [u] = await loadFromDb({model:'user', fields:['resources'], id:trainee._id})
expect(u.resources.length).toEqual(4)
expect(u.resources.length).toEqual(2)
})
})

0 comments on commit a8e03ff

Please sign in to comment.