Skip to content

Commit c6158e7

Browse files
fix: javascript handles nulls in an incredibly stupid way.
1 parent 5d3698d commit c6158e7

File tree

7 files changed

+67
-49
lines changed

7 files changed

+67
-49
lines changed

backend/app/api/static/docs/docs.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -2217,8 +2217,7 @@ const docTemplate = `{
22172217
"type": "string"
22182218
},
22192219
"purchasePrice": {
2220-
"type": "string",
2221-
"example": "0"
2220+
"type": "number"
22222221
},
22232222
"purchaseTime": {
22242223
"description": "Purchase",
@@ -2234,8 +2233,7 @@ const docTemplate = `{
22342233
"type": "string"
22352234
},
22362235
"soldPrice": {
2237-
"type": "string",
2238-
"example": "0"
2236+
"type": "number"
22392237
},
22402238
"soldTime": {
22412239
"description": "Sold",
@@ -2323,8 +2321,7 @@ const docTemplate = `{
23232321
"type": "string"
23242322
},
23252323
"purchasePrice": {
2326-
"type": "string",
2327-
"example": "0"
2324+
"type": "number"
23282325
},
23292326
"quantity": {
23302327
"type": "integer"
@@ -2412,7 +2409,9 @@ const docTemplate = `{
24122409
"maxLength": 255
24132410
},
24142411
"purchasePrice": {
2415-
"type": "number"
2412+
"type": "number",
2413+
"x-nullable": true,
2414+
"x-omitempty": true
24162415
},
24172416
"purchaseTime": {
24182417
"description": "Purchase",
@@ -2429,7 +2428,9 @@ const docTemplate = `{
24292428
"type": "string"
24302429
},
24312430
"soldPrice": {
2432-
"type": "number"
2431+
"type": "number",
2432+
"x-nullable": true,
2433+
"x-omitempty": true
24332434
},
24342435
"soldTime": {
24352436
"description": "Sold",

backend/app/api/static/docs/swagger.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,7 @@
22102210
"type": "string"
22112211
},
22122212
"purchasePrice": {
2213-
"type": "string",
2214-
"example": "0"
2213+
"type": "number"
22152214
},
22162215
"purchaseTime": {
22172216
"description": "Purchase",
@@ -2227,8 +2226,7 @@
22272226
"type": "string"
22282227
},
22292228
"soldPrice": {
2230-
"type": "string",
2231-
"example": "0"
2229+
"type": "number"
22322230
},
22332231
"soldTime": {
22342232
"description": "Sold",
@@ -2316,8 +2314,7 @@
23162314
"type": "string"
23172315
},
23182316
"purchasePrice": {
2319-
"type": "string",
2320-
"example": "0"
2317+
"type": "number"
23212318
},
23222319
"quantity": {
23232320
"type": "integer"
@@ -2405,7 +2402,9 @@
24052402
"maxLength": 255
24062403
},
24072404
"purchasePrice": {
2408-
"type": "number"
2405+
"type": "number",
2406+
"x-nullable": true,
2407+
"x-omitempty": true
24092408
},
24102409
"purchaseTime": {
24112410
"description": "Purchase",
@@ -2422,7 +2421,9 @@
24222421
"type": "string"
24232422
},
24242423
"soldPrice": {
2425-
"type": "number"
2424+
"type": "number",
2425+
"x-nullable": true,
2426+
"x-omitempty": true
24262427
},
24272428
"soldTime": {
24282429
"description": "Sold",

backend/app/api/static/docs/swagger.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ definitions:
171171
purchaseFrom:
172172
type: string
173173
purchasePrice:
174-
example: "0"
175-
type: string
174+
type: number
176175
purchaseTime:
177176
description: Purchase
178177
type: string
@@ -183,8 +182,7 @@ definitions:
183182
soldNotes:
184183
type: string
185184
soldPrice:
186-
example: "0"
187-
type: string
185+
type: number
188186
soldTime:
189187
description: Sold
190188
type: string
@@ -242,8 +240,7 @@ definitions:
242240
name:
243241
type: string
244242
purchasePrice:
245-
example: "0"
246-
type: string
243+
type: number
247244
quantity:
248245
type: integer
249246
updatedAt:
@@ -304,6 +301,8 @@ definitions:
304301
type: string
305302
purchasePrice:
306303
type: number
304+
x-nullable: true
305+
x-omitempty: true
307306
purchaseTime:
308307
description: Purchase
309308
type: string
@@ -316,6 +315,8 @@ definitions:
316315
type: string
317316
soldPrice:
318317
type: number
318+
x-nullable: true
319+
x-omitempty: true
319320
soldTime:
320321
description: Sold
321322
type: string

backend/internal/data/repo/repo_items.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ type (
9393
// Purchase
9494
PurchaseTime types.Date `json:"purchaseTime"`
9595
PurchaseFrom string `json:"purchaseFrom" validate:"max=255"`
96-
PurchasePrice float64 `json:"purchasePrice"`
96+
PurchasePrice float64 `json:"purchasePrice" extensions:"x-nullable,x-omitempty"`
9797

9898
// Sold
9999
SoldTime types.Date `json:"soldTime"`
100100
SoldTo string `json:"soldTo" validate:"max=255"`
101-
SoldPrice float64 `json:"soldPrice"`
101+
SoldPrice float64 `json:"soldPrice" extensions:"x-nullable,x-omitempty"`
102102
SoldNotes string `json:"soldNotes"`
103103

104104
// Extras
@@ -123,7 +123,7 @@ type (
123123
CreatedAt time.Time `json:"createdAt"`
124124
UpdatedAt time.Time `json:"updatedAt"`
125125

126-
PurchasePrice float64 `json:"purchasePrice,string"`
126+
PurchasePrice float64 `json:"purchasePrice"`
127127

128128
// Edges
129129
Location *LocationSummary `json:"location,omitempty" extensions:"x-nullable,x-omitempty"`
@@ -153,7 +153,7 @@ type (
153153
// Sold
154154
SoldTime types.Date `json:"soldTime"`
155155
SoldTo string `json:"soldTo"`
156-
SoldPrice float64 `json:"soldPrice,string"`
156+
SoldPrice float64 `json:"soldPrice"`
157157
SoldNotes string `json:"soldNotes"`
158158

159159
// Extras

docs/docs/api/openapi-2.0.json

+21-15
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,7 @@
22102210
"type": "string"
22112211
},
22122212
"purchasePrice": {
2213-
"type": "string",
2214-
"example": "0"
2213+
"type": "number"
22152214
},
22162215
"purchaseTime": {
22172216
"description": "Purchase",
@@ -2227,8 +2226,7 @@
22272226
"type": "string"
22282227
},
22292228
"soldPrice": {
2230-
"type": "string",
2231-
"example": "0"
2229+
"type": "number"
22322230
},
22332231
"soldTime": {
22342232
"description": "Sold",
@@ -2316,8 +2314,7 @@
23162314
"type": "string"
23172315
},
23182316
"purchasePrice": {
2319-
"type": "string",
2320-
"example": "0"
2317+
"type": "number"
23212318
},
23222319
"quantity": {
23232320
"type": "integer"
@@ -2340,6 +2337,9 @@
23402337
},
23412338
"repo.ItemUpdate": {
23422339
"type": "object",
2340+
"required": [
2341+
"name"
2342+
],
23432343
"properties": {
23442344
"archived": {
23452345
"type": "boolean"
@@ -2348,7 +2348,8 @@
23482348
"type": "string"
23492349
},
23502350
"description": {
2351-
"type": "string"
2351+
"type": "string",
2352+
"maxLength": 1000
23522353
},
23532354
"fields": {
23542355
"type": "array",
@@ -2383,7 +2384,9 @@
23832384
"type": "string"
23842385
},
23852386
"name": {
2386-
"type": "string"
2387+
"type": "string",
2388+
"maxLength": 255,
2389+
"minLength": 1
23872390
},
23882391
"notes": {
23892392
"description": "Extras",
@@ -2395,11 +2398,13 @@
23952398
"x-omitempty": true
23962399
},
23972400
"purchaseFrom": {
2398-
"type": "string"
2401+
"type": "string",
2402+
"maxLength": 255
23992403
},
24002404
"purchasePrice": {
2401-
"type": "string",
2402-
"example": "0"
2405+
"type": "number",
2406+
"x-nullable": true,
2407+
"x-omitempty": true
24032408
},
24042409
"purchaseTime": {
24052410
"description": "Purchase",
@@ -2416,15 +2421,17 @@
24162421
"type": "string"
24172422
},
24182423
"soldPrice": {
2419-
"type": "string",
2420-
"example": "0"
2424+
"type": "number",
2425+
"x-nullable": true,
2426+
"x-omitempty": true
24212427
},
24222428
"soldTime": {
24232429
"description": "Sold",
24242430
"type": "string"
24252431
},
24262432
"soldTo": {
2427-
"type": "string"
2433+
"type": "string",
2434+
"maxLength": 255
24282435
},
24292436
"warrantyDetails": {
24302437
"type": "string"
@@ -2756,7 +2763,6 @@
27562763
"type": "string"
27572764
},
27582765
"url": {
2759-
"description": "URL field is not exposed to the client",
27602766
"type": "string"
27612767
},
27622768
"userId": {

frontend/lib/api/types/data-contracts.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ export interface ItemOut {
106106
notes: string;
107107
parent?: ItemSummary | null;
108108
purchaseFrom: string;
109-
/** @example "0" */
110-
purchasePrice: string;
109+
purchasePrice: number;
111110
/** Purchase */
112111
purchaseTime: Date | string;
113112
quantity: number;
114113
serialNumber: string;
115114
soldNotes: string;
116-
/** @example "0" */
117-
soldPrice: string;
115+
soldPrice: number;
118116
/** Sold */
119117
soldTime: Date | string;
120118
soldTo: string;
@@ -145,8 +143,7 @@ export interface ItemSummary {
145143
/** Edges */
146144
location?: LocationSummary | null;
147145
name: string;
148-
/** @example "0" */
149-
purchasePrice: string;
146+
purchasePrice: number;
150147
quantity: number;
151148
updatedAt: Date | string;
152149
}
@@ -181,14 +178,14 @@ export interface ItemUpdate {
181178
parentId?: string | null;
182179
/** @maxLength 255 */
183180
purchaseFrom: string;
184-
purchasePrice: number;
181+
purchasePrice?: number | null;
185182
/** Purchase */
186183
purchaseTime: Date | string;
187184
quantity: number;
188185
/** Identifications */
189186
serialNumber: string;
190187
soldNotes: string;
191-
soldPrice: number;
188+
soldPrice?: number | null;
192189
/** Sold */
193190
soldTime: Date | string;
194191
/** @maxLength 255 */

frontend/pages/item/[id]/index/edit.vue

+12
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,24 @@
6565
return;
6666
}
6767
68+
let purchasePrice = 0;
69+
let soldPrice = 0;
70+
if (item.value.purchasePrice) {
71+
purchasePrice = item.value.purchasePrice;
72+
}
73+
if (item.value.soldPrice) {
74+
soldPrice = item.value.soldPrice;
75+
}
76+
console.log((item.value.purchasePrice ??= 0));
77+
console.log((item.value.soldPrice ??= 0));
6878
const payload: ItemUpdate = {
6979
...item.value,
7080
locationId: item.value.location?.id,
7181
labelIds: item.value.labels.map(l => l.id),
7282
parentId: parent.value ? parent.value.id : null,
7383
assetId: item.value.assetId,
84+
purchasePrice,
85+
soldPrice,
7486
};
7587
7688
const { error } = await api.items.update(itemId.value, payload);

0 commit comments

Comments
 (0)