Skip to content
Open

Dev #51

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
.env

ServiceAccount.json
.vercel
1 change: 1 addition & 0 deletions controllers/beneficiaries.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 7 additions & 9 deletions controllers/users.controllers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { ObjectId } = require("mongoose").Types;
const admin = require("../firebase");
const auth = require("../firebase");

const User = require("../models/User.js");

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();

Expand Down Expand Up @@ -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);
});
};

Expand Down
9 changes: 5 additions & 4 deletions firebase.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// 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),
// });

// 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);
Expand Down
3 changes: 2 additions & 1 deletion app.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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"));
Expand Down
3 changes: 2 additions & 1 deletion middleware/verifyAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions models/Beneficiary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
15 changes: 15 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 2,
"builds": [
{
"src": "*.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/"
}
]
}