Create: async Functions
This commit is contained in:
parent
a874e4f53c
commit
7af7cd85c9
1 changed files with 26 additions and 0 deletions
26
app-backend/config/functions.config.js
Normal file
26
app-backend/config/functions.config.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
const request = require("request");
|
||||||
|
const VideoCategories = require("../models/objects/video.categories.model");
|
||||||
|
|
||||||
|
function asyncRequest(uri, option){
|
||||||
|
return new Promise(function(resolve){
|
||||||
|
request(uri, option,function (error, response, body){
|
||||||
|
resolve({response: response, body: JSON.parse(body)});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
module.exports.asyncRequest = asyncRequest;
|
||||||
|
|
||||||
|
function asyncInterest(interest, source){
|
||||||
|
return new Promise(function(resolve){
|
||||||
|
for(const i in VideoCategories){
|
||||||
|
for(const j in VideoCategories[i].categories){
|
||||||
|
if((VideoCategories[i].categories[j].name === interest || VideoCategories[i].categories[j].id === interest)
|
||||||
|
&& VideoCategories[i].categories[j].source === source){
|
||||||
|
resolve(VideoCategories[i].interest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
module.exports.asyncInterest = asyncInterest;
|
||||||
Reference in a new issue