Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
Project clean up: Use of newly generated key
Browse files Browse the repository at this point in the history
  • Loading branch information
HJunyuan committed Mar 19, 2020
1 parent eaa98d1 commit c24e1f7
Show file tree
Hide file tree
Showing 7 changed files with 2,039 additions and 1,874 deletions.
2 changes: 1 addition & 1 deletion .firebaserc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"projects": {
"default": "divvy-eb390"
"default": "meddic-57a28"
}
}
29 changes: 19 additions & 10 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"hosting": {
"public": "functions/public",
"rewrites": [
{
"source": "**",
"function": "app"
}
],
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
"hosting": {
"public": "functions/public",
"rewrites": [
{
"source": "**",
"function": "app"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}
123 changes: 123 additions & 0 deletions functions/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 2017
},
"plugins": [
"promise"
],
"extends": "eslint:recommended",
"rules": {
// Removed rule "disallow the use of console" from recommended eslint rules
"no-console": "off",

// Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
"no-regex-spaces": "off",

// Removed rule "disallow the use of debugger" from recommended eslint rules
"no-debugger": "off",

// Removed rule "disallow unused variables" from recommended eslint rules
"no-unused-vars": "off",

// Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules
"no-mixed-spaces-and-tabs": "off",

// Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules
"no-undef": "off",

// Warn against template literal placeholder syntax in regular strings
"no-template-curly-in-string": 1,

// Warn if return statements do not either always or never specify values
"consistent-return": 1,

// Warn if no return statements in callbacks of array methods
"array-callback-return": 1,

// Require the use of === and !==
"eqeqeq": 2,

// Disallow the use of alert, confirm, and prompt
"no-alert": 2,

// Disallow the use of arguments.caller or arguments.callee
"no-caller": 2,

// Disallow null comparisons without type-checking operators
"no-eq-null": 2,

// Disallow the use of eval()
"no-eval": 2,

// Warn against extending native types
"no-extend-native": 1,

// Warn against unnecessary calls to .bind()
"no-extra-bind": 1,

// Warn against unnecessary labels
"no-extra-label": 1,

// Disallow leading or trailing decimal points in numeric literals
"no-floating-decimal": 2,

// Warn against shorthand type conversions
"no-implicit-coercion": 1,

// Warn against function declarations and expressions inside loop statements
"no-loop-func": 1,

// Disallow new operators with the Function object
"no-new-func": 2,

// Warn against new operators with the String, Number, and Boolean objects
"no-new-wrappers": 1,

// Disallow throwing literals as exceptions
"no-throw-literal": 2,

// Require using Error objects as Promise rejection reasons
"prefer-promise-reject-errors": 2,

// Enforce “for” loop update clause moving the counter in the right direction
"for-direction": 2,

// Enforce return statements in getters
"getter-return": 2,

// Disallow await inside of loops
"no-await-in-loop": 2,

// Disallow comparing against -0
"no-compare-neg-zero": 2,

// Warn against catch clause parameters from shadowing variables in the outer scope
"no-catch-shadow": 1,

// Disallow identifiers from shadowing restricted names
"no-shadow-restricted-names": 2,

// Enforce return statements in callbacks of array methods
"callback-return": 2,

// Require error handling in callbacks
"handle-callback-err": 2,

// Warn against string concatenation with __dirname and __filename
"no-path-concat": 1,

// Prefer using arrow functions for callbacks
"prefer-arrow-callback": 1,

// Return inside each then() to create readable and reusable Promise chains.
// Forces developers to return console logs and http calls in promises.
"promise/always-return": 2,

//Enforces the use of catch() on un-returned promises
"promise/catch-or-return": 2,

// Warn against nested then() or catch() statements
"promise/no-nesting": 1
}
}
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
32 changes: 28 additions & 4 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ const app = express();
app.use(bodyParser.urlencoded({ extended: false }));

/* Firebase Initialisation */
var serviceAccount = require("../private/meddic-57a28-firebase-adminsdk-lhwmy-a07a940214.json");
admin.initializeApp({
credential: admin.credential.applicationDefault(),
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://meddic-57a28.firebaseio.com"
});

const database = admin.database();

/* Define directories */
Expand All @@ -27,7 +29,9 @@ const viewsDir = path.join(publicDir, "views");
app.get("/", (req, res) => res.sendFile(path.join(viewsDir, "index.html")));

// Registration Page
app.get("/registration", (req, res) => res.sendFile(path.join(viewsDir, "registration.html")));
app.get("/registration", (req, res) =>
res.sendFile(path.join(viewsDir, "registration.html"))
);

/* ================= API: POST Requests ================= */
// New Student Registration
Expand All @@ -44,7 +48,17 @@ app.post("/api/newregistration", (req, res) => {
const descriptors = person.descriptors;
const imageURL = person.imageURL;

regPatient(fullName, nric, gender, dateOfBirth, drugAllergies, preExisting, comments, descriptors, imageURL);
regPatient(
fullName,
nric,
gender,
dateOfBirth,
drugAllergies,
preExisting,
comments,
descriptors,
imageURL
);

res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify({ msg: "Successfully registered!" }));
Expand Down Expand Up @@ -75,7 +89,17 @@ app.use(function(req, res, next) {
});

/* ================= Functions ================= */
function regPatient(fullName, nric, gender, dateOfBirth, drugAllergies, preExisting, comments, descriptors, imageURL) {
function regPatient(
fullName,
nric,
gender,
dateOfBirth,
drugAllergies,
preExisting,
comments,
descriptors,
imageURL
) {
let databaseRef = database.ref("patients");
databaseRef = databaseRef.child(nric);

Expand Down
Loading

0 comments on commit c24e1f7

Please sign in to comment.