Zone collection + creation

Zone create UI flow
This commit is contained in:
Timothy Armes
2024-04-11 09:05:05 +02:00
parent 1da389a24a
commit 9f12a00030
21 changed files with 431 additions and 90 deletions
+34
View File
@@ -0,0 +1,34 @@
"use server";
import { ObjectId } from "mongodb";
import { auth } from "@/auth";
import { zoneSchema } from "@/schemas";
import { collections, dbConnect } from "@/server/mongodb";
import { errorLog } from "@/utils/logger";
import { ZoneModel } from "./models/zoneModel";
import { action } from "./safeAction";
export const createZone = action(zoneSchema, async (input) => {
try {
await dbConnect();
const user = await auth();
if (!user?.user) {
throw new Error("You must be logged in to create a zone");
}
const zoneData: ZoneModel = {
...input,
userId: new ObjectId(user.user!.id!),
};
const result = await collections.zones!.insertOne(zoneData);
return true;
} catch (error) {
errorLog(error);
throw error;
}
});