Fixed some errors
This commit is contained in:
parent
7773801de4
commit
8bd3b10368
@ -76,7 +76,7 @@ model Observatory {
|
|||||||
longitude String
|
longitude String
|
||||||
latitude String
|
latitude String
|
||||||
dateEstablished Int?
|
dateEstablished Int?
|
||||||
functional Boolean
|
isFunctional Boolean
|
||||||
seismicSensorOnline Boolean @default(true)
|
seismicSensorOnline Boolean @default(true)
|
||||||
creatorId Int?
|
creatorId Int?
|
||||||
creator Scientist? @relation("ScientistObservatoryCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
creator Scientist? @relation("ScientistObservatoryCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
@ -85,9 +85,9 @@ model Observatory {
|
|||||||
|
|
||||||
model Artefact {
|
model Artefact {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
name String
|
||||||
type String @db.VarChar(50) // Lava, Tephra, Ash, Soil
|
type String @db.VarChar(50) // Lava, Tephra, Ash, Soil
|
||||||
warehouseArea String
|
warehouseArea String
|
||||||
description String
|
description String
|
||||||
@ -95,13 +95,13 @@ model Artefact {
|
|||||||
earthquake Earthquake @relation(fields: [earthquakeId], references: [id])
|
earthquake Earthquake @relation(fields: [earthquakeId], references: [id])
|
||||||
creatorId Int?
|
creatorId Int?
|
||||||
creator Scientist? @relation("ScientistArtefactCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
creator Scientist? @relation("ScientistArtefactCreator", fields: [creatorId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
required Boolean @default(true)
|
isRequired Boolean @default(true)
|
||||||
dateAddedToShop DateTime?
|
dateAddedToShop DateTime?
|
||||||
shopPrice Float?
|
shopPrice Float?
|
||||||
purchased Boolean @default(false)
|
isSold Boolean @default(false)
|
||||||
purchasedById Int?
|
purchasedById Int?
|
||||||
purchasedBy User? @relation("UserPurchasedArtefacts", fields: [purchasedById], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
purchasedBy User? @relation("UserPurchasedArtefacts", fields: [purchasedById], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
pickedUp Boolean @default(false)
|
isCollected Boolean @default(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
model Pallet {
|
model Pallet {
|
||||||
|
|||||||
@ -20,41 +20,34 @@ export async function POST(req: Request) {
|
|||||||
console.log("Email:", email); // ! remove
|
console.log("Email:", email); // ! remove
|
||||||
console.log("Password:", password); // ! remove
|
console.log("Password:", password); // ! remove
|
||||||
|
|
||||||
let user;
|
let user = await prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
email, // use the email to uniquely identify the user
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (usingPrisma) {
|
if (user && bcryptjs.compareSync(password, user.passwordHash)) {
|
||||||
user = await prisma.user.findUnique({
|
|
||||||
where: {
|
|
||||||
email, // use the email to uniquely identify the user
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
user = findUserByEmail(userData, email);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user && bcryptjs.compareSync(password, usingPrisma ? user.hashedPassword : user.password)) {
|
|
||||||
// todo remove password from returned user
|
// todo remove password from returned user
|
||||||
|
|
||||||
// get user and relations
|
// get user and relations
|
||||||
if (usingPrisma)
|
user = await prisma.user.findUnique({
|
||||||
user = await prisma.user.findUnique({
|
where: { id: user.id },
|
||||||
where: { id: user.id },
|
include: {
|
||||||
include: {
|
scientist: {
|
||||||
scientist: {
|
include: {
|
||||||
include: {
|
earthquakes: true,
|
||||||
earthquakes: true,
|
observatories: true,
|
||||||
observatories: true,
|
artefacts: true,
|
||||||
artefacts: true,
|
superior: true,
|
||||||
superior: true,
|
subordinates: true,
|
||||||
subordinates: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
purchasedArtefacts: true,
|
|
||||||
},
|
},
|
||||||
});
|
purchasedArtefacts: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const secret = new TextEncoder().encode(env.JWT_SECRET_KEY);
|
const secret = new TextEncoder().encode(env.JWT_SECRET_KEY);
|
||||||
const token = await new SignJWT({ userId: user.id })
|
const token = await new SignJWT({ userId: user!.id })
|
||||||
.setProtectedHeader({ alg: "HS256" })
|
.setProtectedHeader({ alg: "HS256" })
|
||||||
.setExpirationTime("2w")
|
.setExpirationTime("2w")
|
||||||
.sign(secret);
|
.sign(secret);
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
// todo get earthquakes associated with observatories
|
// todo get earthquakes associated with observatories
|
||||||
let observatories;
|
let observatories;
|
||||||
if (usingPrisma) observatories = await prisma.observatories.findMany();
|
if (usingPrisma) observatories = await prisma.observatory.findMany();
|
||||||
|
|
||||||
if (observatories) {
|
if (observatories) {
|
||||||
return NextResponse.json({ message: "Got observatories successfully", observatories }, { status: 200 });
|
return NextResponse.json({ message: "Got observatories successfully", observatories }, { status: 200 });
|
||||||
|
|||||||
@ -88,7 +88,7 @@ export async function POST(req: Request) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let artefacts;
|
let artefacts;
|
||||||
if (usingPrisma) artefacts = await prisma.artefacts.findMany();
|
if (usingPrisma) artefacts = await prisma.artefact.findMany();
|
||||||
|
|
||||||
if (artefacts) {
|
if (artefacts) {
|
||||||
return NextResponse.json({ message: "Got artefacts successfully", artefacts }, { status: 200 });
|
return NextResponse.json({ message: "Got artefacts successfully", artefacts }, { status: 200 });
|
||||||
|
|||||||
@ -8,62 +8,61 @@ import { IoFilter, IoFilterCircleOutline, IoFilterOutline, IoToday } from "react
|
|||||||
|
|
||||||
import type { Artefact } from "@prismaclient";
|
import type { Artefact } from "@prismaclient";
|
||||||
|
|
||||||
|
interface WarehouseArtefact extends Artefact {
|
||||||
|
location: string;
|
||||||
|
}
|
||||||
|
|
||||||
// Warehouse Artefacts Data
|
// Warehouse Artefacts Data
|
||||||
const warehouseArtefacts: Artefact[] = [
|
const warehouseArtefacts: WarehouseArtefact[] = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "Solidified Lava Chunk",
|
name: "Solidified Lava Chunk",
|
||||||
description: "A chunk of solidified lava from the 2023 Iceland eruption.",
|
description: "A chunk of solidified lava from the 2023 Iceland eruption.",
|
||||||
location: "Reykjanes, Iceland",
|
location: "Reykjanes, Iceland",
|
||||||
code: "EQ2023ICL",
|
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
isSold: false,
|
isSold: false,
|
||||||
isCollected: false,
|
isCollected: false,
|
||||||
dateAdded: "2025-05-04",
|
createdAt: "2025-05-04",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
name: "Tephra Sample",
|
name: "Tephra Sample",
|
||||||
description: "Foreign debris from the 2022 Tonga volcanic eruption.",
|
description: "Foreign debris from the 2022 Tonga volcanic eruption.",
|
||||||
location: "Tonga",
|
location: "Tonga",
|
||||||
code: "EQ2022TGA",
|
|
||||||
isRequired: false,
|
isRequired: false,
|
||||||
isSold: true,
|
isSold: true,
|
||||||
isCollected: true,
|
isCollected: true,
|
||||||
dateAdded: "2025-05-03",
|
createdAt: "2025-05-03",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
name: "Ash Sample",
|
name: "Ash Sample",
|
||||||
description: "Volcanic ash from the 2021 La Palma eruption.",
|
description: "Volcanic ash from the 2021 La Palma eruption.",
|
||||||
location: "La Palma, Spain",
|
location: "La Palma, Spain",
|
||||||
code: "EQ2021LPA",
|
|
||||||
isRequired: false,
|
isRequired: false,
|
||||||
isSold: false,
|
isSold: false,
|
||||||
isCollected: false,
|
isCollected: false,
|
||||||
dateAdded: "2025-05-04",
|
createdAt: "2025-05-04",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
name: "Ground Soil",
|
name: "Ground Soil",
|
||||||
description: "Soil sample from the 2020 Croatia earthquake site.",
|
description: "Soil sample from the 2020 Croatia earthquake site.",
|
||||||
location: "Zagreb, Croatia",
|
location: "Zagreb, Croatia",
|
||||||
code: "EQ2020CRO",
|
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
isSold: false,
|
isSold: false,
|
||||||
isCollected: false,
|
isCollected: false,
|
||||||
dateAdded: "2025-05-02",
|
createdAt: "2025-05-02",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
name: "Basalt Fragment",
|
name: "Basalt Fragment",
|
||||||
description: "Basalt rock from the 2019 New Zealand eruption.",
|
description: "Basalt rock from the 2019 New Zealand eruption.",
|
||||||
location: "White Island, New Zealand",
|
location: "White Island, New Zealand",
|
||||||
code: "EQ2019NZL",
|
|
||||||
isRequired: false,
|
isRequired: false,
|
||||||
isSold: true,
|
isSold: true,
|
||||||
isCollected: false,
|
isCollected: false,
|
||||||
dateAdded: "2025-05-04",
|
createdAt: "2025-05-04",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -185,7 +184,7 @@ function ArtefactTable({
|
|||||||
{ label: "Required", key: "isRequired", width: "6%" },
|
{ label: "Required", key: "isRequired", width: "6%" },
|
||||||
{ label: "Sold", key: "isSold", width: "5%" },
|
{ label: "Sold", key: "isSold", width: "5%" },
|
||||||
{ label: "Collected", key: "isCollected", width: "7%" },
|
{ label: "Collected", key: "isCollected", width: "7%" },
|
||||||
{ label: "Date Added", key: "dateAdded", width: "8%" },
|
{ label: "Date Added", key: "createdAt", width: "8%" },
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -205,7 +204,7 @@ function ArtefactTable({
|
|||||||
setFilters({ ...filters, [key]: value } as Record<string, string>);
|
setFilters({ ...filters, [key]: value } as Record<string, string>);
|
||||||
if (value === "") clearSortConfig();
|
if (value === "") clearSortConfig();
|
||||||
}}
|
}}
|
||||||
type={key === "dateAdded" ? "date" : "text"}
|
type={key === "createdAt" ? "date" : "text"}
|
||||||
options={["isRequired", "isSold", "isCollected"].includes(key) ? ["", "true", "false"] : undefined}
|
options={["isRequired", "isSold", "isCollected"].includes(key) ? ["", "true", "false"] : undefined}
|
||||||
/>
|
/>
|
||||||
{sortConfig?.key === key && (
|
{sortConfig?.key === key && (
|
||||||
@ -501,7 +500,7 @@ function EditModal({ artefact, onClose }: { artefact: Artefact; onClose: () => v
|
|||||||
const [isRequired, setIsRequired] = useState(artefact.isRequired);
|
const [isRequired, setIsRequired] = useState(artefact.isRequired);
|
||||||
const [isSold, setIsSold] = useState(artefact.isSold);
|
const [isSold, setIsSold] = useState(artefact.isSold);
|
||||||
const [isCollected, setIsCollected] = useState(artefact.isCollected);
|
const [isCollected, setIsCollected] = useState(artefact.isCollected);
|
||||||
const [dateAdded, setDateAdded] = useState(artefact.dateAdded);
|
const [createdAt, setDateAdded] = useState(artefact.createdAt.toDateString());
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
||||||
@ -512,7 +511,7 @@ function EditModal({ artefact, onClose }: { artefact: Artefact; onClose: () => v
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!name || !description || !location || !earthquakeId || !dateAdded) {
|
if (!name || !description || !location || !earthquakeId || !createdAt) {
|
||||||
setError("All fields are required.");
|
setError("All fields are required.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -603,7 +602,7 @@ function EditModal({ artefact, onClose }: { artefact: Artefact; onClose: () => v
|
|||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
value={dateAdded}
|
value={createdAt}
|
||||||
onChange={(e) => setDateAdded(e.target.value)}
|
onChange={(e) => setDateAdded(e.target.value)}
|
||||||
className="w-full p-2 border border-neutral-300 rounded-md focus:ring-2 focus:ring-blue-500"
|
className="w-full p-2 border border-neutral-300 rounded-md focus:ring-2 focus:ring-blue-500"
|
||||||
aria-label="Date Added"
|
aria-label="Date Added"
|
||||||
@ -658,13 +657,14 @@ const applyFilters = (artefacts: Artefact[], filters: Record<string, string>): A
|
|||||||
return (
|
return (
|
||||||
(filters.id === "" || artefact.id.toString().includes(filters.id)) &&
|
(filters.id === "" || artefact.id.toString().includes(filters.id)) &&
|
||||||
(filters.name === "" || artefact.name.toLowerCase().includes(filters.name.toLowerCase())) &&
|
(filters.name === "" || artefact.name.toLowerCase().includes(filters.name.toLowerCase())) &&
|
||||||
|
// todo fix
|
||||||
(filters.earthquakeId === "" || artefact.earthquakeId.toLowerCase().includes(filters.earthquakeId.toLowerCase())) &&
|
(filters.earthquakeId === "" || artefact.earthquakeId.toLowerCase().includes(filters.earthquakeId.toLowerCase())) &&
|
||||||
(filters.location === "" || artefact.location.toLowerCase().includes(filters.location.toLowerCase())) &&
|
(filters.location === "" || artefact.location.toLowerCase().includes(filters.location.toLowerCase())) &&
|
||||||
(filters.description === "" || artefact.description.toLowerCase().includes(filters.description.toLowerCase())) &&
|
(filters.description === "" || artefact.description.toLowerCase().includes(filters.description.toLowerCase())) &&
|
||||||
(filters.isRequired === "" || (filters.isRequired === "true" ? artefact.isRequired : !artefact.isRequired)) &&
|
(filters.isRequired === "" || (filters.isRequired === "true" ? artefact.isRequired : !artefact.isRequired)) &&
|
||||||
(filters.isSold === "" || (filters.isSold === "true" ? artefact.isSold : !artefact.isSold)) &&
|
(filters.isSold === "" || (filters.isSold === "true" ? artefact.isSold : !artefact.isSold)) &&
|
||||||
(filters.isCollected === "" || (filters.isCollected === "true" ? artefact.isCollected : !artefact.isCollected)) &&
|
(filters.isCollected === "" || (filters.isCollected === "true" ? artefact.isCollected : !artefact.isCollected)) &&
|
||||||
(filters.dateAdded === "" || artefact.dateAdded === filters.dateAdded)
|
(filters.createdAt === "" || artefact.createdAt.toDateString() === filters.createdAt)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -684,7 +684,7 @@ export default function Warehouse() {
|
|||||||
isRequired: "",
|
isRequired: "",
|
||||||
isSold: "",
|
isSold: "",
|
||||||
isCollected: "",
|
isCollected: "",
|
||||||
dateAdded: "",
|
createdAt: "",
|
||||||
});
|
});
|
||||||
const [isFiltering, setIsFiltering] = useState(false);
|
const [isFiltering, setIsFiltering] = useState(false);
|
||||||
const [sortConfig, setSortConfig] = useState<{
|
const [sortConfig, setSortConfig] = useState<{
|
||||||
@ -708,9 +708,11 @@ export default function Warehouse() {
|
|||||||
|
|
||||||
// Overview stats
|
// Overview stats
|
||||||
const totalArtefacts = warehouseArtefacts.length;
|
const totalArtefacts = warehouseArtefacts.length;
|
||||||
const today = "2025-05-04";
|
const today = new Date();
|
||||||
const artefactsAddedToday = warehouseArtefacts.filter((a) => a.dateAdded === today).length;
|
const artefactsAddedToday = warehouseArtefacts.filter((a) => a.createdAt.toDateString() === today.toDateString()).length;
|
||||||
const artefactsSoldToday = warehouseArtefacts.filter((a) => a.isSold && a.dateAdded === today).length;
|
const artefactsSoldToday = warehouseArtefacts.filter(
|
||||||
|
(a) => a.isSold && a.createdAt.toDateString() === today.toDateString()
|
||||||
|
).length;
|
||||||
|
|
||||||
const clearFilters = () => {
|
const clearFilters = () => {
|
||||||
setFilters({
|
setFilters({
|
||||||
@ -722,7 +724,7 @@ export default function Warehouse() {
|
|||||||
isRequired: "",
|
isRequired: "",
|
||||||
isSold: "",
|
isSold: "",
|
||||||
isCollected: "",
|
isCollected: "",
|
||||||
dateAdded: "",
|
createdAt: "",
|
||||||
});
|
});
|
||||||
setSortConfig(null); // Clear sorting
|
setSortConfig(null); // Clear sorting
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user