add stream

This commit is contained in:
Chris Grimmett 2023-12-04 09:39:01 -08:00
parent e8b097f637
commit a15b2e9648
1 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,50 @@
const { ArchiveStatus } = require("@aws-sdk/client-s3");
module.exports = {
async afterUpdate(event) {
console.log(`>>>>>>>>>>>>>> STREAM is beforeUpdate !!!!!!!!!!!!`);
const { data, where, select, populate } = event.params;
console.log(data);
const id = where.id;
// greets https://forum.strapi.io/t/how-to-get-previous-component-data-in-lifecycle-hook/25892/4?u=ggr247
const existingData = await strapi.entityService.findOne("api::stream.stream", id, {
populate: ['vods']
})
// Initialize archiveStatus to a default value
let archiveStatus = 'missing';
// Iterate through all vods to determine archiveStatus
for (const vod of existingData.vods) {
if (!!vod.videoSrcHash) {
if (!!vod.note) {
// If a vod has both videoSrcHash and note, set archiveStatus to 'issue'
archiveStatus = 'issue';
break; // No need to check further
} else {
// If a vod has videoSrcHash but no note, set archiveStatus to 'good'
archiveStatus = 'good';
}
}
}
console.log(`archiveStatus=${archiveStatus}`);
// we can't use query engine here, because that would trigger an infinite loop
// where this
// instead we access knex instance
const update = await strapi.db.connection("streams").where({id: id}).update({archive_status: archiveStatus});
console.log(update)
// await strapi.db.query('api::stream.stream').update({
// where: { id },
// data: {
// archiveStatus
// }
// });
}
};