Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: javascript handles nulls in an incredibly stupid way.

Matt Kilgorec6158e7c9ebf
diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go
index 79d62ccc..4e3a5db2 100644
--- a/backend/app/api/static/docs/docs.go
+++ b/backend/app/api/static/docs/docs.go
@@ -2217,8 +2217,7 @@ const docTemplate = `{
"type": "string"
},
"purchasePrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"purchaseTime": {
"description": "Purchase",
@@ -2234,8 +2233,7 @@ const docTemplate = `{
"type": "string"
},
"soldPrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"soldTime": {
"description": "Sold",
@@ -2323,8 +2321,7 @@ const docTemplate = `{
"type": "string"
},
"purchasePrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"quantity": {
"type": "integer"
@@ -2412,7 +2409,9 @@ const docTemplate = `{
"maxLength": 255
},
"purchasePrice": {
- "type": "number"
+ "type": "number",
+ "x-nullable": true,
+ "x-omitempty": true
},
"purchaseTime": {
"description": "Purchase",
@@ -2429,7 +2428,9 @@ const docTemplate = `{
"type": "string"
},
"soldPrice": {
- "type": "number"
+ "type": "number",
+ "x-nullable": true,
+ "x-omitempty": true
},
"soldTime": {
"description": "Sold",
diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json
index addf7280..532020b8 100644
--- a/backend/app/api/static/docs/swagger.json
+++ b/backend/app/api/static/docs/swagger.json
@@ -2210,8 +2210,7 @@
"type": "string"
},
"purchasePrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"purchaseTime": {
"description": "Purchase",
@@ -2227,8 +2226,7 @@
"type": "string"
},
"soldPrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"soldTime": {
"description": "Sold",
@@ -2316,8 +2314,7 @@
"type": "string"
},
"purchasePrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"quantity": {
"type": "integer"
@@ -2405,7 +2402,9 @@
"maxLength": 255
},
"purchasePrice": {
- "type": "number"
+ "type": "number",
+ "x-nullable": true,
+ "x-omitempty": true
},
"purchaseTime": {
"description": "Purchase",
@@ -2422,7 +2421,9 @@
"type": "string"
},
"soldPrice": {
- "type": "number"
+ "type": "number",
+ "x-nullable": true,
+ "x-omitempty": true
},
"soldTime": {
"description": "Sold",
diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml
index a7211acb..7939eb3d 100644
--- a/backend/app/api/static/docs/swagger.yaml
+++ b/backend/app/api/static/docs/swagger.yaml
@@ -171,8 +171,7 @@ definitions:
purchaseFrom:
type: string
purchasePrice:
- example: "0"
- type: string
+ type: number
purchaseTime:
description: Purchase
type: string
@@ -183,8 +182,7 @@ definitions:
soldNotes:
type: string
soldPrice:
- example: "0"
- type: string
+ type: number
soldTime:
description: Sold
type: string
@@ -242,8 +240,7 @@ definitions:
name:
type: string
purchasePrice:
- example: "0"
- type: string
+ type: number
quantity:
type: integer
updatedAt:
@@ -304,6 +301,8 @@ definitions:
type: string
purchasePrice:
type: number
+ x-nullable: true
+ x-omitempty: true
purchaseTime:
description: Purchase
type: string
@@ -316,6 +315,8 @@ definitions:
type: string
soldPrice:
type: number
+ x-nullable: true
+ x-omitempty: true
soldTime:
description: Sold
type: string
diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go
index d67a60a3..cffc910f 100644
--- a/backend/internal/data/repo/repo_items.go
+++ b/backend/internal/data/repo/repo_items.go
@@ -93,12 +93,12 @@ type (
// Purchase
PurchaseTime types.Date `json:"purchaseTime"`
PurchaseFrom string `json:"purchaseFrom" validate:"max=255"`
- PurchasePrice float64 `json:"purchasePrice"`
+ PurchasePrice float64 `json:"purchasePrice" extensions:"x-nullable,x-omitempty"`
// Sold
SoldTime types.Date `json:"soldTime"`
SoldTo string `json:"soldTo" validate:"max=255"`
- SoldPrice float64 `json:"soldPrice"`
+ SoldPrice float64 `json:"soldPrice" extensions:"x-nullable,x-omitempty"`
SoldNotes string `json:"soldNotes"`
// Extras
@@ -123,7 +123,7 @@ type (
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
- PurchasePrice float64 `json:"purchasePrice,string"`
+ PurchasePrice float64 `json:"purchasePrice"`
// Edges
Location *LocationSummary `json:"location,omitempty" extensions:"x-nullable,x-omitempty"`
@@ -153,7 +153,7 @@ type (
// Sold
SoldTime types.Date `json:"soldTime"`
SoldTo string `json:"soldTo"`
- SoldPrice float64 `json:"soldPrice,string"`
+ SoldPrice float64 `json:"soldPrice"`
SoldNotes string `json:"soldNotes"`
// Extras
diff --git a/docs/docs/api/openapi-2.0.json b/docs/docs/api/openapi-2.0.json
index 12e556ce..532020b8 100644
--- a/docs/docs/api/openapi-2.0.json
+++ b/docs/docs/api/openapi-2.0.json
@@ -2210,8 +2210,7 @@
"type": "string"
},
"purchasePrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"purchaseTime": {
"description": "Purchase",
@@ -2227,8 +2226,7 @@
"type": "string"
},
"soldPrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"soldTime": {
"description": "Sold",
@@ -2316,8 +2314,7 @@
"type": "string"
},
"purchasePrice": {
- "type": "string",
- "example": "0"
+ "type": "number"
},
"quantity": {
"type": "integer"
@@ -2340,6 +2337,9 @@
},
"repo.ItemUpdate": {
"type": "object",
+ "required": [
+ "name"
+ ],
"properties": {
"archived": {
"type": "boolean"
@@ -2348,7 +2348,8 @@
"type": "string"
},
"description": {
- "type": "string"
+ "type": "string",
+ "maxLength": 1000
},
"fields": {
"type": "array",
@@ -2383,7 +2384,9 @@
"type": "string"
},
"name": {
- "type": "string"
+ "type": "string",
+ "maxLength": 255,
+ "minLength": 1
},
"notes": {
"description": "Extras",
@@ -2395,11 +2398,13 @@
"x-omitempty": true
},
"purchaseFrom": {
- "type": "string"
+ "type": "string",
+ "maxLength": 255
},
"purchasePrice": {
- "type": "string",
- "example": "0"
+ "type": "number",
+ "x-nullable": true,
+ "x-omitempty": true
},
"purchaseTime": {
"description": "Purchase",
@@ -2416,15 +2421,17 @@
"type": "string"
},
"soldPrice": {
- "type": "string",
- "example": "0"
+ "type": "number",
+ "x-nullable": true,
+ "x-omitempty": true
},
"soldTime": {
"description": "Sold",
"type": "string"
},
"soldTo": {
- "type": "string"
+ "type": "string",
+ "maxLength": 255
},
"warrantyDetails": {
"type": "string"
@@ -2756,7 +2763,6 @@
"type": "string"
},
"url": {
- "description": "URL field is not exposed to the client",
"type": "string"
},
"userId": {
diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts
index 952e4f1e..c664c93f 100644
--- a/frontend/lib/api/types/data-contracts.ts
+++ b/frontend/lib/api/types/data-contracts.ts
@@ -106,15 +106,13 @@ export interface ItemOut {
notes: string;
parent?: ItemSummary | null;
purchaseFrom: string;
- /** @example "0" */
- purchasePrice: string;
+ purchasePrice: number;
/** Purchase */
purchaseTime: Date | string;
quantity: number;
serialNumber: string;
soldNotes: string;
- /** @example "0" */
- soldPrice: string;
+ soldPrice: number;
/** Sold */
soldTime: Date | string;
soldTo: string;
@@ -145,8 +143,7 @@ export interface ItemSummary {
/** Edges */
location?: LocationSummary | null;
name: string;
- /** @example "0" */
- purchasePrice: string;
+ purchasePrice: number;
quantity: number;
updatedAt: Date | string;
}
@@ -181,14 +178,14 @@ export interface ItemUpdate {
parentId?: string | null;
/** @maxLength 255 */
purchaseFrom: string;
- purchasePrice: number;
+ purchasePrice?: number | null;
/** Purchase */
purchaseTime: Date | string;
quantity: number;
/** Identifications */
serialNumber: string;
soldNotes: string;
- soldPrice: number;
+ soldPrice?: number | null;
/** Sold */
soldTime: Date | string;
/** @maxLength 255 */
diff --git a/frontend/pages/item/[id]/index/edit.vue b/frontend/pages/item/[id]/index/edit.vue
index 2d9c9a70..1f3cd0bc 100644
--- a/frontend/pages/item/[id]/index/edit.vue
+++ b/frontend/pages/item/[id]/index/edit.vue
@@ -65,12 +65,24 @@
return;
}
+ let purchasePrice = 0;
+ let soldPrice = 0;
+ if (item.value.purchasePrice) {
+ purchasePrice = item.value.purchasePrice;
+ }
+ if (item.value.soldPrice) {
+ soldPrice = item.value.soldPrice;
+ }
+ console.log((item.value.purchasePrice ??= 0));
+ console.log((item.value.soldPrice ??= 0));
const payload: ItemUpdate = {
...item.value,
locationId: item.value.location?.id,
labelIds: item.value.labels.map(l => l.id),
parentId: parent.value ? parent.value.id : null,
assetId: item.value.assetId,
+ purchasePrice,
+ soldPrice,
};
const { error } = await api.items.update(itemId.value, payload);