I have this method using Loopback(Node.Js framework) to return a JSON composed of MP3 and videos.
This is the code I have so far
let names = await app.models.cm_comediens.getValue();
let sonMp3 = await app.models.cm_comediens.getMp3ById(id);
const mp3 = sonMp3.map(id => {
let mappedObj = {}
Object.keys(id).forEach( async (key)=> {
let medias = await app.models.cm_comediens_medias.find({ where: {idMedia: id[key].idMedia}} )
mappedObj[key] = {
"Titre": medias.map(person => person.intitule ).toString(),
"Filename": medias.map(person => person.filename ).toString(),
"Langue": names.find(y => y.idValue === id[key].qfLangue).fr,
"Type": names.find(y => y.idValue === id[key].qfType).fr,
"Description": id[key].description,
"Intention1": names.find(y => y.idValue === id[key].qfInterpretation1).fr,
"Intention2": names.find(y => y.idValue === id[key].qfInterpretation2).fr,
"Intention3": names.find(y => y.idValue === id[key].qfInterpretation3).fr,
}
});
return mappedObj;
});
let video = await app.models.cm_comediens.getVideoById(id);
const videoss = video.map(id => {
let mappedObj = {}
Object.keys(id).forEach( async (key)=> {
let medias = await app.models.cm_comediens_medias.find({ where: {idMedia: id[key].idMedia}} )
mappedObj[key] = {
"Titre": medias.map(person => person.intitule ).toString(),
"Filename": medias.map(person => person.filename ).toString(),
"Langue": names.find(y => y.idValue === id[key].qfLangue).fr,
"Type": names.find(y => y.idValue === id[key].qfType).fr,
"Description": id[key].description,
"Intention1": names.find(y => y.idValue === id[key].qfInterpretation1).fr,
"Intention2": names.find(y => y.idValue === id[key].qfInterpretation2).fr,
"Intention3": names.find(y => y.idValue === id[key].qfInterpretation3).fr,
}
});
return mappedObj;
});
result.mp3=mp3;
result.video=videoss;
var resultfinal = [result]
return resultfinal;
The problem is when I run it it returns this :
when I remove let medias = await app.models.cm_comediens_medias.find({ where: {idMedia: id[key].idMedia}} )
and the "Titre" and "FileName" elements from video everything works fine and the results are shown correctly for videos also.Also, when I do a console.log(medias) the results are there like this :
[ { idMedia: 42085,
idComedien: 1426,
intitule: 'Tale of us Distante',
typeMedia: 'video',
filename: 'http://localhost:3000/Who Loves The Sun (Original Mix).mp4',
originalFilename: 'Who Loves The Sun (Original Mix).mp4',
triComedien: 0,
timestampCreation: 2019-06-13T10:56:03.000Z,
timestampModification: 2019-06-13T10:56:03.000Z } ]
(node:13280) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated
[ { idMedia: 42087,
idComedien: 1426,
intitule: 'cxwccw',
typeMedia: 'video',
filename: 'http://localhost:3000/Who Loves The Sun (Original Mix).mp4',
originalFilename: 'Who Loves The Sun (Original Mix).mp4',
triComedien: 0,
timestampCreation: 2019-06-13T11:15:11.000Z,
timestampModification: 2019-06-13T11:15:11.000Z } ]
so I don't know exactly what's wrong. Is it because I am calling the same function twice ?? any help would be appreciated. Thank you