forked from premieroctet/openchakra
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aftral: [premieroctet#90] Trainee current resources
- Loading branch information
1 parent
d7d7518
commit 5cc79fd
Showing
7 changed files
with
28 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,19 @@ | ||
const Progress = require('../../models/Progress') | ||
const Resource = require('../../models/Resource') | ||
const { loadFromDb } = require('../../utils/database') | ||
const { BLOCK_STATUS_CURRENT } = require('./consts') | ||
|
||
const getTraineeResources = async (userId, params, data) => { | ||
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 | ||
) | ||
} | ||
}) | ||
) | ||
) | ||
|
||
return resources | ||
const getTraineeCurrentResources = async (userId, params, data, fields) => { | ||
// Find curent blocks for this user | ||
let userCurrentBlockIds=await Progress.find({user: userId, achievement_status: BLOCK_STATUS_CURRENT}) | ||
userCurrentBlockIds=userCurrentBlockIds.map(p => p.block._id) | ||
let resources = await loadFromDb({ | ||
model: 'resource', fields, params: {'filter._id': {$in: userCurrentBlockIds}} | ||
}) | ||
return resources.map(r => new Resource(r)) | ||
} | ||
|
||
|
||
module.exports = { | ||
getTraineeResources | ||
getTraineeCurrentResources,getTraineeCurrentResources | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,5 @@ | |
}, | ||
"devDependencies": { | ||
"@types/mime": "^3.0.1" | ||
}, | ||
"packageManager": "yarn@3.6.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,5 @@ | |
"eslint src/**/*.{ts,tsx} --fix", | ||
"git add" | ||
] | ||
}, | ||
"packageManager": "yarn@3.6.4" | ||
} | ||
} |