Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/app/api/static/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3512,6 +3512,10 @@ const docTemplate = `{
"description": "Notes holds the value of the \"notes\" field.",
"type": "string"
},
"notify_warranty_expiration": {
"description": "NotifyWarrantyExpiration holds the value of the \"notify_warranty_expiration\" field.",
"type": "boolean"
},
"purchase_date": {
"description": "PurchaseDate holds the value of the \"purchase_date\" field.",
"type": "string"
Expand Down Expand Up @@ -4918,6 +4922,9 @@ const docTemplate = `{
"description": "Extras",
"type": "string"
},
"notifyWarrantyExpiration": {
"type": "boolean"
},
"parent": {
"description": "Edges",
"allOf": [
Expand Down Expand Up @@ -5513,6 +5520,9 @@ const docTemplate = `{
"description": "Extras",
"type": "string"
},
"notifyWarrantyExpiration": {
"type": "boolean"
},
"parentId": {
"type": "string",
"x-nullable": true,
Expand Down
10 changes: 10 additions & 0 deletions backend/app/api/static/docs/openapi-3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3751,6 +3751,10 @@
"description": "Notes holds the value of the \"notes\" field.",
"type": "string"
},
"notify_warranty_expiration": {
"description": "NotifyWarrantyExpiration holds the value of the \"notify_warranty_expiration\" field.",
"type": "boolean"
},
"purchase_date": {
"description": "PurchaseDate holds the value of the \"purchase_date\" field.",
"type": "string"
Expand Down Expand Up @@ -5157,6 +5161,9 @@
"description": "Extras",
"type": "string"
},
"notifyWarrantyExpiration": {
"type": "boolean"
},
"parent": {
"description": "Edges",
"allOf": [
Expand Down Expand Up @@ -5752,6 +5759,9 @@
"description": "Extras",
"type": "string"
},
"notifyWarrantyExpiration": {
"type": "boolean"
},
"parentId": {
"type": "string",
"x-omitempty": true,
Expand Down
8 changes: 8 additions & 0 deletions backend/app/api/static/docs/openapi-3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,10 @@ components:
notes:
description: Notes holds the value of the "notes" field.
type: string
notify_warranty_expiration:
description: NotifyWarrantyExpiration holds the value of the
"notify_warranty_expiration" field.
type: boolean
purchase_date:
description: PurchaseDate holds the value of the "purchase_date" field.
type: string
Expand Down Expand Up @@ -3251,6 +3255,8 @@ components:
notes:
description: Extras
type: string
notifyWarrantyExpiration:
type: boolean
parent:
description: Edges
allOf:
Expand Down Expand Up @@ -3664,6 +3670,8 @@ components:
notes:
description: Extras
type: string
notifyWarrantyExpiration:
type: boolean
parentId:
type: string
x-omitempty: true
Expand Down
10 changes: 10 additions & 0 deletions backend/app/api/static/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3509,6 +3509,10 @@
"description": "Notes holds the value of the \"notes\" field.",
"type": "string"
},
"notify_warranty_expiration": {
"description": "NotifyWarrantyExpiration holds the value of the \"notify_warranty_expiration\" field.",
"type": "boolean"
},
"purchase_date": {
"description": "PurchaseDate holds the value of the \"purchase_date\" field.",
"type": "string"
Expand Down Expand Up @@ -4915,6 +4919,9 @@
"description": "Extras",
"type": "string"
},
"notifyWarrantyExpiration": {
"type": "boolean"
},
"parent": {
"description": "Edges",
"allOf": [
Expand Down Expand Up @@ -5510,6 +5517,9 @@
"description": "Extras",
"type": "string"
},
"notifyWarrantyExpiration": {
"type": "boolean"
},
"parentId": {
"type": "string",
"x-nullable": true,
Expand Down
8 changes: 8 additions & 0 deletions backend/app/api/static/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ definitions:
notes:
description: Notes holds the value of the "notes" field.
type: string
notify_warranty_expiration:
description: NotifyWarrantyExpiration holds the value of the "notify_warranty_expiration"
field.
type: boolean
purchase_date:
description: PurchaseDate holds the value of the "purchase_date" field.
type: string
Expand Down Expand Up @@ -1200,6 +1204,8 @@ definitions:
notes:
description: Extras
type: string
notifyWarrantyExpiration:
type: boolean
parent:
allOf:
- $ref: '#/definitions/repo.EntitySummary'
Expand Down Expand Up @@ -1611,6 +1617,8 @@ definitions:
notes:
description: Extras
type: string
notifyWarrantyExpiration:
type: boolean
parentId:
type: string
x-nullable: true
Expand Down
47 changes: 37 additions & 10 deletions backend/internal/core/services/service_background.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/sysadminsmedia/homebox/backend/internal/sys/validate"
)

// number of days before warranty expiry to send notification
const warrantyNotifyLeadDays = 30

type Latest struct {
Version string `json:"version"`
Date string `json:"date"`
Expand All @@ -36,6 +39,8 @@ func (svc *BackgroundService) SendNotifiersToday(ctx context.Context) error {

today := types.DateFromTime(time.Now())

warrantyTarget := types.DateFromTime(time.Now().AddDate(0, 0, warrantyNotifyLeadDays))

for i := range groups {
group := groups[i]

Expand All @@ -44,11 +49,16 @@ func (svc *BackgroundService) SendNotifiersToday(ctx context.Context) error {
return err
}

if len(entries) == 0 {
warrantyItems, err := svc.repos.Entities.GetWarrantyExpiringOn(ctx, group.ID, warrantyTarget)
if err != nil {
return err
}

if len(entries) == 0 && len(warrantyItems) == 0 {
log.Debug().
Str("group_name", group.Name).
Str("group_id", group.ID.String()).
Msg("No scheduled maintenance for today")
Msg("No scheduled maintenance or expiring warranties for today")
continue
}

Expand All @@ -67,15 +77,32 @@ func (svc *BackgroundService) SendNotifiersToday(ctx context.Context) error {

bldr := strings.Builder{}

bldr.WriteString("Homebox Maintenance for (")
bldr.WriteString(today.String())
bldr.WriteString("):\n")
if len(entries) > 0 {
bldr.WriteString("Homebox Maintenance for (")
bldr.WriteString(today.String())
bldr.WriteString("):\n")

for i := range entries {
entry := entries[i]
bldr.WriteString(" - ")
bldr.WriteString(entry.Name)
bldr.WriteString("\n")
for i := range entries {
entry := entries[i]
bldr.WriteString(" - ")
bldr.WriteString(entry.Name)
bldr.WriteString("\n")
}
}

if len(warrantyItems) > 0 {
if bldr.Len() > 0 {
bldr.WriteString("\n")
}
bldr.WriteString("Homebox Warranties expiring on (")
bldr.WriteString(warrantyTarget.String())
bldr.WriteString("):\n")

for i := range warrantyItems {
bldr.WriteString(" - ")
bldr.WriteString(warrantyItems[i].Name)
bldr.WriteString("\n")
}
}

var sendErrs []error
Expand Down
13 changes: 12 additions & 1 deletion backend/internal/data/ent/entity.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions backend/internal/data/ent/entity/entity.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions backend/internal/data/ent/entity/where.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions backend/internal/data/ent/entity_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading