@@ -102,6 +102,18 @@ def get(self, request, slug, project_id, pk=None):
102102
103103 @check_feature_flag (FeatureFlag .ISSUE_TYPES )
104104 def post (self , request , slug , project_id ):
105+ issue_types = IssueType .objects .filter (
106+ workspace__slug = slug ,
107+ project_issue_types__project_id = project_id ,
108+ is_epic = False ,
109+ ).values_list ("name" , flat = True )
110+
111+ if request .data .get ("name" ) in issue_types :
112+ return Response (
113+ {"error" : "Issue type with this name already exists" },
114+ status = status .HTTP_400_BAD_REQUEST ,
115+ )
116+
105117 # Fetch the project
106118 project = Project .objects .get (pk = project_id )
107119 # Create a new issue type
@@ -261,7 +273,9 @@ def post(self, request, slug, project_id):
261273 )
262274 .annotate (
263275 issue_exists = Exists (
264- Issue .objects .filter (project_id = project_id , type_id = OuterRef ("pk" ))
276+ Issue .objects .filter (
277+ project_id = project_id , type_id = OuterRef ("pk" )
278+ )
265279 )
266280 )
267281 .annotate (
@@ -289,9 +303,7 @@ def post(self, request, slug, project_id):
289303 "is_epic" : work_item_type .is_epic ,
290304 }
291305 WorkitemTemplate .objects .filter (
292- project_id = project_id ,
293- workspace__slug = slug ,
294- type__exact = {},
306+ project_id = project_id , workspace__slug = slug , type__exact = {}
295307 ).update (type = work_item_type_template_schema )
296308
297309 # Serialize the data
@@ -371,9 +383,7 @@ def post(self, request, slug, project_id):
371383 "is_epic" : work_item_type .is_epic ,
372384 }
373385 WorkitemTemplate .objects .filter (
374- project_id = project_id ,
375- workspace__slug = slug ,
376- type__exact = {},
386+ project_id = project_id , workspace__slug = slug , type__exact = {}
377387 ).update (type = work_item_type_template_schema )
378388
379389 # Serialize the data
0 commit comments