Skip to content

Commit

Permalink
Aftral[premieroctet#111]: added evaluation resources to session
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Sep 4, 2024
1 parent 02b99c7 commit 79f6845
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/web/server/plugins/aftral-lms/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,5 @@ module.exports={
ACHIEVEMENT_RULE, ACHIEVEMENT_RULE_SUCCESS, ACHIEVEMENT_RULE_CONSULT, ACHIEVEMENT_RULE_DOWNLOAD,
SCALE, RESOURCE_TYPE_EXT, RESOURCE_TYPE_LINK, DEFAULT_ACHIEVEMENT_RULE, AVAILABLE_ACHIEVEMENT_RULES,
ACHIEVEMENT_RULE_CHECK, DURATION_UNIT, TICKET_TAG, TICKET_STATUS, TICKET_STATUS_NOT_TREATED,
PERMISSIONS,
PERMISSIONS, SCALE_NOT_ACQUIRED
}
2 changes: 2 additions & 0 deletions backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const SessionConversation = require('../../models/SessionConversation')
const { getUserPermissions } = require('./user')
const Search = require('../../models/Search')
const Conversation = require('../../models/Conversation')
const { getEvalResources } = require('./session')

const GENERAL_FEED_ID='FFFFFFFFFFFFFFFFFFFFFFFF'

Expand Down Expand Up @@ -218,6 +219,7 @@ CONVERSATION_MODELS.forEach(model => {

// Session start
declareComputedField({model: 'session', field: 'conversations', getterFn: getSessionConversations})
declareComputedField({model: 'session', field: 'evaluation_resources', getterFn: getEvalResources})
// Session end

const preCreate = async ({model, params, user}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const SessionSchema = new Schema({
default: [],
},
// Computed
resources: {
evaluation_resources: {
type: [{
type: Schema.Types.ObjectId,
ref: `block`,
Expand Down
32 changes: 27 additions & 5 deletions backend/web/server/plugins/aftral-lms/session.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import { getBlockResources } from "./resources"
const Resource = require("../../models/Resource")
const Session = require("../../models/Session")
const User = require("../../models/User")
const { loadFromDb } = require("../../utils/database")
const { getBlockResources } = require("./resources")

const getEvalResources = async (userId, params, data) => {
const resources = await getBlockResources (userId, params, data)
console.log(resources)
const getEvalResources = async (userId, params, data, fields) => {
const resourceIds = await getBlockResources(data._id)
const newParams = {
[`filter._id`]: {$in: resourceIds},
}
const user = await User.findById(userId)

let resources = await loadFromDb({
model: `resource`,
user,
fields: [...fields, `note`, `scale`, `homework_mode`],
params: newParams
})

resources = resources.filter(r =>
r.homework_mode == true || (r.note !== undefined && r.note !== null) || (r.scale !== undefined && r.scale !== null)
)

return resources.map(r => new Resource(r))
}

module.exports()
module.exports = {
getEvalResources
}
82 changes: 76 additions & 6 deletions backend/web/tests/aftral-lms/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Session = require('../../server/models/Session')
require('../../server/models/Certification')
require('../../server/models/Permission')
require('../../server/models/PermissionGroup')
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, ACHIEVEMENT_RULE } = 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, ACHIEVEMENT_RULE, RESOURCE_TYPE, SCALE, SCALE_NOT_ACQUIRED } = require('../../server/plugins/aftral-lms/consts')
const Block = require('../../server/models/Block')
const Homework = require('../../server/models/Homework')
const Progress = require('../../server/models/Progress')
Expand All @@ -23,6 +23,7 @@ jest.setTimeout(60000)

describe('User', () => {
let trainer, trainee1, trainee2, homework1, homework2, block, progress1, progress2, sequence, modulee, program, session, productCode, conceptor, id
let block2, block3, block4, block5
let limit = new Date('06-06-2025')
let sequenceId
beforeAll(async () => {
Expand Down Expand Up @@ -55,6 +56,7 @@ describe('User', () => {
password: `Test`,
email: `t@t.com`,
})

block = await Block.create({
name: `Res`,
type: `resource`,
Expand All @@ -67,6 +69,61 @@ describe('User', () => {
success_note_min:0,
success_note_max: 20,
})

block2 = await Block.create({
name: `Res2`,
type: `resource`,
resource_type:RESOURCE_TYPE_PDF,
url: `test`,
achievement_rule:ACHIEVEMENT_RULE_CONSULT,
creator: trainer._id,
homework_limit_date: limit,
homework_mode: false,
success_note_min:0,
success_note_max: 20,
})

block3 = await Block.create({
name: `Res3`,
type: `resource`,
resource_type:RESOURCE_TYPE_PDF,
url: `test`,
achievement_rule:ACHIEVEMENT_RULE_CONSULT,
creator: trainer._id,
homework_limit_date: limit,
homework_mode: false,
success_note_min:0,
success_note_max: 20,
scale: SCALE_NOT_ACQUIRED,
})

block4 = await Block.create({
name: `Res4`,
type: `resource`,
resource_type:RESOURCE_TYPE_PDF,
url: `test`,
achievement_rule:ACHIEVEMENT_RULE_CONSULT,
creator: trainer._id,
homework_limit_date: limit,
homework_mode: false,
success_note_min:0,
success_note_max: 20,
note: 20
})

block5 = await Block.create({
name: `Res5`,
type: `resource`,
resource_type:RESOURCE_TYPE_PDF,
url: `test`,
achievement_rule:ACHIEVEMENT_RULE_CONSULT,
creator: trainer._id,
homework_limit_date: limit,
homework_mode: false,
success_note_min:0,
success_note_max: 20,
})

homework1 = await Homework.create({
document: `t`,
resource: block._id,
Expand All @@ -82,7 +139,8 @@ describe('User', () => {
creator: trainer._id,
start_date: new Date(`10-10-2024`),
end_date: new Date(`10-10-2025`),
trainees:[trainee1._id, trainee2._id]
trainees:[trainee1._id, trainee2._id],
code: `test`,
})
productCode = await ProductCode.create({code:`Test product code`})
program = await Program.create({
Expand All @@ -99,10 +157,14 @@ describe('User', () => {
creator: trainer._id
})

await addChildAction({parent: session._id, child: program._id}, conceptor)
await addChildAction({parent: program._id, child: modulee._id}, conceptor)
await addChildAction({parent: modulee._id, child: sequence._id}, conceptor)
await addChildAction({parent: sequence._id, child: block._id}, conceptor)
await addChildAction({parent: sequence._id, child: block2._id}, conceptor)
await addChildAction({parent: sequence._id, child: block3._id}, conceptor)
await addChildAction({parent: sequence._id, child: block4._id}, conceptor)
await addChildAction({parent: sequence._id, child: block5._id}, conceptor)
await addChildAction({parent: modulee._id, child: sequence._id}, conceptor)
await addChildAction({parent: program._id, child: modulee._id}, conceptor)
await addChildAction({parent: session._id, child: program._id}, conceptor)

const [ses] = await loadFromDb({model: `session`, user:conceptor, fields:[`children.children.children.children`]})
id = ses.children[0].children[0].children[0].children[0]._id
Expand Down Expand Up @@ -186,7 +248,7 @@ describe('User', () => {
expect(error).toBeDefined()
})

it.only(`must accept achievement rule success for all resource types`, async () => {
it(`must accept achievement rule success for all resource types`, async () => {
let error
try{
for(let type in RESOURCE_TYPE) {
Expand All @@ -208,4 +270,12 @@ describe('User', () => {
expect(error).not.toBeTruthy()
})

it.only(`must return resources on session`, async () => {
const [session] = await loadFromDb({
model: `session`,
user: trainer,
fields: [`evaluation_resources.name`]
})
expect(session.evaluation_resources.length).toEqual(3)
})
})

0 comments on commit 79f6845

Please sign in to comment.