Skip to content

Commit

Permalink
old update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayothegod committed Jul 10, 2024
1 parent fe96643 commit 7ebfa92
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 8 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ origin https://new.url/repo.git (push)
- SETTINGS

- history(chart on spend data)
- recent transaction(table for all resent transactions) can filter the table
- summary {weekly, monthly}
6 changes: 1 addition & 5 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

### TODO

- how to configure header and description for each page in react vite

- also start create transaction category
- in case of error, make all the places i fethced data to return something based on error

- find way to make sessions worthwhile and understandable, how to logout user once the session is expired

- if user, then make the go back home on error page redirect ton dashboard instead of /index
- make description required
- check if no user/transaction data and redirect from transactions page
- update all colors to blue
5 changes: 5 additions & 0 deletions client/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Register from "./routes/register.tsx";
import { Toaster } from "./components/ui/toaster.tsx";
import Login, { Loader as loginLoader } from "./routes/login.tsx";
import Account, { Loader as accountLoader } from "./routes/account.tsx";
import Wallet from "./routes/wallet.tsx";
// NOTE: make sure to add errorBoundary to all routes that throw error from loader and actions

const router = createBrowserRouter([
Expand Down Expand Up @@ -68,6 +69,10 @@ const router = createBrowserRouter([
element: <Account />,
loader: accountLoader,
},
{
path: "/wallet",
element: <Wallet />,
},
],
},
]);
Expand Down
1 change: 0 additions & 1 deletion client/src/routes/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default function Account() {
}, [isUser]);

// TODO: once we update data, create a new user object and save using the updated data

return (
<div className="mx-auto mt-4 pb-16 min-h-screen">
<h1 className="text-xl font-bold">My Account</h1>
Expand Down
6 changes: 6 additions & 0 deletions client/src/routes/wallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export default function Wallet() {
return (
<div>Wallet</div>
)
}
7 changes: 7 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ model User {
password String
transactions Transaction[]
category Category[]
Profile Profile?
}

model Profile {
id String @id @default(cuid())
userId String @unique
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model Transaction {
Expand Down
43 changes: 42 additions & 1 deletion server/src/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,45 @@ export const transactionSchema = z.object({

export const categorySchema = z.object({
name: z.string().min(1, "category is too short"),
})
});

// bio
// phone number
// home address


// Financial Information
// Income Details
// Monthly Income
// Income Sources

// Expenditure Details
// Monthly Rent/Mortgage
// Utility Bills
// Other Recurring Expenses


// Employment Details
// Occupation
// Company Name
// Job Title
// Years of Experience


// Security and Preferences
// Username
// Password
// Two-Factor Authentication (2FA) Setup
// Security Questions
// Notification Preferences
// Email Notifications
// SMS Notifications
// Push Notifications


// Goals and Preferences
// Financial Goals
// Short-term Goals
// Long-term Goals
// Risk Tolerance
// Preferred Investment Types
74 changes: 74 additions & 0 deletions server/src/routes/auth.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,80 @@ const authRoute = app
return c.json({ user: user });
// return c.json({});
})
.post("/create-profile", async (c) => {
try {
const data = await c.req.json();
const parsedData = userSchema.parse(data);

const newUser = await prisma.user.create({
data: {
email: parsedData.email,
username: parsedData.username,
name: parsedData.name,
password: parsedData.password,
},
});

return c.json(
{ msg: "User created successfully", id: newUser.id },
{ status: 201 }
);
} catch (error) {
log(error);

if (error instanceof z.ZodError) {
error.errors.map((error) => {
log(error.message);
// TODO: how to catch errors from catch from the frontend
// throw new Error(error.message);
});
return c.json({ error: "invalid credentials" });
}
return c.json({ error: "try again later" });
}
})
.post("/update-user", async (c) => {
try {
const data = await c.req.json();
const parsedData = userSchema.parse(data);

// check if email already exists
const checkEmail = await prisma.user.findUnique({
where: { email: parsedData.email },
});
if (checkEmail) {
return c.json({ error: "Email already exists" });
}

// Hash password

const newUser = await prisma.user.create({
data: {
email: parsedData.email,
username: parsedData.username,
name: parsedData.name,
password: parsedData.password,
},
});

return c.json(
{ msg: "User created successfully", id: newUser.id },
{ status: 201 }
);
} catch (error) {
log(error);

if (error instanceof z.ZodError) {
error.errors.map((error) => {
log(error.message);
// TODO: how to catch errors from catch from the frontend
// throw new Error(error.message);
});
return c.json({ error: "invalid credentials" });
}
return c.json({ error: "try again later" });
}
})
.delete("logout", async (c) => {
const session = c.get("session");
session.deleteSession();
Expand Down

0 comments on commit 7ebfa92

Please sign in to comment.