Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
checking if school already exists while registering school
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-Sai committed Oct 21, 2018
1 parent fd22c32 commit 00a53ae
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,28 @@ app.post('/onSubmit', (req, res) => {
var mobile = req.body.mobile;
var cheque = req.body.cheque;
console.log(schoolName + " " + facultyName + " " + email + " " + mobile);
var ob = {
cheque : cheque,
schoolName: schoolName,
Faculty: {
ContactNo: mobile,
EmailID: email,
Name: facultyName,
var sch = db.collection("Schools").doc(schoolId);
sch.get().then((doc) => {
if(doc.exists){
return(doc);
}else{
var ob = {
cheque : cheque,
schoolName: schoolName,
Faculty: {
ContactNo: mobile,
EmailID: email,
Name: facultyName,
}

};
db.collection("Schools").doc(schoolId).set(ob);
throw new Error("School does not exist");
}

};
db.collection("Schools").doc(schoolId).set(ob);
}).catch((err)=>{
console.log(err);
});

// db.ref('Schools/'+schoolId).set({
// cheque : cheque,
// schoolName: schoolName,
Expand Down

0 comments on commit 00a53ae

Please sign in to comment.