A continuation of HomeBox the inventory and organization system built for the Home User
fix: invitations not working properly
tonyaellie3f6a1f2e6fd1
diff --git a/backend/app/api/handlers/v1/v1_ctrl_group.go b/backend/app/api/handlers/v1/v1_ctrl_group.goindex 7f8aa6ef..c64d2f46 100644--- a/backend/app/api/handlers/v1/v1_ctrl_group.go+++ b/backend/app/api/handlers/v1/v1_ctrl_group.go@@ -21,6 +21,7 @@ type (}GroupInvitation struct {+ ID uuid.UUID `json:"id"`Token string `json:"token"`ExpiresAt time.Time `json:"expiresAt"`Uses int `json:"uses"`@@ -100,13 +101,17 @@ func (ctrl *V1Controller) HandleGroupInvitationsCreate() errchain.HandlerFunc {auth := services.NewContext(r.Context())- token, err := ctrl.svc.Group.NewInvitation(auth, body.Uses, body.ExpiresAt)+ invitation, token, err := ctrl.svc.Group.NewInvitation(auth, body.Uses, body.ExpiresAt)+ if err != nil {+ return GroupInvitation{}, err+ }return GroupInvitation{+ ID: invitation.ID,Token: token,- ExpiresAt: body.ExpiresAt,- Uses: body.Uses,- }, err+ ExpiresAt: invitation.ExpiresAt,+ Uses: invitation.Uses,+ }, nil}return adapters.Action(fn, http.StatusCreated)diff --git a/backend/app/api/routes.go b/backend/app/api/routes.goindex 848188eb..185338c0 100644--- a/backend/app/api/routes.go+++ b/backend/app/api/routes.go@@ -109,6 +109,9 @@ func (a *app) mountRoutes(r *chi.Mux, chain *errchain.ErrChain, repos *repo.AllRr.Get("/groups/invitations", chain.ToHandlerFunc(v1Ctrl.HandleGroupInvitationsGetAll(), userMW...))r.Post("/groups/invitations", chain.ToHandlerFunc(v1Ctrl.HandleGroupInvitationsCreate(), userMW...))+ r.Delete("/groups/invitations/{id}", chain.ToHandlerFunc(v1Ctrl.HandleGroupInvitationsDelete(), userMW...))+ r.Post("/groups/invitations/{id}", chain.ToHandlerFunc(v1Ctrl.HandleGroupInvitationsAccept(), userMW...))+r.Get("/groups/statistics", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatistics(), userMW...))r.Get("/groups/statistics/purchase-price", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatisticsPriceOverTime(), userMW...))r.Get("/groups/statistics/locations", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatisticsLocations(), userMW...))diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.goindex a62ff381..ea89e3fb 100644--- a/backend/app/api/static/docs/docs.go+++ b/backend/app/api/static/docs/docs.go@@ -5424,6 +5424,9 @@ const docTemplate = `{"expiresAt": {"type": "string"},+ "id": {+ "type": "string"+ },"token": {"type": "string"},diff --git a/backend/app/api/static/docs/openapi-3.json b/backend/app/api/static/docs/openapi-3.jsonindex afb7ef32..2f694ac7 100644--- a/backend/app/api/static/docs/openapi-3.json+++ b/backend/app/api/static/docs/openapi-3.json@@ -5621,6 +5621,9 @@"expiresAt": {"type": "string"},+ "id": {+ "type": "string"+ },"token": {"type": "string"},diff --git a/backend/app/api/static/docs/openapi-3.yaml b/backend/app/api/static/docs/openapi-3.yamlindex 50be7f5a..ff303844 100644--- a/backend/app/api/static/docs/openapi-3.yaml+++ b/backend/app/api/static/docs/openapi-3.yaml@@ -3586,6 +3586,8 @@ components:properties:expiresAt:type: string+ id:+ type: stringtoken:type: stringuses:diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.jsonindex edc7c452..8662b78e 100644--- a/backend/app/api/static/docs/swagger.json+++ b/backend/app/api/static/docs/swagger.json@@ -5422,6 +5422,9 @@"expiresAt": {"type": "string"},+ "id": {+ "type": "string"+ },"token": {"type": "string"},diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yamlindex f42a9d9e..a340de23 100644--- a/backend/app/api/static/docs/swagger.yaml+++ b/backend/app/api/static/docs/swagger.yaml@@ -1836,6 +1836,8 @@ definitions:properties:expiresAt:type: string+ id:+ type: stringtoken:type: stringuses:diff --git a/backend/internal/core/services/service_group.go b/backend/internal/core/services/service_group.goindex 25126c7e..74572cce 100644--- a/backend/internal/core/services/service_group.go+++ b/backend/internal/core/services/service_group.go@@ -41,19 +41,19 @@ func (svc *GroupService) DeleteGroup(ctx Context) error {return svc.repos.Groups.GroupDelete(ctx.Context, ctx.GID)}-func (svc *GroupService) NewInvitation(ctx Context, uses int, expiresAt time.Time) (string, error) {+func (svc *GroupService) NewInvitation(ctx Context, uses int, expiresAt time.Time) (repo.GroupInvitation, string, error) {token := hasher.GenerateToken()- _, err := svc.repos.Groups.InvitationCreate(ctx, ctx.GID, repo.GroupInvitationCreate{+ invitation, err := svc.repos.Groups.InvitationCreate(ctx, ctx.GID, repo.GroupInvitationCreate{Token: token.Hash,Uses: uses,ExpiresAt: expiresAt,})if err != nil {- return "", err+ return repo.GroupInvitation{}, "", err}- return token.Raw, nil+ return invitation, token.Raw, nil}func (svc *GroupService) AddMember(ctx Context, userID uuid.UUID) error {diff --git a/docs/en/api/openapi-2.0.json b/docs/en/api/openapi-2.0.jsonindex edc7c452..8662b78e 100644--- a/docs/en/api/openapi-2.0.json+++ b/docs/en/api/openapi-2.0.json@@ -5422,6 +5422,9 @@"expiresAt": {"type": "string"},+ "id": {+ "type": "string"+ },"token": {"type": "string"},diff --git a/docs/en/api/openapi-2.0.yaml b/docs/en/api/openapi-2.0.yamlindex f42a9d9e..a340de23 100644--- a/docs/en/api/openapi-2.0.yaml+++ b/docs/en/api/openapi-2.0.yaml@@ -1836,6 +1836,8 @@ definitions:properties:expiresAt:type: string+ id:+ type: stringtoken:type: stringuses:diff --git a/docs/en/api/openapi-3.0.json b/docs/en/api/openapi-3.0.jsonindex afb7ef32..2f694ac7 100644--- a/docs/en/api/openapi-3.0.json+++ b/docs/en/api/openapi-3.0.json@@ -5621,6 +5621,9 @@"expiresAt": {"type": "string"},+ "id": {+ "type": "string"+ },"token": {"type": "string"},diff --git a/docs/en/api/openapi-3.0.yaml b/docs/en/api/openapi-3.0.yamlindex 50be7f5a..ff303844 100644--- a/docs/en/api/openapi-3.0.yaml+++ b/docs/en/api/openapi-3.0.yaml@@ -3586,6 +3586,8 @@ components:properties:expiresAt:type: string+ id:+ type: stringtoken:type: stringuses:diff --git a/docs/en/api/swagger-2.0.json b/docs/en/api/swagger-2.0.jsonindex edc7c452..8662b78e 100644--- a/docs/en/api/swagger-2.0.json+++ b/docs/en/api/swagger-2.0.json@@ -5422,6 +5422,9 @@"expiresAt": {"type": "string"},+ "id": {+ "type": "string"+ },"token": {"type": "string"},diff --git a/docs/en/api/swagger-2.0.yaml b/docs/en/api/swagger-2.0.yamlindex f42a9d9e..a340de23 100644--- a/docs/en/api/swagger-2.0.yaml+++ b/docs/en/api/swagger-2.0.yaml@@ -1836,6 +1836,8 @@ definitions:properties:expiresAt:type: string+ id:+ type: stringtoken:type: stringuses:diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.tsindex ec1e461e..442f09fa 100644--- a/frontend/lib/api/types/data-contracts.ts+++ b/frontend/lib/api/types/data-contracts.ts@@ -1124,6 +1124,7 @@ export interface GroupAcceptInvitationResponse {export interface GroupInvitation {expiresAt: Date | string;+ id: string;token: string;uses: number;}diff --git a/frontend/pages/collection/index/invites.vue b/frontend/pages/collection/index/invites.vueindex aa225f3b..03b85284 100644--- a/frontend/pages/collection/index/invites.vue+++ b/frontend/pages/collection/index/invites.vue@@ -17,7 +17,7 @@});type Invitation = GroupInvitation & { id: string; group?: Group };- type InvitationResult = GroupInvitation & { id?: string; group?: Group };+ type InvitationResult = GroupInvitation & { id: string; group?: Group };const { t } = useI18n();@@ -60,6 +60,7 @@toast.error(msg);} else {invites.value = (res.data || []) as Invitation[];+ console.log("Loaded invites:", invites.value);}} catch (e) {const msg = (e as Error).message ?? String(e);@@ -76,10 +77,10 @@onClose: (result?: InvitationResult) => {if (!result) return;- const localId = result.id || `local-${Date.now()}-${Math.random().toString(36).slice(2)}`;+ console.log("Created invite:", result);+const localInvite: Invitation = {...(result as InvitationResult),- id: localId,};localInvites.value = [localInvite, ...localInvites.value];