adapt-authoring-courseassets 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/courseassetsModule.js +19 -7
- package/package.json +1 -1
|
@@ -68,20 +68,32 @@ class CourseAssetsModule extends AbstractApiModule {
|
|
|
68
68
|
if (!contentId || !courseId) {
|
|
69
69
|
return
|
|
70
70
|
}
|
|
71
|
-
// delete any existing course assets for content
|
|
72
|
-
await this.deleteMany({ courseId, contentId })
|
|
73
|
-
|
|
74
71
|
const data = isModify ? arg2 : arg1
|
|
75
72
|
const schema = await this.content.getSchema(this.content.schemaName, data)
|
|
76
73
|
const ids = extractAssetIds(schema.built.properties, data)
|
|
77
74
|
|
|
75
|
+
if (isModify) {
|
|
76
|
+
const existing = await this.find({ courseId, contentId })
|
|
77
|
+
const existingIds = existing.map(r => r.assetId.toString()).sort()
|
|
78
|
+
if (ids.length === existingIds.length && ids.slice().sort().every((id, i) => id === existingIds[i])) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// delete any existing course assets for content
|
|
83
|
+
await this.deleteMany({ courseId, contentId })
|
|
84
|
+
|
|
78
85
|
if (!ids.length) {
|
|
79
86
|
return
|
|
80
87
|
}
|
|
81
|
-
await
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
const found = await this.assets.find({ _id: { $in: ids } })
|
|
89
|
+
const foundIds = new Set(found.map(a => a._id.toString()))
|
|
90
|
+
const validIds = ids.filter(id => foundIds.has(id))
|
|
91
|
+
|
|
92
|
+
if (validIds.length) {
|
|
93
|
+
const mongodb = await this.app.waitForModule('mongodb')
|
|
94
|
+
const docs = validIds.map(assetId => ({ courseId, contentId, assetId }))
|
|
95
|
+
await mongodb.getCollection(this.collectionName).insertMany(docs)
|
|
96
|
+
}
|
|
85
97
|
this.log('debug', 'UPDATE', courseId, contentId)
|
|
86
98
|
}
|
|
87
99
|
|
package/package.json
CHANGED