-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding query,facts,video functions #4
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,49 @@ app.post('/', isAuthenticated ,function(req,response) | |
}); | ||
|
||
exports.signUp = functions.https.onRequest(app); | ||
|
||
|
||
|
||
//<--------Random Fact Generation----------> | ||
//Generates random fact about techspardha. | ||
exports.randomFact = functions.https.onRequest((request , response) => { | ||
const numberOfLines = 8; | ||
const randomIndex = Math.floor(Math.random() * numberOfLines); | ||
database.ref('/facts/' + randomIndex).on('value',function(snapshot){ | ||
console.log(snapshot.val()); | ||
response.status(401).json({ | ||
message : snapshot.val() | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
//<------Returning the array of all the videos------> | ||
//Returns the array of videos containing title and url of a video. | ||
exports.getVideo = functions.https.onRequest((request , response) => { | ||
let items = []; | ||
database.ref('/videos').on('value', function(snapshot) { | ||
snapshot.forEach(function(childSnapshot) { | ||
items.push(childSnapshot.key,{ | ||
title : childSnapshot.val().title, | ||
url : childSnapshot.val().url | ||
}); | ||
}); | ||
}); | ||
response.status(401).json(items); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think directly returning snapshot.val() should work. no need to iterate and make separate object |
||
}); | ||
|
||
|
||
//<-----Adding query to database-------> | ||
//only add newly asked query to the database. | ||
exports.addQuery = functions.https.onRequest((request,response)=>{ | ||
const query = request.query.text; | ||
var newPostKey = admin.database().ref().child('queries').push().key; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validate query if not null. |
||
var updates = {}; | ||
updates['/queries/' + newPostKey] = query; | ||
database.ref().update(updates); | ||
response.status(401).json({ | ||
message : "query successfully added" | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to change it as per the number of facts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.