-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice.ts
44 lines (39 loc) · 1.03 KB
/
service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { gql } from "graphql-request";
import type { Flow } from "../../../types.js";
import { getClient } from "../../../client/index.js";
import type { Team } from "@opensystemslab/planx-core/types";
export const moveFlow = async (flowId: string, teamSlug: string) => {
const $client = getClient();
const team = await $client.team.getBySlug(teamSlug);
if (!team)
throw Error(
`Unable to find a team matching slug ${teamSlug}, exiting move`,
);
await updateFlow(flowId, team.id);
};
interface UpdateFlow {
flow: Pick<Flow, "id">;
}
const updateFlow = async (
flowId: Flow["id"],
teamId: Team["id"],
): Promise<Flow["id"]> => {
const { client: $client } = getClient();
const { flow } = await $client.request<UpdateFlow>(
gql`
mutation UpdateFlow($id: uuid!, $team_id: Int!) {
flow: update_flows_by_pk(
pk_columns: { id: $id }
_set: { team_id: $team_id }
) {
id
}
}
`,
{
id: flowId,
team_id: teamId,
},
);
return flow.id;
};