From 5e81e6010687d8b15cc4bac06e73faedafc735aa Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Fri, 29 Nov 2024 13:18:20 -0500 Subject: [PATCH] fix: #289 Corrects the asset ID to always be correct for the description data. (#351) --- backend/app/api/static/docs/docs.go | 4 ++++ backend/app/api/static/docs/swagger.json | 4 ++++ backend/app/api/static/docs/swagger.yaml | 3 +++ backend/internal/data/repo/repo_items.go | 4 ++++ docs/docs/api/openapi-2.0.json | 4 ++++ frontend/lib/api/types/data-contracts.ts | 2 ++ frontend/pages/reports/label-generator.vue | 13 ++++++------- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 4e3a5db2..a0bba346 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -2286,6 +2286,10 @@ const docTemplate = `{ "archived": { "type": "boolean" }, + "assetId": { + "type": "string", + "example": "0" + }, "createdAt": { "type": "string" }, diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 532020b8..4b84c8ed 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -2279,6 +2279,10 @@ "archived": { "type": "boolean" }, + "assetId": { + "type": "string", + "example": "0" + }, "createdAt": { "type": "string" }, diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index 7939eb3d..14c4abf0 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -217,6 +217,9 @@ definitions: properties: archived: type: boolean + assetId: + example: "0" + type: string createdAt: type: string description: diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index cffc910f..dd6a1c64 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -115,6 +115,7 @@ type ( ItemSummary struct { ImportRef string `json:"-"` ID uuid.UUID `json:"id"` + AssetID AssetID `json:"assetId,string"` Name string `json:"name"` Description string `json:"description"` Quantity int `json:"quantity"` @@ -190,6 +191,7 @@ func mapItemSummary(item *ent.Item) ItemSummary { return ItemSummary{ ID: item.ID, + AssetID: AssetID(item.AssetID), Name: item.Name, Description: item.Description, ImportRef: item.ImportRef, @@ -422,6 +424,8 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite qb = qb.Order(ent.Desc(item.FieldCreatedAt)) case "updatedAt": qb = qb.Order(ent.Desc(item.FieldUpdatedAt)) + case "assetId": + qb = qb.Order(ent.Asc(item.FieldAssetID)) default: // "name" qb = qb.Order(ent.Asc(item.FieldName)) } diff --git a/docs/docs/api/openapi-2.0.json b/docs/docs/api/openapi-2.0.json index 532020b8..4b84c8ed 100644 --- a/docs/docs/api/openapi-2.0.json +++ b/docs/docs/api/openapi-2.0.json @@ -2279,6 +2279,10 @@ "archived": { "type": "boolean" }, + "assetId": { + "type": "string", + "example": "0" + }, "createdAt": { "type": "string" }, diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index c664c93f..a7eb117b 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -134,6 +134,8 @@ export interface ItemPath { export interface ItemSummary { archived: boolean; + /** @example "0" */ + assetId: string; createdAt: Date | string; description: string; id: string; diff --git a/frontend/pages/reports/label-generator.vue b/frontend/pages/reports/label-generator.vue index 2ce40903..e2e6154f 100644 --- a/frontend/pages/reports/label-generator.vue +++ b/frontend/pages/reports/label-generator.vue @@ -183,21 +183,20 @@ return route(`/qrcode`, { data: encodeURIComponent(data) }); } - function getItem(n: number, item: { name: string; location: { name: string } } | null): LabelData { + function getItem(n: number, item: { assetId: string; name: string; location: { name: string } } | null): LabelData { // format n into - seperated string with leading zeros - - const assetID = fmtAssetID(n); + const assetID = fmtAssetID(n + 1); return { url: getQRCodeUrl(assetID), - assetID, + assetID: item?.assetId ?? assetID, name: item?.name ?? "_______________", location: item?.location?.name ?? "_______________", }; } const { data: allFields } = await useAsyncData(async () => { - const { data, error } = await api.items.getAll(); + const { data, error } = await api.items.getAll({ orderBy: "assetId" }); if (error) { return { @@ -220,10 +219,10 @@ } const items: LabelData[] = []; - for (let i = displayProperties.assetRange; i < displayProperties.assetRangeMax; i++) { + for (let i = displayProperties.assetRange - 1; i < displayProperties.assetRangeMax - 1; i++) { const item = allFields?.value?.items?.[i]; if (item?.location) { - items.push(getItem(i, item as { location: { name: string }; name: string })); + items.push(getItem(i, item as { assetId: string; location: { name: string }; name: string })); } else { items.push(getItem(i, null)); }