Zone collection + creation

Zone create UI flow
This commit is contained in:
Timothy Armes
2024-10-21 15:19:28 +02:00
parent 1da389a24a
commit 9f12a00030
21 changed files with 431 additions and 90 deletions
+29
View File
@@ -0,0 +1,29 @@
"use server";
import { omit } from "lodash";
import { ObjectId } from "mongodb";
import { z } from "zod";
import { auth } from "@/auth";
import { collections, dbConnect } from "@/server/mongodb";
import { action } from "./safeAction";
export const myZones = action(z.void(), async () => {
await dbConnect();
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to fetch your zones");
}
const zones = await collections
.zones!.find({ userId: new ObjectId(user.user!.id!) })
.toArray();
return zones.map((zone) => ({
...omit(zone, ["_id"]),
id: zone._id.toString(),
userId: zone.userId.toString(),
}));
});