Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
bnonni committed May 7, 2022
2 parents c026850 + 18ffdb8 commit 3d59da6
Show file tree
Hide file tree
Showing 39 changed files with 9,787 additions and 28 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ logs
**/*.backup.*
**/*.back.*

node_modules
**/node_modules
bower_components

*.sublime*
Expand All @@ -18,6 +18,12 @@ psd
thumb
sketch

<<<<<<< HEAD
*.lock

# End of https://www.toptal.com/developers/gitignore/api/react
# End of https://www.toptal.com/developers/gitignore/api/react
=======
# End of https://www.toptal.com/developers/gitignore/api/react

**/service-account.json
>>>>>>> 18ffdb861cdf24a7ebaea8c6f91205ed97a03c98
85 changes: 85 additions & 0 deletions backend/api/Admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//Parent Account Requests

// CreateNewAccount
// - ManageChildren
// - GetChildren
// - InviteChild
// - Role (1-4)
// - TransitionChildRole
// - SetChildAllowance
// - TransferFunds

import db, { getFamily } from "../db/db";
import {
collection,
doc,
setDoc,
updateDoc,
arrayUnion,
getDocs,
query,
where,
} from "firebase/firestore";

export const GetFamily = async (familyName) => {
console.log("Getting Family");
return await getFamily(familyName);
};

export const CreateNewFamily = async (familyName) => {
await setDoc(doc(db, "families", familyName), {
familyName: familyName,
children: [],
});
return { success: true };
};
export const GetChildren = async (familyId) => {
return { children };
};

export const InviteChild = async (familyId, childName, role) => {
return { success: true };
};

export const AddChild = async (
familyName,
childName,
role,
balance,
allowance
) => {
const coll = collection(db, "families");
const docs = await getDocs(coll);
console.log("getDocs", docs);
let famDoc = null;
await docs.forEach((doc) => {
console.log("snap", doc);
famDoc = doc;
});

await updateDoc(famDoc, {
children: arrayUnion({
allowance: allowance,
name: childName,
role: role,
balance: balance,
}),
});
return { success: true, familyDoc };
};

export const TransitionChildRole = async (familyId, childId, newRole) => {
return { success: true };
};

export const SetChildAllowance = async (familyId, childId, allowance) => {
return { success: true };
};

export const TransferFunds = async (familyId, childId, amount) => {
return { success: true };
};

export const ExportChild = async (familyId, childId) => {
return { success: true };
};
26 changes: 26 additions & 0 deletions backend/api/Child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Children Account Requests
// - GetBalance
// - GetTransactions
// - GetAllowance
// - SendPayment
// - RequestOneTimeAllowance

export const GetBalance = async (familyId, childId) => {
return { balance: 0 };
};

export const GetTransactions = async (familyId, childId) => {
return { transactions: [] };
};

export const GetAllowance = async (familyId, childId) => {
return { allowance: 0 };
};

export const SendPayment = async (familyId, childId, amount) => {
return { success: true };
};

export const RequestOneTimeAllowance = async (familyId, childId, amount) => {
return { success: true };
};
7 changes: 7 additions & 0 deletions backend/db/collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const db = require("./db");
const DB_COLLECTION = "families";

const collection = db.collection(DB_COLLECTION);
console.log(`Connected to collection ${db.projectId}/${DB_COLLECTION}`);

export default collection;
22 changes: 22 additions & 0 deletions backend/db/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { initializeApp } from "firebase/app";
import { getFirestore, collection, getDocs } from "firebase/firestore";

const firebaseConfig = require("../service-account.json");
console.log(firebaseConfig);

const app = initializeApp(firebaseConfig);

const db = getFirestore(app);
utils.info(`Connection to GCP Project ${db.projectId} successful!`);
export default db;

export const getFamily = async (familyName) => {
const querySnapshot = await getDocs(collection(db, "families"));
let res = null;
const docs = await querySnapshot.forEach((doc) => {
if (doc.data()["family-name"] === familyName) {
res = doc.data();
}
});
return res;
};
File renamed without changes.
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# Created by https://www.toptal.com/developers/gitignore/api/react
# Edit at https://www.toptal.com/developers/gitignore?templates=react

### react ###
.DS_*
*.log
logs
**/*.backup.*
**/*.back.*

node_modules
bower_components

*.sublime*

psd
thumb
sketch

# End of https://www.toptal.com/developers/gitignore/api/react

service-account.json
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json → frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"node-fetch": "^3.2.4",
"firebase": "9.8.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions frontend/src/routes/Accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Outlet, useParams, Link } from "react-router-dom";
import { AddChild, CreateNewFamily, GetFamily } from "../serviceRequests/Admin";
import { useEffect, useState } from "react";
import { async } from "@firebase/util";
//Specifc, Private Family Page
const Accounts = () => {
const { family } = useParams();
const [fam, setFam] = useState([]);
const [children, setChildren] = useState([]);

useEffect(() => {
async function getData() {
// await CreateNewFamily("atlantabitdevs");
const res = await AddChild("atlantabitdevs", "Bryan", "piggy", 20, 0);
// const _fam = await GetFamily("atlantabitdevs");
// setFam(_fam);
// const members = await _fam.children.map((member) => member.name);
// setChildren(members);
}
getData();
}, []);

// const members = ["Steven", "Alex", "Bryan", "Jordan"];

return (
<div>
<h2>Welcome {family} family!</h2>
<ul>
{children &&
children.map((member, key) => {
return (
<li key={key}>
<Link to={`${member}`}>{member}'s Account</Link>
</li>
);
})}
</ul>
<Outlet />
</div>
);
};

export default Accounts;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Outlet } from "react-router-dom";
const NewAccount = () => {
return (
<div>
<h1>New Account Screen</h1>
<Outlet />
</div>
);
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
85 changes: 85 additions & 0 deletions frontend/src/serviceRequests/Admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//Parent Account Requests

// CreateNewAccount
// - ManageChildren
// - GetChildren
// - InviteChild
// - Role (1-4)
// - TransitionChildRole
// - SetChildAllowance
// - TransferFunds

// import db, { getFamily } from "../db/db";
// import {
// collection,
// doc,
// setDoc,
// updateDoc,
// arrayUnion,
// getDocs,
// query,
// where,
// } from "firebase/firestore";

export const GetFamily = async (familyName) => {
console.log("Getting Family");
// return await getFamily(familyName);
};

export const CreateNewFamily = async (familyName) => {
// await setDoc(doc(db, "families", familyName), {
// familyName: familyName,
// children: [],
// });
return { success: true };
};
export const GetChildren = async (familyId) => {
return { children };
};

export const InviteChild = async (familyId, childName, role) => {
return { success: true };
};

export const AddChild = async (
familyName,
childName,
role,
balance,
allowance
) => {
// const coll = collection(db, "families");
// const docs = await getDocs(coll);
// console.log("getDocs", docs);
// let famDoc = null;
// await docs.forEach((doc) => {
// console.log("snap", doc);
// famDoc = doc;
// });

// await updateDoc(famDoc, {
// children: arrayUnion({
// allowance: allowance,
// name: childName,
// role: role,
// balance: balance,
// }),
// });
return { success: true, familyDoc };
};

export const TransitionChildRole = async (familyId, childId, newRole) => {
return { success: true };
};

export const SetChildAllowance = async (familyId, childId, allowance) => {
return { success: true };
};

export const TransferFunds = async (familyId, childId, amount) => {
return { success: true };
};

export const ExportChild = async (familyId, childId) => {
return { success: true };
};
26 changes: 26 additions & 0 deletions frontend/src/serviceRequests/Child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Children Account Requests
// - GetBalance
// - GetTransactions
// - GetAllowance
// - SendPayment
// - RequestOneTimeAllowance

export const GetBalance = async (familyId, childId) => {
return { balance: 0 };
};

export const GetTransactions = async (familyId, childId) => {
return { transactions: [] };
};

export const GetAllowance = async (familyId, childId) => {
return { allowance: 0 };
};

export const SendPayment = async (familyId, childId, amount) => {
return { success: true };
};

export const RequestOneTimeAllowance = async (familyId, childId, amount) => {
return { success: true };
};
File renamed without changes.
Loading

0 comments on commit 3d59da6

Please sign in to comment.