@@ -10,6 +10,7 @@ const RequestBodySchema = z.object({
10
10
name : z . string ( ) . optional ( ) ,
11
11
description : z . string ( ) . optional ( ) ,
12
12
makeDefaultForProjectId : z . string ( ) . optional ( ) ,
13
+ removeDefaultFromProject : z . boolean ( ) . default ( false ) ,
13
14
} ) ;
14
15
15
16
export async function action ( { request } : ActionFunctionArgs ) {
@@ -36,7 +37,34 @@ export async function action({ request }: ActionFunctionArgs) {
36
37
37
38
try {
38
39
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
+ }
40
68
41
69
const existingWorkerGroup = await prisma . workerInstanceGroup . findFirst ( {
42
70
where : {
@@ -119,6 +147,44 @@ async function createWorkerGroup(name: string | undefined, description: string |
119
147
return await service . createWorkerGroup ( { name, description } ) ;
120
148
}
121
149
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
+
122
188
async function setWorkerGroupAsDefaultForProject (
123
189
workerGroupId : string ,
124
190
projectId : string
0 commit comments