Skip to content

Instantly share code, notes, and snippets.

@shardiwal
Created July 6, 2020 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shardiwal/d454e0c71333902bbd9a12d569da0c19 to your computer and use it in GitHub Desktop.
Save shardiwal/d454e0c71333902bbd9a12d569da0c19 to your computer and use it in GitHub Desktop.
async findContentTypeVideos(ctx) {
let content = await this.findSingle(ctx);
let videoContentTypes = [];
let units = content.units;
if ( units ) {
units.forEach( async function(unit) {
let unit_content = unit.content;
if ( unit_content ) {
unit_content.forEach(function(uc) {
if ( uc.video_type ) {
console.log('unit_content_push');
videoContentTypes.push( uc.video_type );
}
});
}
let unit_lessons = unit.lessons;
if ( unit_lessons ) {
unit_lessons.forEach(async function(ul) {
let lesson = await strapi.query('lesson').findOne({ id: ul });
let lesson_scenario = lesson.scenario;
if ( lesson_scenario ) {
lesson_scenario.forEach(async function(uls) {
if ( uls.video_type ) {
console.log('lesson_scenario_push');
videoContentTypes.push( uls.video_type );
}
});
}
let lesson_learning_element = lesson.learningElementSection;
if ( lesson_learning_element ) {
lesson_learning_element.forEach(async function(ulle) {
if ( ulle.video_type ) {
console.log('lesson_learning_element_push');
videoContentTypes.push( ulle.video_type );
}
});
}
});
}
let unit_keywords = unit.keywords;
if ( unit_keywords ) {
unit_keywords.forEach(async function(uk) {
let unit_tag = await strapi.query('tag-type').findOne({ id: uk });
let tag_videos = unit_tag.videos;
if ( tag_videos ) {
tag_videos.forEach(async function(tagv) {
console.log('tag keyword push');
videoContentTypes.push( tagv );
});
}
});
}
});
}
console.log( videoContentTypes );
return videoContentTypes;
},
@shardiwal
Copy link
Author

shardiwal commented Jul 6, 2020

Console log below

`
unit_content_push
unit_content_push
[
{
type: 'music',
tags: [ 5f02d5106e6db72eb30e888e ],
_id: 5f02d8d017bdfd33bda51215,
description: 'this is a video ',
videoText: '',
slug: 'first-video',
name: 'First video',
language: {
code: 'nn_NO',
_id: 5f02d8d017bdfd33bda51216,
createdAt: 2020-07-06T07:54:56.140Z,
updatedAt: 2020-07-06T07:54:56.140Z,
__v: 0,
id: '5f02d8d017bdfd33bda51216'
},
license: null,
mediaChapter: [],
closedCaption: null,
cover: null,
createdAt: 2020-07-06T07:54:56.131Z,
updatedAt: 2020-07-06T08:48:34.780Z,
__v: 1,
file: {
_id: 5f02d8c417bdfd33bda51214,
name: 'sample-mp4-file',
alternativeText: '',
caption: '',
hash: 'sample_mp4_file_82afcd81a4',
ext: '.mp4',
mime: 'video/mp4',
size: 10546.62,
url: '/uploads/sample_mp4_file_82afcd81a4.mp4',
provider: 'local',
width: null,
height: null,
related: [Array],
createdAt: 2020-07-06T07:54:44.915Z,
updatedAt: 2020-07-06T07:54:56.161Z,
__v: 0,
id: '5f02d8c417bdfd33bda51214'
},
id: '5f02d8d017bdfd33bda51215'
},
{
type: null,
tags: [ 5f02d5106e6db72eb30e888e ],
_id: 5f02dbcd17bdfd33bda51222,
description: '',
videoText: '',
slug: 'laboratory',
name: 'laboratory',
language: {
code: 'nb_NO',
_id: 5f02dbcd17bdfd33bda51223,
createdAt: 2020-07-06T08:07:41.633Z,
updatedAt: 2020-07-06T08:07:41.633Z,
__v: 0,
id: '5f02dbcd17bdfd33bda51223'
},
license: null,
mediaChapter: [],
closedCaption: null,
cover: null,
createdAt: 2020-07-06T08:07:41.631Z,
updatedAt: 2020-07-06T08:48:34.780Z,
__v: 1,
file: {
_id: 5f02dbc017bdfd33bda51221,
name: '181004_10_LABORATORIES-SCIENCE_11',
alternativeText: '',
caption: '',
hash: '181004_10_LABORATORIES_SCIENCE_11_82fb777c15',
ext: '.mp4',
mime: 'video/mp4',
size: 30344.7,
url: '/uploads/181004_10_LABORATORIES_SCIENCE_11_82fb777c15.mp4',
provider: 'local',
width: null,
height: null,
related: [Array],
createdAt: 2020-07-06T08:07:28.262Z,
updatedAt: 2020-07-06T08:07:41.652Z,
__v: 0,
id: '5f02dbc017bdfd33bda51221'
},
id: '5f02dbcd17bdfd33bda51222'
}
]
[2020-07-06T09:43:03.924Z] debug GET /courses/5efdb2e80e894728e18f6628 (730 ms) 200
tag keyword push
tag keyword push
lesson_scenario_push
lesson_learning_element_push
lesson_learning_element_push

`

@shardiwal
Copy link
Author

shardiwal commented Jul 6, 2020

`
async findContentTypeVideos(ctx) {
let content = await this.findSingle(ctx);
let videoContentTypes = [];
let units = content.units;
if ( units ) {
units.forEach( async function(unit) {
let unit_content = unit.content;
if ( unit_content ) {
unit_content.forEach(function(uc) {
if ( uc.video_type ) {
console.log('unit_content_push');
videoContentTypes.push( uc.video_type );
}
});
}
let unit_lessons = unit.lessons;
if ( unit_lessons ) {
await Promise.all(unit_lessons.map(ul => {
let lesson = await strapi.query('lesson').findOne({ id: ul });
let lesson_scenario = lesson.scenario;
if ( lesson_scenario ) {
lesson_scenario.forEach(async function(uls) {
if ( uls.video_type ) {
console.log('lesson_scenario_push');
videoContentTypes.push( uls.video_type );
}
});
}
let lesson_learning_element = lesson.learningElementSection;
if ( lesson_learning_element ) {
lesson_learning_element.forEach(async function(ulle) {
if ( ulle.video_type ) {
console.log('lesson_learning_element_push');
videoContentTypes.push( ulle.video_type );
}
});
}
}));
}
let unit_keywords = unit.keywords;
if ( unit_keywords ) {
unit_keywords.forEach(async function(uk) {
let unit_tag = await strapi.query('tag-type').findOne({ id: uk });
let tag_videos = unit_tag.videos;
if ( tag_videos ) {
tag_videos.forEach(async function(tagv) {
console.log('tag keyword push');
videoContentTypes.push( tagv );
});
}
});
}
});
}
console.log( videoContentTypes );
return videoContentTypes;
},

`
What's wrong at unit_lessons ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment