Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -2,6 +2,7 @@

# dependencies
/node_modules
.env
/.pnp
.pnp.*
.yarn/*
Expand Down
137 changes: 137 additions & 0 deletions package-lock.json

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

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
"start": "next start"
},
"dependencies": {
"argon2": "^0.44.0",
"next": "16.0.1",
"react": "19.2.0",
"react-dom": "19.2.0",
"next": "16.0.1"
"react-dom": "19.2.0"
},
"devDependencies": {
"typescript": "^5",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@tailwindcss/postcss": "^4",
"tailwindcss": "^4"
"tailwindcss": "^4",
"typescript": "^5"
}
}
Binary file removed src/app/favicon.ico
Binary file not shown.
34 changes: 0 additions & 34 deletions src/app/layout.tsx

This file was deleted.

Empty file added src/components/.gitadd
Empty file.
6 changes: 6 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "@/styles/globals.css";
import type { AppProps } from "next/app";

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
}
16 changes: 16 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Html, Head, Main, NextScript } from "next/document";

export default function Document() {
return (
<Html
lang="en"
className={`h-full antialiased`}
>
<Head />
<body className="min-h-full flex flex-col">
<Main />
<NextScript />
</body>
</Html>
);
}
14 changes: 14 additions & 0 deletions src/pages/api/admin/animals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getAllAnimals } from "../../../../webapp/server/mongodb/actions/animalActions.js";

export default async function handler(req, res) {
if (req.method === "GET") {
try {
const animals = await getAllAnimals();
return res.status(200).json(animals);
} catch (err) {
return res.status(500).json({ error: err.message });
}
}

return res.status(405).json({ error: "Method not allowed" });
}
25 changes: 25 additions & 0 deletions src/pages/api/admin/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// allows you to get all user information, given that you are an admin

import { NextApiRequest, NextApiResponse } from 'next';
import connectDB from '../../../../webapp/server/mongodb';
import User from '../../../../webapp/server/mongodb/models/user';

// we need the id to be passed in of the person requesting this info
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
if (req.method !== 'GET') {
throw new Error('Invalid HTTP method');
}
await connectDB();
const requesterId = req.headers['user-id'];
const requester = await User.findById(requesterId);

if (!requester || !requester.admin) {
return res.status(500).json({ error: "Unauthorized"});
}
const users = await User.find().select('-password');
return res.status(200).json(users);
} catch (error) {
return res.status(500).json({ error: 'There was an error' });
}
}
25 changes: 25 additions & 0 deletions src/pages/api/animal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createAnimal, updateAnimal } from "../../../server/mongodb/actions/animalActions.js";

export default async function handler(req, res) {
if (req.method === "POST") {
try {
const animal = await createAnimal(req.body);
return res.status(201).json(animal);
} catch (err) {
return res.status(400).json({ error: err.message });
}
}

if (req.method === "PATCH") {
try {
const { id, ...data } = req.body;
const animal = await updateAnimal(id, data);
if (!animal) return res.status(404).json({ error: "Animal not found" });
return res.status(200).json(animal);
} catch (err) {
return res.status(400).json({ error: err.message });
}
}

return res.status(405).json({ error: "Method not allowed" });
}
Loading