mirror of
https://github.com/hay-kot/homebox.git
synced 2025-06-03 11:02:29 +00:00
fix: date picker improvements (#793)
* use vue component for date picker * zero out database fields even when set to 0001-xx-xx * fix wrong datetime display + improved datepicker * fix ts error * zero out times * add date-fns to dependencies
This commit is contained in:
parent
c708b1759e
commit
4c9ddac395
9 changed files with 186 additions and 41 deletions
|
@ -799,8 +799,11 @@ func (e *ItemsRepository) ZeroOutTimeFields(ctx context.Context, GID uuid.UUID)
|
|||
item.HasGroupWith(group.ID(GID)),
|
||||
item.Or(
|
||||
item.PurchaseTimeNotNil(),
|
||||
item.PurchaseFromLT("0002-01-01"),
|
||||
item.SoldTimeNotNil(),
|
||||
item.SoldToLT("0002-01-01"),
|
||||
item.WarrantyExpiresNotNil(),
|
||||
item.WarrantyDetailsLT("0002-01-01"),
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -819,15 +822,36 @@ func (e *ItemsRepository) ZeroOutTimeFields(ctx context.Context, GID uuid.UUID)
|
|||
updateQ := e.db.Item.Update().Where(item.ID(i.ID))
|
||||
|
||||
if !i.PurchaseTime.IsZero() {
|
||||
updateQ.SetPurchaseTime(toDateOnly(i.PurchaseTime))
|
||||
switch {
|
||||
case i.PurchaseTime.Year() < 100:
|
||||
updateQ.ClearPurchaseTime()
|
||||
default:
|
||||
updateQ.SetPurchaseTime(toDateOnly(i.PurchaseTime))
|
||||
}
|
||||
} else {
|
||||
updateQ.ClearPurchaseTime()
|
||||
}
|
||||
|
||||
if !i.SoldTime.IsZero() {
|
||||
updateQ.SetSoldTime(toDateOnly(i.SoldTime))
|
||||
switch {
|
||||
case i.SoldTime.Year() < 100:
|
||||
updateQ.ClearSoldTime()
|
||||
default:
|
||||
updateQ.SetSoldTime(toDateOnly(i.SoldTime))
|
||||
}
|
||||
} else {
|
||||
updateQ.ClearSoldTime()
|
||||
}
|
||||
|
||||
if !i.WarrantyExpires.IsZero() {
|
||||
updateQ.SetWarrantyExpires(toDateOnly(i.WarrantyExpires))
|
||||
switch {
|
||||
case i.WarrantyExpires.Year() < 100:
|
||||
updateQ.ClearWarrantyExpires()
|
||||
default:
|
||||
updateQ.SetWarrantyExpires(toDateOnly(i.WarrantyExpires))
|
||||
}
|
||||
} else {
|
||||
updateQ.ClearWarrantyExpires()
|
||||
}
|
||||
|
||||
_, err = updateQ.Save(ctx)
|
||||
|
@ -879,7 +903,6 @@ func (e *ItemsRepository) SetPrimaryPhotos(ctx context.Context, GID uuid.UUID) (
|
|||
_, err = e.db.Attachment.UpdateOne(a).
|
||||
SetPrimary(true).
|
||||
Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return updated, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue