Skip to content

Commit

Permalink
should turn the other awaits into Promisse.all statements so if any f…
Browse files Browse the repository at this point in the history
…ails this throws instead of still creating
  • Loading branch information
qweliant committed May 9, 2024
1 parent a62ac89 commit 5168d67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
34 changes: 22 additions & 12 deletions core/app/(user)/communities/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions core/app/(user)/communities/getCommunityTableColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +73,7 @@ export const getCommunityTableColumns = ({ user }: { user: UserAndMemberships })
{
header: ({ column }) => <DataTableColumnHeader column={column} title="Slug" />,
accessorKey: "slug",
cell: ({ row }) => <Link href={`/communities/${row.getValue("slug")}`}>{row.original.slug}</Link>,
},
{
header: ({ column }) => <DataTableColumnHeader column={column} title="Created" />,
Expand Down

0 comments on commit 5168d67

Please sign in to comment.