mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2026-01-01 18:47:20 +01:00
* ent re-generation
* add oidc integration
* document oidc integration
* go fmt
* address backend linter findings
* run prettier on index.vue
* State cookie domain can mismatch when Hostname override is used (breaks CSRF check). Add SameSite.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Delete state cookie with matching domain and MaxAge; add SameSite.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Fix endpoint path in comments and error to include /api/v1.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Also use request context when verifying the ID token.
* Do not return raw auth errors to clients (user-enumeration risk).
* consistently set cookie the same way across function
* remove baseURL after declaration
* only enable OIDC routes if OIDC is enabled
* swagger doc for failure
* Only block when provider=local; move the check after parsing provider
* fix extended session comment
* reduce pii logging
* futher reduce pii logging
* remove unused DiscoveryDocument
* remove unused offline_access from default oidc scopes
* remove offline access from AuthCodeURL
* support host from X-Forwarded-Host
* set sane default claim names if unset
* error strings should not be capitalized
* Revert "run prettier on index.vue"
This reverts commit aa22330a23.
* Add timeout to provider discovery
* Split scopes robustly
* refactor hostname calculation
* address frontend prettier findings
* add property oidc on type APISummary
* LoginOIDC: Normalize inputs, only create if not found
* add oidc email verification
* oidc handleCallback: clear state cookie before each return
* add support for oidc nonce parameter
* Harden first-login race: handle concurrent creates gracefully and fix log key.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* support email verified claim as bool or string
* fail fast on empty email
* PKCE verifier
* fix: add timing delay to attachment test to resolve CI race condition
The attachment test was failing intermittently in CI due to a race condition
between attachment creation and retrieval. Adding a small 100ms delay after
attachment creation ensures the file system and database operations complete
before the test attempts to verify the attachment exists.
* Revert "fix: add timing delay to attachment test to resolve CI race condition"
This reverts commit 4aa8b2a0d829753e8d2dd1ba76f4b1e04e28c45e.
* oidc error state, use ref
* rename oidc.force to oidc.authRedirect
* remove hardcoded oidc error timeout
* feat: sub/iss based identity matching and userinfo endpoint collection
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Matthew Kilgore <matthew@kilgore.dev>
609 lines
19 KiB
Go
Generated
609 lines
19 KiB
Go
Generated
// 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/item"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate"
|
|
)
|
|
|
|
// MaintenanceEntryUpdate is the builder for updating MaintenanceEntry entities.
|
|
type MaintenanceEntryUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *MaintenanceEntryMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the MaintenanceEntryUpdate builder.
|
|
func (_u *MaintenanceEntryUpdate) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *MaintenanceEntryUpdate) SetUpdatedAt(v time.Time) *MaintenanceEntryUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetItemID sets the "item_id" field.
|
|
func (_u *MaintenanceEntryUpdate) SetItemID(v uuid.UUID) *MaintenanceEntryUpdate {
|
|
_u.mutation.SetItemID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemID sets the "item_id" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdate) SetNillableItemID(v *uuid.UUID) *MaintenanceEntryUpdate {
|
|
if v != nil {
|
|
_u.SetItemID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDate sets the "date" field.
|
|
func (_u *MaintenanceEntryUpdate) SetDate(v time.Time) *MaintenanceEntryUpdate {
|
|
_u.mutation.SetDate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDate sets the "date" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdate) SetNillableDate(v *time.Time) *MaintenanceEntryUpdate {
|
|
if v != nil {
|
|
_u.SetDate(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDate clears the value of the "date" field.
|
|
func (_u *MaintenanceEntryUpdate) ClearDate() *MaintenanceEntryUpdate {
|
|
_u.mutation.ClearDate()
|
|
return _u
|
|
}
|
|
|
|
// SetScheduledDate sets the "scheduled_date" field.
|
|
func (_u *MaintenanceEntryUpdate) SetScheduledDate(v time.Time) *MaintenanceEntryUpdate {
|
|
_u.mutation.SetScheduledDate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableScheduledDate sets the "scheduled_date" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdate) SetNillableScheduledDate(v *time.Time) *MaintenanceEntryUpdate {
|
|
if v != nil {
|
|
_u.SetScheduledDate(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearScheduledDate clears the value of the "scheduled_date" field.
|
|
func (_u *MaintenanceEntryUpdate) ClearScheduledDate() *MaintenanceEntryUpdate {
|
|
_u.mutation.ClearScheduledDate()
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *MaintenanceEntryUpdate) SetName(v string) *MaintenanceEntryUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdate) SetNillableName(v *string) *MaintenanceEntryUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *MaintenanceEntryUpdate) SetDescription(v string) *MaintenanceEntryUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdate) SetNillableDescription(v *string) *MaintenanceEntryUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *MaintenanceEntryUpdate) ClearDescription() *MaintenanceEntryUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetCost sets the "cost" field.
|
|
func (_u *MaintenanceEntryUpdate) SetCost(v float64) *MaintenanceEntryUpdate {
|
|
_u.mutation.ResetCost()
|
|
_u.mutation.SetCost(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCost sets the "cost" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdate) SetNillableCost(v *float64) *MaintenanceEntryUpdate {
|
|
if v != nil {
|
|
_u.SetCost(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCost adds value to the "cost" field.
|
|
func (_u *MaintenanceEntryUpdate) AddCost(v float64) *MaintenanceEntryUpdate {
|
|
_u.mutation.AddCost(v)
|
|
return _u
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (_u *MaintenanceEntryUpdate) SetItem(v *Item) *MaintenanceEntryUpdate {
|
|
return _u.SetItemID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the MaintenanceEntryMutation object of the builder.
|
|
func (_u *MaintenanceEntryUpdate) Mutation() *MaintenanceEntryMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (_u *MaintenanceEntryUpdate) ClearItem() *MaintenanceEntryUpdate {
|
|
_u.mutation.ClearItem()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *MaintenanceEntryUpdate) 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 *MaintenanceEntryUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *MaintenanceEntryUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MaintenanceEntryUpdate) 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 *MaintenanceEntryUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := maintenanceentry.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *MaintenanceEntryUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := maintenanceentry.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := maintenanceentry.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.ItemCleared() && len(_u.mutation.ItemIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *MaintenanceEntryUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(maintenanceentry.Table, maintenanceentry.Columns, sqlgraph.NewFieldSpec(maintenanceentry.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(maintenanceentry.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Date(); ok {
|
|
_spec.SetField(maintenanceentry.FieldDate, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DateCleared() {
|
|
_spec.ClearField(maintenanceentry.FieldDate, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.ScheduledDate(); ok {
|
|
_spec.SetField(maintenanceentry.FieldScheduledDate, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.ScheduledDateCleared() {
|
|
_spec.ClearField(maintenanceentry.FieldScheduledDate, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(maintenanceentry.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(maintenanceentry.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(maintenanceentry.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Cost(); ok {
|
|
_spec.SetField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCost(); ok {
|
|
_spec.AddField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.ItemCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: maintenanceentry.ItemTable,
|
|
Columns: []string{maintenanceentry.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ItemIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: maintenanceentry.ItemTable,
|
|
Columns: []string{maintenanceentry.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.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{maintenanceentry.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// MaintenanceEntryUpdateOne is the builder for updating a single MaintenanceEntry entity.
|
|
type MaintenanceEntryUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *MaintenanceEntryMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *MaintenanceEntryUpdateOne) SetUpdatedAt(v time.Time) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetItemID sets the "item_id" field.
|
|
func (_u *MaintenanceEntryUpdateOne) SetItemID(v uuid.UUID) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.SetItemID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemID sets the "item_id" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdateOne) SetNillableItemID(v *uuid.UUID) *MaintenanceEntryUpdateOne {
|
|
if v != nil {
|
|
_u.SetItemID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDate sets the "date" field.
|
|
func (_u *MaintenanceEntryUpdateOne) SetDate(v time.Time) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.SetDate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDate sets the "date" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdateOne) SetNillableDate(v *time.Time) *MaintenanceEntryUpdateOne {
|
|
if v != nil {
|
|
_u.SetDate(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDate clears the value of the "date" field.
|
|
func (_u *MaintenanceEntryUpdateOne) ClearDate() *MaintenanceEntryUpdateOne {
|
|
_u.mutation.ClearDate()
|
|
return _u
|
|
}
|
|
|
|
// SetScheduledDate sets the "scheduled_date" field.
|
|
func (_u *MaintenanceEntryUpdateOne) SetScheduledDate(v time.Time) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.SetScheduledDate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableScheduledDate sets the "scheduled_date" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdateOne) SetNillableScheduledDate(v *time.Time) *MaintenanceEntryUpdateOne {
|
|
if v != nil {
|
|
_u.SetScheduledDate(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearScheduledDate clears the value of the "scheduled_date" field.
|
|
func (_u *MaintenanceEntryUpdateOne) ClearScheduledDate() *MaintenanceEntryUpdateOne {
|
|
_u.mutation.ClearScheduledDate()
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *MaintenanceEntryUpdateOne) SetName(v string) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdateOne) SetNillableName(v *string) *MaintenanceEntryUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *MaintenanceEntryUpdateOne) SetDescription(v string) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdateOne) SetNillableDescription(v *string) *MaintenanceEntryUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *MaintenanceEntryUpdateOne) ClearDescription() *MaintenanceEntryUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetCost sets the "cost" field.
|
|
func (_u *MaintenanceEntryUpdateOne) SetCost(v float64) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.ResetCost()
|
|
_u.mutation.SetCost(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCost sets the "cost" field if the given value is not nil.
|
|
func (_u *MaintenanceEntryUpdateOne) SetNillableCost(v *float64) *MaintenanceEntryUpdateOne {
|
|
if v != nil {
|
|
_u.SetCost(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCost adds value to the "cost" field.
|
|
func (_u *MaintenanceEntryUpdateOne) AddCost(v float64) *MaintenanceEntryUpdateOne {
|
|
_u.mutation.AddCost(v)
|
|
return _u
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (_u *MaintenanceEntryUpdateOne) SetItem(v *Item) *MaintenanceEntryUpdateOne {
|
|
return _u.SetItemID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the MaintenanceEntryMutation object of the builder.
|
|
func (_u *MaintenanceEntryUpdateOne) Mutation() *MaintenanceEntryMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (_u *MaintenanceEntryUpdateOne) ClearItem() *MaintenanceEntryUpdateOne {
|
|
_u.mutation.ClearItem()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the MaintenanceEntryUpdate builder.
|
|
func (_u *MaintenanceEntryUpdateOne) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryUpdateOne {
|
|
_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 *MaintenanceEntryUpdateOne) Select(field string, fields ...string) *MaintenanceEntryUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated MaintenanceEntry entity.
|
|
func (_u *MaintenanceEntryUpdateOne) Save(ctx context.Context) (*MaintenanceEntry, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *MaintenanceEntryUpdateOne) SaveX(ctx context.Context) *MaintenanceEntry {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *MaintenanceEntryUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MaintenanceEntryUpdateOne) 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 *MaintenanceEntryUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := maintenanceentry.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *MaintenanceEntryUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := maintenanceentry.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := maintenanceentry.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.ItemCleared() && len(_u.mutation.ItemIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *MaintenanceEntryUpdateOne) sqlSave(ctx context.Context) (_node *MaintenanceEntry, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(maintenanceentry.Table, maintenanceentry.Columns, sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MaintenanceEntry.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, maintenanceentry.FieldID)
|
|
for _, f := range fields {
|
|
if !maintenanceentry.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != maintenanceentry.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(maintenanceentry.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Date(); ok {
|
|
_spec.SetField(maintenanceentry.FieldDate, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DateCleared() {
|
|
_spec.ClearField(maintenanceentry.FieldDate, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.ScheduledDate(); ok {
|
|
_spec.SetField(maintenanceentry.FieldScheduledDate, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.ScheduledDateCleared() {
|
|
_spec.ClearField(maintenanceentry.FieldScheduledDate, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(maintenanceentry.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(maintenanceentry.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(maintenanceentry.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Cost(); ok {
|
|
_spec.SetField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCost(); ok {
|
|
_spec.AddField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.ItemCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: maintenanceentry.ItemTable,
|
|
Columns: []string{maintenanceentry.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ItemIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: maintenanceentry.ItemTable,
|
|
Columns: []string{maintenanceentry.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &MaintenanceEntry{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{maintenanceentry.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|