master
Evan Chen 2021-12-24 22:31:29 +08:00
parent 8f207bf356
commit 0d58e402f8
2 changed files with 16 additions and 1 deletions

View File

@ -19,7 +19,6 @@ type Calendar struct {
Name string `gorm:"index:idx_cal,unique"`
Description string
ExtLink string
Timezone string

View File

@ -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
})
}