mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 12:36:57 +00:00
Update packages
This commit is contained in:
+35
-32
@@ -10,43 +10,46 @@ import { collections, dbConnect } from "@/server/mongodb";
|
||||
import { errorLog } from "@/utils/logger";
|
||||
|
||||
import { ZoneModel } from "./models/zoneModel";
|
||||
import { action } from "./safeAction";
|
||||
import { actionClient } from "./safeAction";
|
||||
|
||||
const editZoneSchema = z.object({
|
||||
id: z.string(),
|
||||
zone: zoneSchema,
|
||||
});
|
||||
|
||||
export const editZone = action(editZoneSchema, async ({ id, zone }) => {
|
||||
try {
|
||||
await dbConnect();
|
||||
export const editZone = actionClient
|
||||
.schema(editZoneSchema)
|
||||
.action(async (input) => {
|
||||
const { id, zone } = input.parsedInput;
|
||||
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 = {
|
||||
...zone,
|
||||
userId: new ObjectId(user.user!.id!),
|
||||
};
|
||||
|
||||
const result = await collections.zones!.findOneAndUpdate(
|
||||
{ _id: new ObjectId(id), userId: new ObjectId(user.user!.id!) },
|
||||
{ $set: { _id: new ObjectId(id), ...zoneData } },
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
throw new Error("ERR_ZONE_UPDATE_FAILED");
|
||||
}
|
||||
|
||||
return {
|
||||
...omit(result, ["_id"]),
|
||||
id: result._id.toString(),
|
||||
userId: result.userId.toString(),
|
||||
};
|
||||
} catch (error) {
|
||||
errorLog(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const zoneData: ZoneModel = {
|
||||
...zone,
|
||||
userId: new ObjectId(user.user!.id!),
|
||||
};
|
||||
|
||||
const result = await collections.zones!.findOneAndUpdate(
|
||||
{ _id: new ObjectId(id), userId: new ObjectId(user.user!.id!) },
|
||||
{ $set: { _id: new ObjectId(id), ...zoneData } },
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
throw new Error("ERR_ZONE_UPDATE_FAILED");
|
||||
}
|
||||
|
||||
return {
|
||||
...omit(result, ["_id"]),
|
||||
id: result._id.toString(),
|
||||
userId: result.userId.toString(),
|
||||
};
|
||||
} catch (error) {
|
||||
errorLog(error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user