diff --git a/.gitignore b/.gitignore index eda0de0..4b37ae0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ node_modules .env ServiceAccount.json +.vercel diff --git a/controllers/beneficiaries.controllers.js b/controllers/beneficiaries.controllers.js index dbfcd1a..c6bcb70 100644 --- a/controllers/beneficiaries.controllers.js +++ b/controllers/beneficiaries.controllers.js @@ -68,6 +68,7 @@ const editBeneficiary = async (req, res) => { try { const beneficiaryId = req.params?.beneficiaryId; console.log(req.body); + if (beneficiaryId) { const beneficiary = Beneficiary.findByIdAndUpdate( beneficiaryId, diff --git a/controllers/users.controllers.js b/controllers/users.controllers.js index ab10f3a..83a70e2 100644 --- a/controllers/users.controllers.js +++ b/controllers/users.controllers.js @@ -1,5 +1,5 @@ const { ObjectId } = require("mongoose").Types; -const admin = require("../firebase"); +const auth = require("../firebase"); const User = require("../models/User.js"); @@ -7,7 +7,7 @@ const createUser = async (req, res) => { try { //needed in case we need to add validation stuff in the future const { firebaseUID, firstName, lastName, joinDate, level } = req.body; - + console.log("ADDING USER"); const newUser = await User.create(req.body); await newUser.save(); @@ -139,19 +139,17 @@ const deleteUser = async (req, res) => { const createFirebaseUser = (req, res) => { // TODO: encrypt this bro const { email, pass } = req.body; - admin - .auth() - .createUser({ - email: email, - password: pass, - }) + auth.createUser({ + email: email, + password: pass, + }) .then((userRecord) => { console.log("Successfully created user"); console.log(userRecord); res.send(userRecord); }) .catch((error) => { - console.log("Error, error"); + console.log(error); }); }; diff --git a/firebase.js b/firebase.js index c968ac3..d200659 100644 --- a/firebase.js +++ b/firebase.js @@ -1,6 +1,6 @@ // const admin = require("firebase-admin"); // const serviceAccount = require("./ServiceAccount.json"); -// const {getAuth} = require('firebase-admin/auth') +// const { getAuth } = require('firebase-admin/auth') // admin.initializeApp({ // credential: admin.credential.cert(serviceAccount), @@ -8,13 +8,14 @@ // module.exports = admin; // TODO: figure out the difference between above and below + const { initializeApp, cert } = require("firebase-admin/app"); const { getAuth } = require("firebase-admin/auth"); - -const serviceAccount = require("./ServiceAccount.json"); +//const admin = require("firebase-admin"); +// const serviceAccount = require("./ServiceAccount.json"); const app = initializeApp({ - credential: cert(serviceAccount), + credential: cert(JSON.parse(process.env.VERCEL_URI)), }); const auth = getAuth(app); diff --git a/app.js b/index.js similarity index 90% rename from app.js rename to index.js index 2d11c5a..9261e2c 100644 --- a/app.js +++ b/index.js @@ -3,7 +3,7 @@ const cors = require("cors"); const helmet = require("helmet"); const connectDB = require("./config/database.js"); -const PORT = 3000; +const PORT = process.env.VERCEL_URL || 3000; const app = express(); @@ -13,6 +13,7 @@ connectDB(); // Connect to MongoDB app.use(express.json()); app.use(cors()); app.use(helmet()); +// app.use(express.static('public')) // Routers app.use("/assessments", require("./routes/assessments.router.js")); diff --git a/middleware/verifyAdmin.js b/middleware/verifyAdmin.js index f8d0949..a0bd833 100644 --- a/middleware/verifyAdmin.js +++ b/middleware/verifyAdmin.js @@ -33,9 +33,10 @@ const verifyAdmin = async (req, res, next) => { }; const checkAdminStatus = async (uid, token) => { + console.log("checkAdmin function starting"); try { const res = await fetch( - `http://localhost:3000/users?firebaseUID=${uid}`, + `https://hfc-backend-delta.vercel.app/users?firebaseUID=${uid}`, { headers: { "Content-Type": "application/json", diff --git a/models/Beneficiary.js b/models/Beneficiary.js index fc5a777..bba11a1 100644 --- a/models/Beneficiary.js +++ b/models/Beneficiary.js @@ -83,6 +83,45 @@ const BeneficiarySchema = new Schema({ photo: { type: String, // change this when we know how to store photos }, + hasBankAccountIntake: { + type: Boolean, + }, + hasBankAccountCompletion: { + type: Boolean, + }, + englishLvlIntake: { + type: Number, + }, + englishLvlCompletion: { + type: Number, + }, + computerSkillsIntake: { + type: Number, + }, + computerSkillsCompletion: { + type: Number, + }, + emotionalWellnessIntake: { + type: Number, + }, + emotionalWellnessCompletion: { + type: Number, + }, + incomeIntake: { + type: Number, + }, + incomeCompletion: { + type: Number, + }, + savingsIntake: { + type: Number, + }, + savingsCompletion: { + type: Number, + }, + hasFoundWorkCompletion: { + type: Boolean, + }, }); module.exports = Beneficiary = mongoose.model( diff --git a/package-lock.json b/package-lock.json index 3bc2396..86dedcf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "express": "^4.18.2", "firebase-admin": "^11.5.0", "helmet": "^6.0.1", + "i": "^0.3.7", "mongoose": "^6.7.2" }, "devDependencies": { @@ -2815,6 +2816,14 @@ "url": "https://github.com/sponsors/typicode" } }, + "node_modules/i": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/i/-/i-0.3.7.tgz", + "integrity": "sha512-FYz4wlXgkQwIPqhzC5TdNMLSE5+GS1IIDJZY/1ZiEPCT2S3COUVZeT5OW4BmW4r5LHLQuOosSwsvnroG9GR59Q==", + "engines": { + "node": ">=0.4" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "license": "MIT", @@ -7199,6 +7208,11 @@ "version": "8.0.2", "dev": true }, + "i": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/i/-/i-0.3.7.tgz", + "integrity": "sha512-FYz4wlXgkQwIPqhzC5TdNMLSE5+GS1IIDJZY/1ZiEPCT2S3COUVZeT5OW4BmW4r5LHLQuOosSwsvnroG9GR59Q==" + }, "iconv-lite": { "version": "0.4.24", "requires": { diff --git a/package.json b/package.json index 7d7606c..6bd82fa 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,10 @@ "name": "hfc-backend", "version": "1.0.0", "description": "", - "main": "app.js", + "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon app.js", + "start": "node index.js", "format": "prettier --write \"**/*.{js,jsx,json,css,md}\"" }, "lint-staged": { @@ -32,6 +32,7 @@ "express": "^4.18.2", "firebase-admin": "^11.5.0", "helmet": "^6.0.1", + "i": "^0.3.7", "mongoose": "^6.7.2" }, "devDependencies": { diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..64fa037 --- /dev/null +++ b/vercel.json @@ -0,0 +1,15 @@ +{ + "version": 2, + "builds": [ + { + "src": "*.js", + "use": "@vercel/node" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "/" + } + ] +}