mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-30 17:47:24 +01:00
1004 lines
29 KiB
Go
1004 lines
29 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/authtokens"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/group"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/user"
|
|
)
|
|
|
|
// UserUpdate is the builder for updating User entities.
|
|
type UserUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *UserMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the UserUpdate builder.
|
|
func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *UserUpdate) SetName(v string) *UserUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableName(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (_u *UserUpdate) SetEmail(v string) *UserUpdate {
|
|
_u.mutation.SetEmail(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableEmail(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetEmail(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (_u *UserUpdate) SetPassword(v string) *UserUpdate {
|
|
_u.mutation.SetPassword(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePassword sets the "password" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillablePassword(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetPassword(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetIsSuperuser sets the "is_superuser" field.
|
|
func (_u *UserUpdate) SetIsSuperuser(v bool) *UserUpdate {
|
|
_u.mutation.SetIsSuperuser(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsSuperuser sets the "is_superuser" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableIsSuperuser(v *bool) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetIsSuperuser(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSuperuser sets the "superuser" field.
|
|
func (_u *UserUpdate) SetSuperuser(v bool) *UserUpdate {
|
|
_u.mutation.SetSuperuser(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSuperuser sets the "superuser" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableSuperuser(v *bool) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetSuperuser(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (_u *UserUpdate) SetRole(v user.Role) *UserUpdate {
|
|
_u.mutation.SetRole(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRole sets the "role" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableRole(v *user.Role) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetRole(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetActivatedOn sets the "activated_on" field.
|
|
func (_u *UserUpdate) SetActivatedOn(v time.Time) *UserUpdate {
|
|
_u.mutation.SetActivatedOn(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActivatedOn sets the "activated_on" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableActivatedOn(v *time.Time) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetActivatedOn(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearActivatedOn clears the value of the "activated_on" field.
|
|
func (_u *UserUpdate) ClearActivatedOn() *UserUpdate {
|
|
_u.mutation.ClearActivatedOn()
|
|
return _u
|
|
}
|
|
|
|
// SetSettings sets the "settings" field.
|
|
func (_u *UserUpdate) SetSettings(v schema.UserSettings) *UserUpdate {
|
|
_u.mutation.SetSettings(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableSettings(v *schema.UserSettings) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetSettings(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearSettings clears the value of the "settings" field.
|
|
func (_u *UserUpdate) ClearSettings() *UserUpdate {
|
|
_u.mutation.ClearSettings()
|
|
return _u
|
|
}
|
|
|
|
// SetGroupID sets the "group" edge to the Group entity by ID.
|
|
func (_u *UserUpdate) SetGroupID(id uuid.UUID) *UserUpdate {
|
|
_u.mutation.SetGroupID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetGroup sets the "group" edge to the Group entity.
|
|
func (_u *UserUpdate) SetGroup(v *Group) *UserUpdate {
|
|
return _u.SetGroupID(v.ID)
|
|
}
|
|
|
|
// AddAuthTokenIDs adds the "auth_tokens" edge to the AuthTokens entity by IDs.
|
|
func (_u *UserUpdate) AddAuthTokenIDs(ids ...uuid.UUID) *UserUpdate {
|
|
_u.mutation.AddAuthTokenIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAuthTokens adds the "auth_tokens" edges to the AuthTokens entity.
|
|
func (_u *UserUpdate) AddAuthTokens(v ...*AuthTokens) *UserUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAuthTokenIDs(ids...)
|
|
}
|
|
|
|
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by IDs.
|
|
func (_u *UserUpdate) AddNotifierIDs(ids ...uuid.UUID) *UserUpdate {
|
|
_u.mutation.AddNotifierIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddNotifiers adds the "notifiers" edges to the Notifier entity.
|
|
func (_u *UserUpdate) AddNotifiers(v ...*Notifier) *UserUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddNotifierIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the UserMutation object of the builder.
|
|
func (_u *UserUpdate) Mutation() *UserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearGroup clears the "group" edge to the Group entity.
|
|
func (_u *UserUpdate) ClearGroup() *UserUpdate {
|
|
_u.mutation.ClearGroup()
|
|
return _u
|
|
}
|
|
|
|
// ClearAuthTokens clears all "auth_tokens" edges to the AuthTokens entity.
|
|
func (_u *UserUpdate) ClearAuthTokens() *UserUpdate {
|
|
_u.mutation.ClearAuthTokens()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAuthTokenIDs removes the "auth_tokens" edge to AuthTokens entities by IDs.
|
|
func (_u *UserUpdate) RemoveAuthTokenIDs(ids ...uuid.UUID) *UserUpdate {
|
|
_u.mutation.RemoveAuthTokenIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAuthTokens removes "auth_tokens" edges to AuthTokens entities.
|
|
func (_u *UserUpdate) RemoveAuthTokens(v ...*AuthTokens) *UserUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAuthTokenIDs(ids...)
|
|
}
|
|
|
|
// ClearNotifiers clears all "notifiers" edges to the Notifier entity.
|
|
func (_u *UserUpdate) ClearNotifiers() *UserUpdate {
|
|
_u.mutation.ClearNotifiers()
|
|
return _u
|
|
}
|
|
|
|
// RemoveNotifierIDs removes the "notifiers" edge to Notifier entities by IDs.
|
|
func (_u *UserUpdate) RemoveNotifierIDs(ids ...uuid.UUID) *UserUpdate {
|
|
_u.mutation.RemoveNotifierIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveNotifiers removes "notifiers" edges to Notifier entities.
|
|
func (_u *UserUpdate) RemoveNotifiers(v ...*Notifier) *UserUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveNotifierIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *UserUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *UserUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *UserUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *UserUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := user.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *UserUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := user.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Email(); ok {
|
|
if err := user.EmailValidator(v); err != nil {
|
|
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Password(); ok {
|
|
if err := user.PasswordValidator(v); err != nil {
|
|
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "User.password": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Role(); ok {
|
|
if err := user.RoleValidator(v); err != nil {
|
|
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "User.group"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(user.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Email(); ok {
|
|
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Password(); ok {
|
|
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.IsSuperuser(); ok {
|
|
_spec.SetField(user.FieldIsSuperuser, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Superuser(); ok {
|
|
_spec.SetField(user.FieldSuperuser, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Role(); ok {
|
|
_spec.SetField(user.FieldRole, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.ActivatedOn(); ok {
|
|
_spec.SetField(user.FieldActivatedOn, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.ActivatedOnCleared() {
|
|
_spec.ClearField(user.FieldActivatedOn, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.Settings(); ok {
|
|
_spec.SetField(user.FieldSettings, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.SettingsCleared() {
|
|
_spec.ClearField(user.FieldSettings, field.TypeJSON)
|
|
}
|
|
if _u.mutation.GroupCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: user.GroupTable,
|
|
Columns: []string{user.GroupColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: user.GroupTable,
|
|
Columns: []string{user.GroupColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.AuthTokensCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.AuthTokensTable,
|
|
Columns: []string{user.AuthTokensColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAuthTokensIDs(); len(nodes) > 0 && !_u.mutation.AuthTokensCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.AuthTokensTable,
|
|
Columns: []string{user.AuthTokensColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.AuthTokensIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.AuthTokensTable,
|
|
Columns: []string{user.AuthTokensColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.NotifiersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.NotifiersTable,
|
|
Columns: []string{user.NotifiersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifier.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedNotifiersIDs(); len(nodes) > 0 && !_u.mutation.NotifiersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.NotifiersTable,
|
|
Columns: []string{user.NotifiersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifier.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.NotifiersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.NotifiersTable,
|
|
Columns: []string{user.NotifiersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifier.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{user.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// UserUpdateOne is the builder for updating a single User entity.
|
|
type UserUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *UserMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *UserUpdateOne) SetName(v string) *UserUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableName(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (_u *UserUpdateOne) SetEmail(v string) *UserUpdateOne {
|
|
_u.mutation.SetEmail(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableEmail(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetEmail(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (_u *UserUpdateOne) SetPassword(v string) *UserUpdateOne {
|
|
_u.mutation.SetPassword(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePassword sets the "password" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillablePassword(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetPassword(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetIsSuperuser sets the "is_superuser" field.
|
|
func (_u *UserUpdateOne) SetIsSuperuser(v bool) *UserUpdateOne {
|
|
_u.mutation.SetIsSuperuser(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsSuperuser sets the "is_superuser" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableIsSuperuser(v *bool) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetIsSuperuser(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSuperuser sets the "superuser" field.
|
|
func (_u *UserUpdateOne) SetSuperuser(v bool) *UserUpdateOne {
|
|
_u.mutation.SetSuperuser(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSuperuser sets the "superuser" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableSuperuser(v *bool) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetSuperuser(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetRole sets the "role" field.
|
|
func (_u *UserUpdateOne) SetRole(v user.Role) *UserUpdateOne {
|
|
_u.mutation.SetRole(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRole sets the "role" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableRole(v *user.Role) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetRole(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetActivatedOn sets the "activated_on" field.
|
|
func (_u *UserUpdateOne) SetActivatedOn(v time.Time) *UserUpdateOne {
|
|
_u.mutation.SetActivatedOn(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActivatedOn sets the "activated_on" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableActivatedOn(v *time.Time) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetActivatedOn(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearActivatedOn clears the value of the "activated_on" field.
|
|
func (_u *UserUpdateOne) ClearActivatedOn() *UserUpdateOne {
|
|
_u.mutation.ClearActivatedOn()
|
|
return _u
|
|
}
|
|
|
|
// SetSettings sets the "settings" field.
|
|
func (_u *UserUpdateOne) SetSettings(v schema.UserSettings) *UserUpdateOne {
|
|
_u.mutation.SetSettings(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableSettings(v *schema.UserSettings) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetSettings(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearSettings clears the value of the "settings" field.
|
|
func (_u *UserUpdateOne) ClearSettings() *UserUpdateOne {
|
|
_u.mutation.ClearSettings()
|
|
return _u
|
|
}
|
|
|
|
// SetGroupID sets the "group" edge to the Group entity by ID.
|
|
func (_u *UserUpdateOne) SetGroupID(id uuid.UUID) *UserUpdateOne {
|
|
_u.mutation.SetGroupID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetGroup sets the "group" edge to the Group entity.
|
|
func (_u *UserUpdateOne) SetGroup(v *Group) *UserUpdateOne {
|
|
return _u.SetGroupID(v.ID)
|
|
}
|
|
|
|
// AddAuthTokenIDs adds the "auth_tokens" edge to the AuthTokens entity by IDs.
|
|
func (_u *UserUpdateOne) AddAuthTokenIDs(ids ...uuid.UUID) *UserUpdateOne {
|
|
_u.mutation.AddAuthTokenIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAuthTokens adds the "auth_tokens" edges to the AuthTokens entity.
|
|
func (_u *UserUpdateOne) AddAuthTokens(v ...*AuthTokens) *UserUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAuthTokenIDs(ids...)
|
|
}
|
|
|
|
// AddNotifierIDs adds the "notifiers" edge to the Notifier entity by IDs.
|
|
func (_u *UserUpdateOne) AddNotifierIDs(ids ...uuid.UUID) *UserUpdateOne {
|
|
_u.mutation.AddNotifierIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddNotifiers adds the "notifiers" edges to the Notifier entity.
|
|
func (_u *UserUpdateOne) AddNotifiers(v ...*Notifier) *UserUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddNotifierIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the UserMutation object of the builder.
|
|
func (_u *UserUpdateOne) Mutation() *UserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearGroup clears the "group" edge to the Group entity.
|
|
func (_u *UserUpdateOne) ClearGroup() *UserUpdateOne {
|
|
_u.mutation.ClearGroup()
|
|
return _u
|
|
}
|
|
|
|
// ClearAuthTokens clears all "auth_tokens" edges to the AuthTokens entity.
|
|
func (_u *UserUpdateOne) ClearAuthTokens() *UserUpdateOne {
|
|
_u.mutation.ClearAuthTokens()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAuthTokenIDs removes the "auth_tokens" edge to AuthTokens entities by IDs.
|
|
func (_u *UserUpdateOne) RemoveAuthTokenIDs(ids ...uuid.UUID) *UserUpdateOne {
|
|
_u.mutation.RemoveAuthTokenIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAuthTokens removes "auth_tokens" edges to AuthTokens entities.
|
|
func (_u *UserUpdateOne) RemoveAuthTokens(v ...*AuthTokens) *UserUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAuthTokenIDs(ids...)
|
|
}
|
|
|
|
// ClearNotifiers clears all "notifiers" edges to the Notifier entity.
|
|
func (_u *UserUpdateOne) ClearNotifiers() *UserUpdateOne {
|
|
_u.mutation.ClearNotifiers()
|
|
return _u
|
|
}
|
|
|
|
// RemoveNotifierIDs removes the "notifiers" edge to Notifier entities by IDs.
|
|
func (_u *UserUpdateOne) RemoveNotifierIDs(ids ...uuid.UUID) *UserUpdateOne {
|
|
_u.mutation.RemoveNotifierIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveNotifiers removes "notifiers" edges to Notifier entities.
|
|
func (_u *UserUpdateOne) RemoveNotifiers(v ...*Notifier) *UserUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveNotifierIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the UserUpdate builder.
|
|
func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated User entity.
|
|
func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *UserUpdateOne) SaveX(ctx context.Context) *User {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *UserUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *UserUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *UserUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := user.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *UserUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := user.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Email(); ok {
|
|
if err := user.EmailValidator(v); err != nil {
|
|
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Password(); ok {
|
|
if err := user.PasswordValidator(v); err != nil {
|
|
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "User.password": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Role(); ok {
|
|
if err := user.RoleValidator(v); err != nil {
|
|
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "User.group"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
|
for _, f := range fields {
|
|
if !user.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != user.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(user.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Email(); ok {
|
|
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Password(); ok {
|
|
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.IsSuperuser(); ok {
|
|
_spec.SetField(user.FieldIsSuperuser, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Superuser(); ok {
|
|
_spec.SetField(user.FieldSuperuser, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Role(); ok {
|
|
_spec.SetField(user.FieldRole, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.ActivatedOn(); ok {
|
|
_spec.SetField(user.FieldActivatedOn, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.ActivatedOnCleared() {
|
|
_spec.ClearField(user.FieldActivatedOn, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.Settings(); ok {
|
|
_spec.SetField(user.FieldSettings, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.SettingsCleared() {
|
|
_spec.ClearField(user.FieldSettings, field.TypeJSON)
|
|
}
|
|
if _u.mutation.GroupCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: user.GroupTable,
|
|
Columns: []string{user.GroupColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: user.GroupTable,
|
|
Columns: []string{user.GroupColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.AuthTokensCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.AuthTokensTable,
|
|
Columns: []string{user.AuthTokensColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAuthTokensIDs(); len(nodes) > 0 && !_u.mutation.AuthTokensCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.AuthTokensTable,
|
|
Columns: []string{user.AuthTokensColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.AuthTokensIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.AuthTokensTable,
|
|
Columns: []string{user.AuthTokensColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.NotifiersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.NotifiersTable,
|
|
Columns: []string{user.NotifiersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifier.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedNotifiersIDs(); len(nodes) > 0 && !_u.mutation.NotifiersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.NotifiersTable,
|
|
Columns: []string{user.NotifiersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifier.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.NotifiersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.NotifiersTable,
|
|
Columns: []string{user.NotifiersColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifier.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &User{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{user.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|