diff --git a/calendar/calendar.go b/calendar/calendar.go index 7ee03ac..b1ad079 100644 --- a/calendar/calendar.go +++ b/calendar/calendar.go @@ -19,7 +19,6 @@ type Calendar struct { Name string `gorm:"index:idx_cal,unique"` Description string - ExtLink string Timezone string diff --git a/calendar/util.go b/calendar/util.go index 1ba8a3a..62dd906 100644 --- a/calendar/util.go +++ b/calendar/util.go @@ -2,6 +2,7 @@ package calendar import ( "github.com/gin-gonic/gin" + "gorm.io/gorm" "kumoly.io/kumoly/app/auth" "kumoly.io/kumoly/app/errors" ) @@ -33,3 +34,18 @@ func HasEventAccess(c *gin.Context, e *Event, cid string) error { } return nil } + +func ChangeCalGroup(cal_id, to string) error { + return db.Transaction(func(tx *gorm.DB) error { + affected := tx.Exec(`update events set group_id = ( + select id from groups where name = ? + ) where calendar_id = ?`, to, cal_id).RowsAffected + if affected == 0 { + return errors.ErrorNotFound + } + tx.Exec(`update events set group_id = ( + select id from groups where name = ? + ) where calendar_id = ?`, to, cal_id) + return nil + }) +}