Skip to content

Commit 47f7819

Browse files
committed
add option to remove default worker group from project
1 parent 0af367f commit 47f7819

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

apps/webapp/app/routes/admin.api.v1.workers.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const RequestBodySchema = z.object({
1010
name: z.string().optional(),
1111
description: z.string().optional(),
1212
makeDefaultForProjectId: z.string().optional(),
13+
removeDefaultFromProject: z.boolean().default(false),
1314
});
1415

1516
export async function action({ request }: ActionFunctionArgs) {
@@ -36,7 +37,34 @@ export async function action({ request }: ActionFunctionArgs) {
3637

3738
try {
3839
const rawBody = await request.json();
39-
const { name, description, makeDefaultForProjectId } = RequestBodySchema.parse(rawBody ?? {});
40+
const { name, description, makeDefaultForProjectId, removeDefaultFromProject } =
41+
RequestBodySchema.parse(rawBody ?? {});
42+
43+
if (removeDefaultFromProject) {
44+
if (!makeDefaultForProjectId) {
45+
return json(
46+
{
47+
error:
48+
"makeDefaultForProjectId is required to remove default worker group from project",
49+
},
50+
{ status: 400 }
51+
);
52+
}
53+
54+
const updated = await removeDefaultWorkerGroupFromProject(makeDefaultForProjectId);
55+
56+
if (!updated.success) {
57+
return json(
58+
{ error: `failed to remove default worker group from project: ${updated.error}` },
59+
{ status: 400 }
60+
);
61+
}
62+
63+
return json({
64+
outcome: "removed default worker group from project",
65+
project: updated.project,
66+
});
67+
}
4068

4169
const existingWorkerGroup = await prisma.workerInstanceGroup.findFirst({
4270
where: {
@@ -119,6 +147,44 @@ async function createWorkerGroup(name: string | undefined, description: string |
119147
return await service.createWorkerGroup({ name, description });
120148
}
121149

150+
async function removeDefaultWorkerGroupFromProject(projectId: string) {
151+
const project = await prisma.project.findFirst({
152+
where: {
153+
id: projectId,
154+
},
155+
});
156+
157+
if (!project) {
158+
return {
159+
success: false,
160+
error: "project not found",
161+
};
162+
}
163+
164+
const [error] = await tryCatch(
165+
prisma.project.update({
166+
where: {
167+
id: projectId,
168+
},
169+
data: {
170+
defaultWorkerGroupId: null,
171+
},
172+
})
173+
);
174+
175+
if (error) {
176+
return {
177+
success: false,
178+
error: error instanceof Error ? error.message : error,
179+
};
180+
}
181+
182+
return {
183+
success: true,
184+
project,
185+
};
186+
}
187+
122188
async function setWorkerGroupAsDefaultForProject(
123189
workerGroupId: string,
124190
projectId: string

0 commit comments

Comments
 (0)