snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
33
timespan/stop.go
Normal file
33
timespan/stop.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package timespan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/traggo/server/auth"
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
// StopTimeSpan sets an end date to an existing time span.
|
||||
func (r *ResolverForTimeSpan) StopTimeSpan(ctx context.Context, id int, end model.Time) (*gqlmodel.TimeSpan, error) {
|
||||
old := &model.TimeSpan{ID: id}
|
||||
|
||||
if r.DB.Preload("Tags").Where("user_id = ?", auth.GetUser(ctx).ID).Find(old).RecordNotFound() {
|
||||
return nil, fmt.Errorf("time span with id %d does not exist", id)
|
||||
}
|
||||
|
||||
if old.EndUTC != nil {
|
||||
return nil, fmt.Errorf("timespan with id %d has already an end date", id)
|
||||
}
|
||||
|
||||
utc := end.UTC()
|
||||
old.EndUTC = &utc
|
||||
userTime := end.OmitTimeZone()
|
||||
old.EndUserTime = &userTime
|
||||
r.DB.Where("time_span_id = ?", old.ID).Delete(new(model.TimeSpanTag))
|
||||
r.DB.Save(old)
|
||||
|
||||
external := timeSpanToExternal(*old)
|
||||
return external, nil
|
||||
}
|
||||
Reference in New Issue
Block a user