@@ -57,6 +57,14 @@ func (c *itemCreation) validateAssignments() error {
5757 if err := validation .ValidatePlanningAssignments (c .db , params .WorkspaceID , params .MilestoneIDs , params .IterationID ); err != nil {
5858 return err
5959 }
60+ labels := repository .NewLabelRepository (c .db )
61+ for _ , labelID := range params .LabelIDs {
62+ if _ , err := labels .GetByID (labelID ); errors .Is (err , repository .ErrNotFound ) {
63+ return & validation.ValidationError {Field : "label_ids" , Message : fmt .Sprintf ("Label %d not found" , labelID )}
64+ } else if err != nil {
65+ return fmt .Errorf ("validate label %d: %w" , labelID , err )
66+ }
67+ }
6068 if params .ValidatingUserID > 0 && params .AssigneeID != nil {
6169 actionable , err := c .assigneeCanAct ()
6270 if err != nil {
@@ -275,6 +283,11 @@ func (c *itemCreation) extendTransaction(tx database.Tx, itemID int) error {
275283 return fmt .Errorf ("failed to attach milestone %d to new item: %w" , milestoneID , err )
276284 }
277285 }
286+ if len (c .params .LabelIDs ) > 0 {
287+ if err := repository .NewLabelRepository (c .db ).ReplaceItemLabelsTx (c .ctx , tx , itemID , c .params .LabelIDs ); err != nil {
288+ return err
289+ }
290+ }
278291 if c .params .AfterCreate != nil {
279292 return c .params .AfterCreate (c .ctx , tx , itemID )
280293 }
0 commit comments