mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 12:36:57 +00:00
Update packages
This commit is contained in:
+27
-25
@@ -8,31 +8,33 @@ import { collections, dbConnect } from "@/server/mongodb";
|
||||
import { errorLog } from "@/utils/logger";
|
||||
|
||||
import { ZoneModel } from "./models/zoneModel";
|
||||
import { action } from "./safeAction";
|
||||
import { actionClient } from "./safeAction";
|
||||
|
||||
export const createZone = action(zoneSchema, async (input) => {
|
||||
try {
|
||||
await dbConnect();
|
||||
export const createZone = actionClient
|
||||
.schema(zoneSchema)
|
||||
.action(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 user = await auth();
|
||||
if (!user?.user) {
|
||||
throw new Error("You must be logged in to create a zone");
|
||||
}
|
||||
|
||||
const zoneData: ZoneModel = {
|
||||
...input.parsedInput,
|
||||
userId: new ObjectId(user.user!.id!),
|
||||
};
|
||||
|
||||
const result = await collections.zones!.insertOne(zoneData);
|
||||
|
||||
if (!result.acknowledged) {
|
||||
throw new Error("ERR_ZONE_INSERT_FAILED");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
errorLog(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const zoneData: ZoneModel = {
|
||||
...input,
|
||||
userId: new ObjectId(user.user!.id!),
|
||||
};
|
||||
|
||||
const result = await collections.zones!.insertOne(zoneData);
|
||||
|
||||
if (!result.acknowledged) {
|
||||
throw new Error("ERR_ZONE_INSERT_FAILED");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
errorLog(error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user