Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove manual population of creator ID #3884

Merged
merged 1 commit into from
Oct 31, 2024
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
9 changes: 4 additions & 5 deletions api.planx.uk/helpers.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to overcomplicate this but, would this be a good time to switch this to the CreateFlow mutation from planx-core so it matches the editor? @DafyddLlyr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, makes sense to standardise this I think and it could have avoided this issue.

As this is currently blocking work, I'd vote for moving this forward just now and getting to prod and picking up this refactor as a follow up?

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Flow, Node } from "./types.js";
import type { FlowGraph } from "@opensystemslab/planx-core/types";
import { ComponentType } from "@opensystemslab/planx-core/types";
import { $public, getClient } from "./client/index.js";
import { userContext } from "./modules/auth/middleware.js";

export interface FlowData {
slug: string;
Expand Down Expand Up @@ -67,10 +68,11 @@ const insertFlow = async (
slug: string,
name: string,
flowData: Flow["data"],
creatorId?: number,
copiedFrom?: Flow["id"],
) => {
const { client: $client } = getClient();
const userId = userContext.getStore()?.user?.sub;

try {
const {
flow: { id },
Expand All @@ -81,7 +83,6 @@ const insertFlow = async (
$slug: String!
$name: String!
$data: jsonb = {}
$creator_id: Int
$copied_from: uuid
) {
flow: insert_flows_one(
Expand All @@ -91,7 +92,6 @@ const insertFlow = async (
name: $name
data: $data
version: 1
creator_id: $creator_id
copied_from: $copied_from
}
) {
Expand All @@ -104,7 +104,6 @@ const insertFlow = async (
slug: slug,
name: name,
data: flowData,
creator_id: creatorId,
copied_from: copiedFrom,
},
);
Expand All @@ -113,7 +112,7 @@ const insertFlow = async (
return { id };
} catch (error) {
throw Error(
`User ${creatorId} failed to insert flow to teamId ${teamId}. Please check permissions. Error: ${error}`,
`User ${userId} failed to insert flow to teamId ${teamId}. Please check permissions. Error: ${error}`,
);
}
};
Expand Down
12 changes: 1 addition & 11 deletions api.planx.uk/modules/flows/copyFlow/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { makeUniqueFlow, getFlowData, insertFlow } from "../../../helpers.js";
import { userContext } from "../../auth/middleware.js";

const copyFlow = async (
flowId: string,
Expand All @@ -16,18 +15,9 @@ const copyFlow = async (
if (insert) {
const newSlug = flow.slug + "-copy";
const newName = flow.name + " (copy)";
const creatorId = userContext.getStore()?.user?.sub;
if (!creatorId) throw Error("User details missing from request");

// Insert the flow and an associated operation
await insertFlow(
flow.team_id,
newSlug,
newName,
uniqueFlowData,
parseInt(creatorId),
flowId,
);
await insertFlow(flow.team_id, newSlug, newName, uniqueFlowData, flowId);
}

return { flow, uniqueFlowData };
Expand Down
Loading