Skip to content

Commit

Permalink
Addressed CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
OAGr committed Apr 10, 2024
1 parent 675cfcf commit 44c61af
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-- AlterTable
ALTER TABLE "ModelExport" ADD COLUMN "isCurrent" BOOLEAN NOT NULL DEFAULT false;
UPDATE "ModelExport" SET "isCurrent" = true WHERE "modelRevisionId" IN (SELECT "currentRevisionId" FROM "Model");
4 changes: 2 additions & 2 deletions packages/hub/src/app/users/[username]/UserLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
newModelRoute,
userDefinitionsRoute,
userGroupsRoute,
userModelExportRoute,
userModelExportsRoute,
userRoute,
} from "@/routes";

Expand Down Expand Up @@ -119,7 +119,7 @@ export const UserLayout: FC<
{isMe || user.modelExports.edges.length ? (
<StyledTabLink
name="Exports"
href={userModelExportRoute({ username: user.username })}
href={userModelExportsRoute({ username: user.username })}
/>
) : null}
{isMe || user.relativeValuesDefinitions.edges.length ? (
Expand Down
43 changes: 0 additions & 43 deletions packages/hub/src/graphql/helpers/modelExportHelpers.ts

This file was deleted.

36 changes: 22 additions & 14 deletions packages/hub/src/graphql/queries/exports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import merge from "lodash/merge";

import { builder } from "@/graphql/builder";
import { prisma } from "@/prisma";

import { modelExportWhereHasAccess } from "../helpers/modelExportHelpers";
import { modelWhereHasAccess } from "../helpers/modelHelpers";
import { ModelExport, ModelExportConnection } from "../types/ModelExport";

const ModelExportQueryInput = builder.inputType("ModelExportQueryInput", {
Expand All @@ -22,22 +24,28 @@ builder.queryField("modelExports", (t) =>
},
resolve: (query, _, { input }, { session }) => {
const modelId = input?.modelId;

const queries = merge(
{},
{ modelRevision: { model: modelWhereHasAccess(session) } },
modelId && {
modelRevision: {
modelId: modelId,
},
},
input?.owner && {
modelRevision: { model: { owner: { slug: input.owner } } },
},
input &&
input.variableName && {
variableName: input.variableName,
}
);

return prisma.modelExport.findMany({
...query,
where: {
...modelExportWhereHasAccess(session),
...(modelId && {
modelRevision: {
modelId: modelId,
},
}),
...(input &&
input.variableName && {
variableName: input.variableName,
}),
...(input?.owner && {
modelRevision: { model: { owner: { slug: input.owner } } },
}),
...queries,
isCurrent: true,
},
orderBy: {
Expand Down
4 changes: 2 additions & 2 deletions packages/hub/src/graphql/types/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export const Group = builder.prismaNode("Group", {
},
},
}),
resolve: (user, args, ctx) => {
resolve: (group, args, ctx) => {
const exports =
user.asOwner?.models
group.asOwner?.models
.map((model) => model.currentRevision?.exports ?? [])
.flat() ?? [];
return modelExportConnectionHelpers.resolve(exports, args, ctx);
Expand Down

0 comments on commit 44c61af

Please sign in to comment.