Skip to content

adding event functions#2

Open
gogarattan wants to merge 3 commits intomasterfrom
events
Open

adding event functions#2
gogarattan wants to merge 3 commits intomasterfrom
events

Conversation

@gogarattan
Copy link
Copy Markdown
Collaborator

Signed-off-by: Gaurav gogarattan@gmail.com
Signed-off-by: Ankur Charan ankurcharan98@gmail.com
Signed-off-by: Vaibhav
Signed-off-by: Harshita

Signed-off-by: Gaurav <gogarattan@gmail.com>
Comment thread functions/index.js
let startTime = req.body.startTime;
let endTime = req.body.endTime;
let eventDescription = req.body.eventDescription;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make generic body design of event data. Many new fields can be introduced later on. So accept form data as json and parse it here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okkk

Comment thread functions/index.js
endTime : endTime
})
.then((snapshot) => {
console.log('done')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify the success message to "Added {event} to timeline successfully".

Comment thread functions/index.js
console.log('done')
}).catch((err) => {
res.send(err)
})
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appropriate error statement: Error occurred while adding to timeline

Comment thread functions/index.js
eventDescription : eventDescription,
startTime : startTime,
endTime : endTime
}).then((snapshot) => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to generic implementation

Comment thread functions/index.js
}).catch((err) => {
return res.send(err)
})
})
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appropriate log messages.

Comment thread functions/index.js

const db = admin.database().ref();

exports.addEvent = functions.https.onRequest((req,res) => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comments? Please explain this function in comments

Comment thread functions/index.js
{
var obj = {};
obj.name = i;
data.categories.push(obj);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response should be like :
{
"categories": ["a", "b"]
}

Comment thread functions/index.js
{
var obj = {};
obj.category = category,
obj.name = database[category][event].name;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this as previous: {
"managerial": ["a", "b"],
"programming" : ["a","b"]
}

Comment thread functions/index.js
}
else if(req.query.category == 'one')
{
let cat = req.query.eventCategory;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat? change it

Comment thread functions/index.js
})
}
else {
return res.send("Invalid parameters.");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print parameter also.

Comment thread functions/index.js

exports.getEventDescription = functions.https.onRequest((req,res) => {

if(req.query.events == 'all')
Copy link
Copy Markdown
Owner

@devgrpnitkkr devgrpnitkkr Sep 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. Dead code. Never all events are required. Use cases are:

  1. Single event
  2. All events for one category.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okok

Comment thread functions/index.js

exports.getCategories = functions.https.onRequest((req,res) => {

return db.child('events').once('value')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hard-code these strings. Declare global variables for references.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to declare them global . this is the general uniform format of writing code .

Comment thread functions/index.js

if(req.query.category == 'all')
{
return db.child('events').once('value')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hard-code these strings. Declare global variables for references.

Comment thread functions/index.js
else if(req.query.category == 'one')
{
let cat = req.query.eventCategory;
return db.child(`events/${cat}`).once('value')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hard-code these strings. Declare global variables for references.

Comment thread functions/index.js

if(req.query.events == 'all')
{
return db.child('eventDescription').once('value')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hard-code these strings. Declare global variables for references.

Comment thread functions/index.js

var events=database[category];

for(var event in events)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build separate function for this

Comment thread functions/index.js
data.eventDesciption.push(obj);
}
}
return res.send(data);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no processing required

Comment thread functions/index.js
let eventName = req.query.eventName

if(eventCategory == null || eventName == null) {
res.send("Insufficient parameters.")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print event category and event name values

Comment thread functions/index.js
db.child(`eventDescription/${eventCategory}/${eventName}`).once('value')
.then((snapshot) => {
if(snapshot == null) {
return res.send("Event Doesn't Exist.");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print values

Comment thread functions/index.js
return res.send(err)
})
}
else if(req.query.events == 'cat')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat? and hardcoded?

Comment thread functions/index.js
let categoryName = req.query.eventCategory;
if(categoryName == null)
{
return res.send("Insufficient Parameters.");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change error message.

Copy link
Copy Markdown
Owner

@devgrpnitkkr devgrpnitkkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify as per comments

Comment thread functions/index.js
Comment thread functions/index.js Outdated
response.send("Invalid Parameters.");
}

const request = require('request');
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require statements on top.

Comment thread functions/index.js Outdated
{
return console.log(err);
}
console.log(body);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to log complete body?

Comment thread functions/index.js Outdated
}

let email1 = body.emails[0].value;
let email = email1.replace(/\./g,',');
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make seperate function for this and rename this variable.

Comment thread functions/index.js Outdated
let node = "userRegistrations/"+ eventName;
console.log(node);
// let db = database.ref();
let db = admin.database().ref();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Comment thread functions/index.js Outdated

db.child(`${node}`).push(email);

db.child("users/" + email + "/events").once('value')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registeredEvents

Comment thread functions/index.js Outdated
}
else
{
newEventString = eventString + ", " + eventName;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove space

Comment thread functions/index.js Outdated
"events": newEventString
})
.then(() => {
response.send("Registered");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return json

Comment thread functions/index.js Outdated
})
.catch((error) => {
console.log(error);
response.send("Could not Register!");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants