enables schema saving in db, initial refactor of db schema for revisions
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import { prisma } from "@/prisma/prismaClient";
|
||||
import { isEmailVerified } from "@/util/isEmailVerified";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export const createSchema = async (form: FormData) => {
|
||||
const name = form.get("name")?.toString();
|
||||
const gsId = form.get("gsId")?.toString();
|
||||
|
||||
const session = await auth();
|
||||
|
||||
if (!name || !gsId || !session?.user?.id || !isEmailVerified(session.user.id))
|
||||
return;
|
||||
|
||||
const { id } = await prisma.schema.create({
|
||||
data: {
|
||||
name,
|
||||
schema: "{}",
|
||||
types: "{}",
|
||||
version: 0,
|
||||
gameSystemId: gsId,
|
||||
authorId: session.user.id,
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
redirect(`/game-systems/${gsId}/schema/${id}`);
|
||||
};
|
@@ -1,20 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/prisma/prismaClient";
|
||||
|
||||
export const findSchema = async (id: string) => {
|
||||
const schema = await prisma.schema.findFirst({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
gameSystem: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return schema;
|
||||
};
|
79
actions/Schemas/index.ts
Normal file
79
actions/Schemas/index.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
"use server";
|
||||
import { auth } from "@/auth";
|
||||
import { isEmailVerified } from "@/util/isEmailVerified";
|
||||
import { redirect } from "next/navigation";
|
||||
import { prisma } from "@/prisma/prismaClient";
|
||||
|
||||
export const saveSchemaDb = async (s: Schema) => {
|
||||
const sesh = await auth();
|
||||
if (!sesh?.user?.id) return;
|
||||
|
||||
const { id } = await prisma.schema.upsert({
|
||||
// data: {
|
||||
// ...s,
|
||||
// },
|
||||
create: {
|
||||
...s,
|
||||
version: 0,
|
||||
authorId: sesh.user.id,
|
||||
id: undefined,
|
||||
},
|
||||
update: s,
|
||||
where: {
|
||||
id: s.id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
redirect(`/game-systems/${s.gameSystemId}/schema/${id}`);
|
||||
};
|
||||
|
||||
export const findSchema = async (id: string): Promise<Schema | null> => {
|
||||
const schema = await prisma.schema.findFirst({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
// include: {
|
||||
// gameSystem: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// name: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
schema: true,
|
||||
types: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!schema) return null;
|
||||
|
||||
return schema as Schema;
|
||||
};
|
||||
|
||||
export const createSchema = async (form: FormData) => {
|
||||
const name = form.get("name")?.toString();
|
||||
const gsId = form.get("gsId")?.toString();
|
||||
|
||||
const session = await auth();
|
||||
|
||||
if (!name || !gsId || !session?.user?.id || !isEmailVerified(session.user.id))
|
||||
return;
|
||||
|
||||
const { id } = await prisma.schema.create({
|
||||
data: {
|
||||
name,
|
||||
schema: "{}",
|
||||
types: "{}",
|
||||
version: 0,
|
||||
gameSystemId: gsId,
|
||||
authorId: session.user.id,
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
redirect(`/game-systems/${gsId}/schema/${id}`);
|
||||
};
|
Reference in New Issue
Block a user