rano/db/ent/user_update.go
Ankit Patial 26a00c9f7c working on auth.
mailer, basic setup with html template and a dev treansport
2024-11-15 21:42:15 +05:30

1169 lines
34 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"
"gitserver.in/patialtech/rano/db/ent/audit"
"gitserver.in/patialtech/rano/db/ent/predicate"
"gitserver.in/patialtech/rano/db/ent/user"
"gitserver.in/patialtech/rano/db/ent/usersession"
)
// 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 (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
uu.mutation.Where(ps...)
return uu
}
// SetUpdatedAt sets the "updated_at" field.
func (uu *UserUpdate) SetUpdatedAt(t time.Time) *UserUpdate {
uu.mutation.SetUpdatedAt(t)
return uu
}
// SetEmail sets the "email" field.
func (uu *UserUpdate) SetEmail(s string) *UserUpdate {
uu.mutation.SetEmail(s)
return uu
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (uu *UserUpdate) SetNillableEmail(s *string) *UserUpdate {
if s != nil {
uu.SetEmail(*s)
}
return uu
}
// SetEmailVerified sets the "email_verified" field.
func (uu *UserUpdate) SetEmailVerified(b bool) *UserUpdate {
uu.mutation.SetEmailVerified(b)
return uu
}
// SetNillableEmailVerified sets the "email_verified" field if the given value is not nil.
func (uu *UserUpdate) SetNillableEmailVerified(b *bool) *UserUpdate {
if b != nil {
uu.SetEmailVerified(*b)
}
return uu
}
// SetPhone sets the "phone" field.
func (uu *UserUpdate) SetPhone(s string) *UserUpdate {
uu.mutation.SetPhone(s)
return uu
}
// SetNillablePhone sets the "phone" field if the given value is not nil.
func (uu *UserUpdate) SetNillablePhone(s *string) *UserUpdate {
if s != nil {
uu.SetPhone(*s)
}
return uu
}
// ClearPhone clears the value of the "phone" field.
func (uu *UserUpdate) ClearPhone() *UserUpdate {
uu.mutation.ClearPhone()
return uu
}
// SetPhoneVerified sets the "phone_verified" field.
func (uu *UserUpdate) SetPhoneVerified(b bool) *UserUpdate {
uu.mutation.SetPhoneVerified(b)
return uu
}
// SetNillablePhoneVerified sets the "phone_verified" field if the given value is not nil.
func (uu *UserUpdate) SetNillablePhoneVerified(b *bool) *UserUpdate {
if b != nil {
uu.SetPhoneVerified(*b)
}
return uu
}
// SetPwdSalt sets the "pwd_salt" field.
func (uu *UserUpdate) SetPwdSalt(s string) *UserUpdate {
uu.mutation.SetPwdSalt(s)
return uu
}
// SetNillablePwdSalt sets the "pwd_salt" field if the given value is not nil.
func (uu *UserUpdate) SetNillablePwdSalt(s *string) *UserUpdate {
if s != nil {
uu.SetPwdSalt(*s)
}
return uu
}
// SetPwdHash sets the "pwd_hash" field.
func (uu *UserUpdate) SetPwdHash(s string) *UserUpdate {
uu.mutation.SetPwdHash(s)
return uu
}
// SetNillablePwdHash sets the "pwd_hash" field if the given value is not nil.
func (uu *UserUpdate) SetNillablePwdHash(s *string) *UserUpdate {
if s != nil {
uu.SetPwdHash(*s)
}
return uu
}
// SetLoginFailedCount sets the "login_failed_count" field.
func (uu *UserUpdate) SetLoginFailedCount(u uint8) *UserUpdate {
uu.mutation.ResetLoginFailedCount()
uu.mutation.SetLoginFailedCount(u)
return uu
}
// SetNillableLoginFailedCount sets the "login_failed_count" field if the given value is not nil.
func (uu *UserUpdate) SetNillableLoginFailedCount(u *uint8) *UserUpdate {
if u != nil {
uu.SetLoginFailedCount(*u)
}
return uu
}
// AddLoginFailedCount adds u to the "login_failed_count" field.
func (uu *UserUpdate) AddLoginFailedCount(u int8) *UserUpdate {
uu.mutation.AddLoginFailedCount(u)
return uu
}
// ClearLoginFailedCount clears the value of the "login_failed_count" field.
func (uu *UserUpdate) ClearLoginFailedCount() *UserUpdate {
uu.mutation.ClearLoginFailedCount()
return uu
}
// SetLoginAttemptOn sets the "login_attempt_on" field.
func (uu *UserUpdate) SetLoginAttemptOn(t time.Time) *UserUpdate {
uu.mutation.SetLoginAttemptOn(t)
return uu
}
// SetNillableLoginAttemptOn sets the "login_attempt_on" field if the given value is not nil.
func (uu *UserUpdate) SetNillableLoginAttemptOn(t *time.Time) *UserUpdate {
if t != nil {
uu.SetLoginAttemptOn(*t)
}
return uu
}
// ClearLoginAttemptOn clears the value of the "login_attempt_on" field.
func (uu *UserUpdate) ClearLoginAttemptOn() *UserUpdate {
uu.mutation.ClearLoginAttemptOn()
return uu
}
// SetLoginLockedUntil sets the "login_locked_until" field.
func (uu *UserUpdate) SetLoginLockedUntil(t time.Time) *UserUpdate {
uu.mutation.SetLoginLockedUntil(t)
return uu
}
// SetNillableLoginLockedUntil sets the "login_locked_until" field if the given value is not nil.
func (uu *UserUpdate) SetNillableLoginLockedUntil(t *time.Time) *UserUpdate {
if t != nil {
uu.SetLoginLockedUntil(*t)
}
return uu
}
// ClearLoginLockedUntil clears the value of the "login_locked_until" field.
func (uu *UserUpdate) ClearLoginLockedUntil() *UserUpdate {
uu.mutation.ClearLoginLockedUntil()
return uu
}
// SetFirstName sets the "first_name" field.
func (uu *UserUpdate) SetFirstName(s string) *UserUpdate {
uu.mutation.SetFirstName(s)
return uu
}
// SetNillableFirstName sets the "first_name" field if the given value is not nil.
func (uu *UserUpdate) SetNillableFirstName(s *string) *UserUpdate {
if s != nil {
uu.SetFirstName(*s)
}
return uu
}
// SetMiddleName sets the "middle_name" field.
func (uu *UserUpdate) SetMiddleName(s string) *UserUpdate {
uu.mutation.SetMiddleName(s)
return uu
}
// SetNillableMiddleName sets the "middle_name" field if the given value is not nil.
func (uu *UserUpdate) SetNillableMiddleName(s *string) *UserUpdate {
if s != nil {
uu.SetMiddleName(*s)
}
return uu
}
// SetLastName sets the "last_name" field.
func (uu *UserUpdate) SetLastName(s string) *UserUpdate {
uu.mutation.SetLastName(s)
return uu
}
// SetNillableLastName sets the "last_name" field if the given value is not nil.
func (uu *UserUpdate) SetNillableLastName(s *string) *UserUpdate {
if s != nil {
uu.SetLastName(*s)
}
return uu
}
// SetStatus sets the "status" field.
func (uu *UserUpdate) SetStatus(u user.Status) *UserUpdate {
uu.mutation.SetStatus(u)
return uu
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (uu *UserUpdate) SetNillableStatus(u *user.Status) *UserUpdate {
if u != nil {
uu.SetStatus(*u)
}
return uu
}
// AddSessionIDs adds the "sessions" edge to the UserSession entity by IDs.
func (uu *UserUpdate) AddSessionIDs(ids ...int64) *UserUpdate {
uu.mutation.AddSessionIDs(ids...)
return uu
}
// AddSessions adds the "sessions" edges to the UserSession entity.
func (uu *UserUpdate) AddSessions(u ...*UserSession) *UserUpdate {
ids := make([]int64, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.AddSessionIDs(ids...)
}
// AddAuditLogIDs adds the "audit_logs" edge to the Audit entity by IDs.
func (uu *UserUpdate) AddAuditLogIDs(ids ...int64) *UserUpdate {
uu.mutation.AddAuditLogIDs(ids...)
return uu
}
// AddAuditLogs adds the "audit_logs" edges to the Audit entity.
func (uu *UserUpdate) AddAuditLogs(a ...*Audit) *UserUpdate {
ids := make([]int64, len(a))
for i := range a {
ids[i] = a[i].ID
}
return uu.AddAuditLogIDs(ids...)
}
// Mutation returns the UserMutation object of the builder.
func (uu *UserUpdate) Mutation() *UserMutation {
return uu.mutation
}
// ClearSessions clears all "sessions" edges to the UserSession entity.
func (uu *UserUpdate) ClearSessions() *UserUpdate {
uu.mutation.ClearSessions()
return uu
}
// RemoveSessionIDs removes the "sessions" edge to UserSession entities by IDs.
func (uu *UserUpdate) RemoveSessionIDs(ids ...int64) *UserUpdate {
uu.mutation.RemoveSessionIDs(ids...)
return uu
}
// RemoveSessions removes "sessions" edges to UserSession entities.
func (uu *UserUpdate) RemoveSessions(u ...*UserSession) *UserUpdate {
ids := make([]int64, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.RemoveSessionIDs(ids...)
}
// ClearAuditLogs clears all "audit_logs" edges to the Audit entity.
func (uu *UserUpdate) ClearAuditLogs() *UserUpdate {
uu.mutation.ClearAuditLogs()
return uu
}
// RemoveAuditLogIDs removes the "audit_logs" edge to Audit entities by IDs.
func (uu *UserUpdate) RemoveAuditLogIDs(ids ...int64) *UserUpdate {
uu.mutation.RemoveAuditLogIDs(ids...)
return uu
}
// RemoveAuditLogs removes "audit_logs" edges to Audit entities.
func (uu *UserUpdate) RemoveAuditLogs(a ...*Audit) *UserUpdate {
ids := make([]int64, len(a))
for i := range a {
ids[i] = a[i].ID
}
return uu.RemoveAuditLogIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
uu.defaults()
return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (uu *UserUpdate) SaveX(ctx context.Context) int {
affected, err := uu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (uu *UserUpdate) Exec(ctx context.Context) error {
_, err := uu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (uu *UserUpdate) ExecX(ctx context.Context) {
if err := uu.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (uu *UserUpdate) defaults() {
if _, ok := uu.mutation.UpdatedAt(); !ok {
v := user.UpdateDefaultUpdatedAt()
uu.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (uu *UserUpdate) check() error {
if v, ok := uu.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 := uu.mutation.Phone(); ok {
if err := user.PhoneValidator(v); err != nil {
return &ValidationError{Name: "phone", err: fmt.Errorf(`ent: validator failed for field "User.phone": %w`, err)}
}
}
if v, ok := uu.mutation.PwdSalt(); ok {
if err := user.PwdSaltValidator(v); err != nil {
return &ValidationError{Name: "pwd_salt", err: fmt.Errorf(`ent: validator failed for field "User.pwd_salt": %w`, err)}
}
}
if v, ok := uu.mutation.PwdHash(); ok {
if err := user.PwdHashValidator(v); err != nil {
return &ValidationError{Name: "pwd_hash", err: fmt.Errorf(`ent: validator failed for field "User.pwd_hash": %w`, err)}
}
}
if v, ok := uu.mutation.FirstName(); ok {
if err := user.FirstNameValidator(v); err != nil {
return &ValidationError{Name: "first_name", err: fmt.Errorf(`ent: validator failed for field "User.first_name": %w`, err)}
}
}
if v, ok := uu.mutation.MiddleName(); ok {
if err := user.MiddleNameValidator(v); err != nil {
return &ValidationError{Name: "middle_name", err: fmt.Errorf(`ent: validator failed for field "User.middle_name": %w`, err)}
}
}
if v, ok := uu.mutation.LastName(); ok {
if err := user.LastNameValidator(v); err != nil {
return &ValidationError{Name: "last_name", err: fmt.Errorf(`ent: validator failed for field "User.last_name": %w`, err)}
}
}
if v, ok := uu.mutation.Status(); ok {
if err := user.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)}
}
}
return nil
}
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := uu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64))
if ps := uu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := uu.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := uu.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value)
}
if value, ok := uu.mutation.EmailVerified(); ok {
_spec.SetField(user.FieldEmailVerified, field.TypeBool, value)
}
if value, ok := uu.mutation.Phone(); ok {
_spec.SetField(user.FieldPhone, field.TypeString, value)
}
if uu.mutation.PhoneCleared() {
_spec.ClearField(user.FieldPhone, field.TypeString)
}
if value, ok := uu.mutation.PhoneVerified(); ok {
_spec.SetField(user.FieldPhoneVerified, field.TypeBool, value)
}
if value, ok := uu.mutation.PwdSalt(); ok {
_spec.SetField(user.FieldPwdSalt, field.TypeString, value)
}
if value, ok := uu.mutation.PwdHash(); ok {
_spec.SetField(user.FieldPwdHash, field.TypeString, value)
}
if value, ok := uu.mutation.LoginFailedCount(); ok {
_spec.SetField(user.FieldLoginFailedCount, field.TypeUint8, value)
}
if value, ok := uu.mutation.AddedLoginFailedCount(); ok {
_spec.AddField(user.FieldLoginFailedCount, field.TypeUint8, value)
}
if uu.mutation.LoginFailedCountCleared() {
_spec.ClearField(user.FieldLoginFailedCount, field.TypeUint8)
}
if value, ok := uu.mutation.LoginAttemptOn(); ok {
_spec.SetField(user.FieldLoginAttemptOn, field.TypeTime, value)
}
if uu.mutation.LoginAttemptOnCleared() {
_spec.ClearField(user.FieldLoginAttemptOn, field.TypeTime)
}
if value, ok := uu.mutation.LoginLockedUntil(); ok {
_spec.SetField(user.FieldLoginLockedUntil, field.TypeTime, value)
}
if uu.mutation.LoginLockedUntilCleared() {
_spec.ClearField(user.FieldLoginLockedUntil, field.TypeTime)
}
if value, ok := uu.mutation.FirstName(); ok {
_spec.SetField(user.FieldFirstName, field.TypeString, value)
}
if value, ok := uu.mutation.MiddleName(); ok {
_spec.SetField(user.FieldMiddleName, field.TypeString, value)
}
if value, ok := uu.mutation.LastName(); ok {
_spec.SetField(user.FieldLastName, field.TypeString, value)
}
if value, ok := uu.mutation.Status(); ok {
_spec.SetField(user.FieldStatus, field.TypeEnum, value)
}
if uu.mutation.SessionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SessionsTable,
Columns: []string{user.SessionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersession.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uu.mutation.RemovedSessionsIDs(); len(nodes) > 0 && !uu.mutation.SessionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SessionsTable,
Columns: []string{user.SessionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersession.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uu.mutation.SessionsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SessionsTable,
Columns: []string{user.SessionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersession.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if uu.mutation.AuditLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.AuditLogsTable,
Columns: []string{user.AuditLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(audit.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uu.mutation.RemovedAuditLogsIDs(); len(nodes) > 0 && !uu.mutation.AuditLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.AuditLogsTable,
Columns: []string{user.AuditLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(audit.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uu.mutation.AuditLogsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.AuditLogsTable,
Columns: []string{user.AuditLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(audit.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, uu.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
}
uu.mutation.done = true
return n, 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 (uuo *UserUpdateOne) SetUpdatedAt(t time.Time) *UserUpdateOne {
uuo.mutation.SetUpdatedAt(t)
return uuo
}
// SetEmail sets the "email" field.
func (uuo *UserUpdateOne) SetEmail(s string) *UserUpdateOne {
uuo.mutation.SetEmail(s)
return uuo
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableEmail(s *string) *UserUpdateOne {
if s != nil {
uuo.SetEmail(*s)
}
return uuo
}
// SetEmailVerified sets the "email_verified" field.
func (uuo *UserUpdateOne) SetEmailVerified(b bool) *UserUpdateOne {
uuo.mutation.SetEmailVerified(b)
return uuo
}
// SetNillableEmailVerified sets the "email_verified" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableEmailVerified(b *bool) *UserUpdateOne {
if b != nil {
uuo.SetEmailVerified(*b)
}
return uuo
}
// SetPhone sets the "phone" field.
func (uuo *UserUpdateOne) SetPhone(s string) *UserUpdateOne {
uuo.mutation.SetPhone(s)
return uuo
}
// SetNillablePhone sets the "phone" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillablePhone(s *string) *UserUpdateOne {
if s != nil {
uuo.SetPhone(*s)
}
return uuo
}
// ClearPhone clears the value of the "phone" field.
func (uuo *UserUpdateOne) ClearPhone() *UserUpdateOne {
uuo.mutation.ClearPhone()
return uuo
}
// SetPhoneVerified sets the "phone_verified" field.
func (uuo *UserUpdateOne) SetPhoneVerified(b bool) *UserUpdateOne {
uuo.mutation.SetPhoneVerified(b)
return uuo
}
// SetNillablePhoneVerified sets the "phone_verified" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillablePhoneVerified(b *bool) *UserUpdateOne {
if b != nil {
uuo.SetPhoneVerified(*b)
}
return uuo
}
// SetPwdSalt sets the "pwd_salt" field.
func (uuo *UserUpdateOne) SetPwdSalt(s string) *UserUpdateOne {
uuo.mutation.SetPwdSalt(s)
return uuo
}
// SetNillablePwdSalt sets the "pwd_salt" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillablePwdSalt(s *string) *UserUpdateOne {
if s != nil {
uuo.SetPwdSalt(*s)
}
return uuo
}
// SetPwdHash sets the "pwd_hash" field.
func (uuo *UserUpdateOne) SetPwdHash(s string) *UserUpdateOne {
uuo.mutation.SetPwdHash(s)
return uuo
}
// SetNillablePwdHash sets the "pwd_hash" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillablePwdHash(s *string) *UserUpdateOne {
if s != nil {
uuo.SetPwdHash(*s)
}
return uuo
}
// SetLoginFailedCount sets the "login_failed_count" field.
func (uuo *UserUpdateOne) SetLoginFailedCount(u uint8) *UserUpdateOne {
uuo.mutation.ResetLoginFailedCount()
uuo.mutation.SetLoginFailedCount(u)
return uuo
}
// SetNillableLoginFailedCount sets the "login_failed_count" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableLoginFailedCount(u *uint8) *UserUpdateOne {
if u != nil {
uuo.SetLoginFailedCount(*u)
}
return uuo
}
// AddLoginFailedCount adds u to the "login_failed_count" field.
func (uuo *UserUpdateOne) AddLoginFailedCount(u int8) *UserUpdateOne {
uuo.mutation.AddLoginFailedCount(u)
return uuo
}
// ClearLoginFailedCount clears the value of the "login_failed_count" field.
func (uuo *UserUpdateOne) ClearLoginFailedCount() *UserUpdateOne {
uuo.mutation.ClearLoginFailedCount()
return uuo
}
// SetLoginAttemptOn sets the "login_attempt_on" field.
func (uuo *UserUpdateOne) SetLoginAttemptOn(t time.Time) *UserUpdateOne {
uuo.mutation.SetLoginAttemptOn(t)
return uuo
}
// SetNillableLoginAttemptOn sets the "login_attempt_on" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableLoginAttemptOn(t *time.Time) *UserUpdateOne {
if t != nil {
uuo.SetLoginAttemptOn(*t)
}
return uuo
}
// ClearLoginAttemptOn clears the value of the "login_attempt_on" field.
func (uuo *UserUpdateOne) ClearLoginAttemptOn() *UserUpdateOne {
uuo.mutation.ClearLoginAttemptOn()
return uuo
}
// SetLoginLockedUntil sets the "login_locked_until" field.
func (uuo *UserUpdateOne) SetLoginLockedUntil(t time.Time) *UserUpdateOne {
uuo.mutation.SetLoginLockedUntil(t)
return uuo
}
// SetNillableLoginLockedUntil sets the "login_locked_until" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableLoginLockedUntil(t *time.Time) *UserUpdateOne {
if t != nil {
uuo.SetLoginLockedUntil(*t)
}
return uuo
}
// ClearLoginLockedUntil clears the value of the "login_locked_until" field.
func (uuo *UserUpdateOne) ClearLoginLockedUntil() *UserUpdateOne {
uuo.mutation.ClearLoginLockedUntil()
return uuo
}
// SetFirstName sets the "first_name" field.
func (uuo *UserUpdateOne) SetFirstName(s string) *UserUpdateOne {
uuo.mutation.SetFirstName(s)
return uuo
}
// SetNillableFirstName sets the "first_name" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableFirstName(s *string) *UserUpdateOne {
if s != nil {
uuo.SetFirstName(*s)
}
return uuo
}
// SetMiddleName sets the "middle_name" field.
func (uuo *UserUpdateOne) SetMiddleName(s string) *UserUpdateOne {
uuo.mutation.SetMiddleName(s)
return uuo
}
// SetNillableMiddleName sets the "middle_name" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableMiddleName(s *string) *UserUpdateOne {
if s != nil {
uuo.SetMiddleName(*s)
}
return uuo
}
// SetLastName sets the "last_name" field.
func (uuo *UserUpdateOne) SetLastName(s string) *UserUpdateOne {
uuo.mutation.SetLastName(s)
return uuo
}
// SetNillableLastName sets the "last_name" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableLastName(s *string) *UserUpdateOne {
if s != nil {
uuo.SetLastName(*s)
}
return uuo
}
// SetStatus sets the "status" field.
func (uuo *UserUpdateOne) SetStatus(u user.Status) *UserUpdateOne {
uuo.mutation.SetStatus(u)
return uuo
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableStatus(u *user.Status) *UserUpdateOne {
if u != nil {
uuo.SetStatus(*u)
}
return uuo
}
// AddSessionIDs adds the "sessions" edge to the UserSession entity by IDs.
func (uuo *UserUpdateOne) AddSessionIDs(ids ...int64) *UserUpdateOne {
uuo.mutation.AddSessionIDs(ids...)
return uuo
}
// AddSessions adds the "sessions" edges to the UserSession entity.
func (uuo *UserUpdateOne) AddSessions(u ...*UserSession) *UserUpdateOne {
ids := make([]int64, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.AddSessionIDs(ids...)
}
// AddAuditLogIDs adds the "audit_logs" edge to the Audit entity by IDs.
func (uuo *UserUpdateOne) AddAuditLogIDs(ids ...int64) *UserUpdateOne {
uuo.mutation.AddAuditLogIDs(ids...)
return uuo
}
// AddAuditLogs adds the "audit_logs" edges to the Audit entity.
func (uuo *UserUpdateOne) AddAuditLogs(a ...*Audit) *UserUpdateOne {
ids := make([]int64, len(a))
for i := range a {
ids[i] = a[i].ID
}
return uuo.AddAuditLogIDs(ids...)
}
// Mutation returns the UserMutation object of the builder.
func (uuo *UserUpdateOne) Mutation() *UserMutation {
return uuo.mutation
}
// ClearSessions clears all "sessions" edges to the UserSession entity.
func (uuo *UserUpdateOne) ClearSessions() *UserUpdateOne {
uuo.mutation.ClearSessions()
return uuo
}
// RemoveSessionIDs removes the "sessions" edge to UserSession entities by IDs.
func (uuo *UserUpdateOne) RemoveSessionIDs(ids ...int64) *UserUpdateOne {
uuo.mutation.RemoveSessionIDs(ids...)
return uuo
}
// RemoveSessions removes "sessions" edges to UserSession entities.
func (uuo *UserUpdateOne) RemoveSessions(u ...*UserSession) *UserUpdateOne {
ids := make([]int64, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.RemoveSessionIDs(ids...)
}
// ClearAuditLogs clears all "audit_logs" edges to the Audit entity.
func (uuo *UserUpdateOne) ClearAuditLogs() *UserUpdateOne {
uuo.mutation.ClearAuditLogs()
return uuo
}
// RemoveAuditLogIDs removes the "audit_logs" edge to Audit entities by IDs.
func (uuo *UserUpdateOne) RemoveAuditLogIDs(ids ...int64) *UserUpdateOne {
uuo.mutation.RemoveAuditLogIDs(ids...)
return uuo
}
// RemoveAuditLogs removes "audit_logs" edges to Audit entities.
func (uuo *UserUpdateOne) RemoveAuditLogs(a ...*Audit) *UserUpdateOne {
ids := make([]int64, len(a))
for i := range a {
ids[i] = a[i].ID
}
return uuo.RemoveAuditLogIDs(ids...)
}
// Where appends a list predicates to the UserUpdate builder.
func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
uuo.mutation.Where(ps...)
return uuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
uuo.fields = append([]string{field}, fields...)
return uuo
}
// Save executes the query and returns the updated User entity.
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
uuo.defaults()
return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
node, err := uuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (uuo *UserUpdateOne) Exec(ctx context.Context) error {
_, err := uuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
if err := uuo.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (uuo *UserUpdateOne) defaults() {
if _, ok := uuo.mutation.UpdatedAt(); !ok {
v := user.UpdateDefaultUpdatedAt()
uuo.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (uuo *UserUpdateOne) check() error {
if v, ok := uuo.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 := uuo.mutation.Phone(); ok {
if err := user.PhoneValidator(v); err != nil {
return &ValidationError{Name: "phone", err: fmt.Errorf(`ent: validator failed for field "User.phone": %w`, err)}
}
}
if v, ok := uuo.mutation.PwdSalt(); ok {
if err := user.PwdSaltValidator(v); err != nil {
return &ValidationError{Name: "pwd_salt", err: fmt.Errorf(`ent: validator failed for field "User.pwd_salt": %w`, err)}
}
}
if v, ok := uuo.mutation.PwdHash(); ok {
if err := user.PwdHashValidator(v); err != nil {
return &ValidationError{Name: "pwd_hash", err: fmt.Errorf(`ent: validator failed for field "User.pwd_hash": %w`, err)}
}
}
if v, ok := uuo.mutation.FirstName(); ok {
if err := user.FirstNameValidator(v); err != nil {
return &ValidationError{Name: "first_name", err: fmt.Errorf(`ent: validator failed for field "User.first_name": %w`, err)}
}
}
if v, ok := uuo.mutation.MiddleName(); ok {
if err := user.MiddleNameValidator(v); err != nil {
return &ValidationError{Name: "middle_name", err: fmt.Errorf(`ent: validator failed for field "User.middle_name": %w`, err)}
}
}
if v, ok := uuo.mutation.LastName(); ok {
if err := user.LastNameValidator(v); err != nil {
return &ValidationError{Name: "last_name", err: fmt.Errorf(`ent: validator failed for field "User.last_name": %w`, err)}
}
}
if v, ok := uuo.mutation.Status(); ok {
if err := user.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)}
}
}
return nil
}
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
if err := uuo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64))
id, ok := uuo.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 := uuo.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 := uuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := uuo.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := uuo.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value)
}
if value, ok := uuo.mutation.EmailVerified(); ok {
_spec.SetField(user.FieldEmailVerified, field.TypeBool, value)
}
if value, ok := uuo.mutation.Phone(); ok {
_spec.SetField(user.FieldPhone, field.TypeString, value)
}
if uuo.mutation.PhoneCleared() {
_spec.ClearField(user.FieldPhone, field.TypeString)
}
if value, ok := uuo.mutation.PhoneVerified(); ok {
_spec.SetField(user.FieldPhoneVerified, field.TypeBool, value)
}
if value, ok := uuo.mutation.PwdSalt(); ok {
_spec.SetField(user.FieldPwdSalt, field.TypeString, value)
}
if value, ok := uuo.mutation.PwdHash(); ok {
_spec.SetField(user.FieldPwdHash, field.TypeString, value)
}
if value, ok := uuo.mutation.LoginFailedCount(); ok {
_spec.SetField(user.FieldLoginFailedCount, field.TypeUint8, value)
}
if value, ok := uuo.mutation.AddedLoginFailedCount(); ok {
_spec.AddField(user.FieldLoginFailedCount, field.TypeUint8, value)
}
if uuo.mutation.LoginFailedCountCleared() {
_spec.ClearField(user.FieldLoginFailedCount, field.TypeUint8)
}
if value, ok := uuo.mutation.LoginAttemptOn(); ok {
_spec.SetField(user.FieldLoginAttemptOn, field.TypeTime, value)
}
if uuo.mutation.LoginAttemptOnCleared() {
_spec.ClearField(user.FieldLoginAttemptOn, field.TypeTime)
}
if value, ok := uuo.mutation.LoginLockedUntil(); ok {
_spec.SetField(user.FieldLoginLockedUntil, field.TypeTime, value)
}
if uuo.mutation.LoginLockedUntilCleared() {
_spec.ClearField(user.FieldLoginLockedUntil, field.TypeTime)
}
if value, ok := uuo.mutation.FirstName(); ok {
_spec.SetField(user.FieldFirstName, field.TypeString, value)
}
if value, ok := uuo.mutation.MiddleName(); ok {
_spec.SetField(user.FieldMiddleName, field.TypeString, value)
}
if value, ok := uuo.mutation.LastName(); ok {
_spec.SetField(user.FieldLastName, field.TypeString, value)
}
if value, ok := uuo.mutation.Status(); ok {
_spec.SetField(user.FieldStatus, field.TypeEnum, value)
}
if uuo.mutation.SessionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SessionsTable,
Columns: []string{user.SessionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersession.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uuo.mutation.RemovedSessionsIDs(); len(nodes) > 0 && !uuo.mutation.SessionsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SessionsTable,
Columns: []string{user.SessionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersession.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uuo.mutation.SessionsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.SessionsTable,
Columns: []string{user.SessionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersession.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if uuo.mutation.AuditLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.AuditLogsTable,
Columns: []string{user.AuditLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(audit.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uuo.mutation.RemovedAuditLogsIDs(); len(nodes) > 0 && !uuo.mutation.AuditLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.AuditLogsTable,
Columns: []string{user.AuditLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(audit.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := uuo.mutation.AuditLogsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.AuditLogsTable,
Columns: []string{user.AuditLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(audit.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &User{config: uuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, uuo.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
}
uuo.mutation.done = true
return _node, nil
}