Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = { instances: NonNullable<IntegrationData>; token: string };

const getTitle = (pub: Props["instances"][number]["pubs"][number]) => {
const titleValue = pub.values.find((value) => {
return value.field.name === "Title";
return value.field.slug === "unjournal/title";
});
return titleValue?.value as string;
};
Expand Down
2 changes: 1 addition & 1 deletion core/app/c/[communitySlug]/stages/components/Assign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Props = {

const getTitle = (pub: Props["pub"]) => {
const titleValue = pub.values.find((value) => {
return value.field.name === "Title";
return value.field.slug === "unjournal/title";
});
return titleValue?.value as string;
};
Expand Down
2 changes: 1 addition & 1 deletion core/app/components/PubRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const groupPubChildrenByPubType = (pubs: PubPayload["children"]) => {

const getTitle = (pub: PubPayload["children"][number]) => {
const title = pub.values.find((value) => {
return value.field.name === "Title";
return value.field.slug === "unjournal/title";
});
return title?.value as string;
};
Expand Down
16 changes: 8 additions & 8 deletions core/lib/server/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const pubValuesInclude = {
orderBy: { createdAt: "desc" },
include: {
field: {
select: { name: true },
select: { slug: true },
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've just substituted slugs for names but kept the same "values" : { "<slug>": "<value>" } structure for pub responses. But I wonder if we should modify this structure so that we can include the name as well?

},
},
},
Expand All @@ -21,7 +21,7 @@ const recursivelyDenormalizePubValues = async (
pub: Prisma.PubGetPayload<RecursiveInclude<"children", typeof pubValuesInclude>>
): Promise<GetPubResponseBody> => {
const values = pub.values.reduce((prev, curr) => {
prev[curr.field.name] = curr.value;
prev[curr.field.slug] = curr.value;
return prev;
}, {} as Record<string, Prisma.JsonValue>);
const children = await Promise.all(pub.children?.map(recursivelyDenormalizePubValues));
Expand All @@ -39,14 +39,14 @@ export const getPub = async (pubId: string, depth = 0): Promise<GetPubResponseBo

const InstanceNotFoundError = new NotFoundError("Integration instance not found");
const PubNotFoundError = new NotFoundError("Pub not found");
const PubFieldNamesNotFoundError = new NotFoundError("Pub fields not found");
const PubFieldSlugsNotFoundError = new NotFoundError("Pub fields not found");

const normalizePubValues = async (values: CreatePubRequestBody["values"], pubTypeId?: string) => {
const pubFieldNames = Object.keys(values);
const pubFieldSlugs = Object.keys(values);
const pubFieldIds = await prisma.pubField.findMany({
where: {
name: {
in: pubFieldNames,
slug: {
in: pubFieldSlugs,
},
pubTypes: {
some: {
Expand All @@ -57,13 +57,13 @@ const normalizePubValues = async (values: CreatePubRequestBody["values"], pubTyp
});

if (!pubFieldIds) {
throw PubFieldNamesNotFoundError;
throw PubFieldSlugsNotFoundError;
}

const normalizedValues = pubFieldIds.map((field) => {
return {
fieldId: field.id,
value: values[field.name],
value: values[field.slug],
};
});

Expand Down
Loading