From 5168d67373a8ae3bba42d6139d5930190074692e Mon Sep 17 00:00:00 2001 From: qweliant Date: Thu, 9 May 2024 14:54:20 -0400 Subject: [PATCH] should turn the other awaits into Promisse.all statements so if any fails this throws instead of still creating --- core/app/(user)/communities/actions.ts | 34 ++++++++++++------- .../communities/getCommunityTableColumns.tsx | 2 ++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/app/(user)/communities/actions.ts b/core/app/(user)/communities/actions.ts index 6e606648b..b8b913f8c 100644 --- a/core/app/(user)/communities/actions.ts +++ b/core/app/(user)/communities/actions.ts @@ -66,7 +66,12 @@ export const createCommunity = defineServerAction(async function createCommunity .executeTakeFirst() ); const communityUUID = c.id as CommunitiesId; - const member = await db + + const pubTypeId: string = uuidv4(); + + const corePubSlugs = corePubFields.map((field) => field.slug); + + const memberPromise = db .insertInto("members") .values({ user_id: user.id as UsersId, @@ -76,33 +81,33 @@ export const createCommunity = defineServerAction(async function createCommunity .returning("id") .executeTakeFirst(); - const pubTypeId: string = uuidv4(); - - const corePubSlugs = corePubFields.map((field) => field.slug); - - const [title] = await db + const pubFieldsPromise = db .selectFrom("pub_fields") .selectAll() .where("pub_fields.slug", "in", corePubSlugs) .execute(); + const [fields, member] = await Promise.all([pubFieldsPromise, memberPromise]); await db .with("core_pub_type", (db) => db .insertInto("pub_types") .values({ id: pubTypeId as PubTypesId, - name: "Title Pub That Only List Titles", + name: "Submission ", community_id: c.id as CommunitiesId, }) .returning("id") ) .insertInto("_PubFieldToPubType") - .values((eb) => ({ - A: title.id, - B: eb.selectFrom("core_pub_type").select("id"), - })) + .values((eb) => + fields.map((fields) => ({ + A: fields.id, + B: eb.selectFrom("core_pub_type").select("id"), + })) + ) .execute(); + const stages = ( await db .insertInto("stages") @@ -226,9 +231,14 @@ export const createCommunity = defineServerAction(async function createCommunity .values((eb) => [ { pub_id: eb.selectFrom("new_pubs").select("new_pubs.id"), - field_id: title.id, + field_id: fields.find((field) => field.slug === "pubpub:title")!.id, value: '"The Activity of Slugs I. The Induction of Activity by Changing Temperatures"', }, + { + pub_id: eb.selectFrom("new_pubs").select("new_pubs.id"), + field_id: fields.find((field) => field.slug === "pubpub:content")!.id, + value: '"LONG LIVE THE SLUGS"', + }, ]) .execute(); } diff --git a/core/app/(user)/communities/getCommunityTableColumns.tsx b/core/app/(user)/communities/getCommunityTableColumns.tsx index 404912500..508e671e0 100644 --- a/core/app/(user)/communities/getCommunityTableColumns.tsx +++ b/core/app/(user)/communities/getCommunityTableColumns.tsx @@ -18,6 +18,7 @@ import { MoreVertical } from "ui/icon"; import { UserAndMemberships } from "~/lib/types"; import { RemoveCommunityButton } from "./RemoveCommunityButton"; +import Link from "next/link"; export type TableCommunity = { id: string; @@ -72,6 +73,7 @@ export const getCommunityTableColumns = ({ user }: { user: UserAndMemberships }) { header: ({ column }) => , accessorKey: "slug", + cell: ({ row }) => {row.original.slug}, }, { header: ({ column }) => ,