Skip to content

Commit

Permalink
fix: Remove manual population of creator ID (#3884)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Oct 31, 2024
1 parent 68e989a commit 447e33e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
9 changes: 4 additions & 5 deletions api.planx.uk/helpers.ts
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

0 comments on commit 447e33e

Please sign in to comment.