Skip to content

Commit

Permalink
fix: javascript handles nulls in an incredibly stupid way.
Browse files Browse the repository at this point in the history
  • Loading branch information
tankerkiller125 committed Oct 5, 2024
1 parent 5d3698d commit c6158e7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 49 deletions.
17 changes: 9 additions & 8 deletions backend/app/api/static/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2217,8 +2217,7 @@ const docTemplate = `{
"type": "string"
},
"purchasePrice": {
"type": "string",
"example": "0"
"type": "number"
},
"purchaseTime": {
"description": "Purchase",
Expand All @@ -2234,8 +2233,7 @@ const docTemplate = `{
"type": "string"
},
"soldPrice": {
"type": "string",
"example": "0"
"type": "number"
},
"soldTime": {
"description": "Sold",
Expand Down Expand Up @@ -2323,8 +2321,7 @@ const docTemplate = `{
"type": "string"
},
"purchasePrice": {
"type": "string",
"example": "0"
"type": "number"
},
"quantity": {
"type": "integer"
Expand Down Expand Up @@ -2412,7 +2409,9 @@ const docTemplate = `{
"maxLength": 255
},
"purchasePrice": {
"type": "number"
"type": "number",
"x-nullable": true,
"x-omitempty": true
},
"purchaseTime": {
"description": "Purchase",
Expand All @@ -2429,7 +2428,9 @@ const docTemplate = `{
"type": "string"
},
"soldPrice": {
"type": "number"
"type": "number",
"x-nullable": true,
"x-omitempty": true
},
"soldTime": {
"description": "Sold",
Expand Down
17 changes: 9 additions & 8 deletions backend/app/api/static/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,7 @@
"type": "string"
},
"purchasePrice": {
"type": "string",
"example": "0"
"type": "number"
},
"purchaseTime": {
"description": "Purchase",
Expand All @@ -2227,8 +2226,7 @@
"type": "string"
},
"soldPrice": {
"type": "string",
"example": "0"
"type": "number"
},
"soldTime": {
"description": "Sold",
Expand Down Expand Up @@ -2316,8 +2314,7 @@
"type": "string"
},
"purchasePrice": {
"type": "string",
"example": "0"
"type": "number"
},
"quantity": {
"type": "integer"
Expand Down Expand Up @@ -2405,7 +2402,9 @@
"maxLength": 255
},
"purchasePrice": {
"type": "number"
"type": "number",
"x-nullable": true,
"x-omitempty": true
},
"purchaseTime": {
"description": "Purchase",
Expand All @@ -2422,7 +2421,9 @@
"type": "string"
},
"soldPrice": {
"type": "number"
"type": "number",
"x-nullable": true,
"x-omitempty": true
},
"soldTime": {
"description": "Sold",
Expand Down
13 changes: 7 additions & 6 deletions backend/app/api/static/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ definitions:
purchaseFrom:
type: string
purchasePrice:
example: "0"
type: string
type: number
purchaseTime:
description: Purchase
type: string
Expand All @@ -183,8 +182,7 @@ definitions:
soldNotes:
type: string
soldPrice:
example: "0"
type: string
type: number
soldTime:
description: Sold
type: string
Expand Down Expand Up @@ -242,8 +240,7 @@ definitions:
name:
type: string
purchasePrice:
example: "0"
type: string
type: number
quantity:
type: integer
updatedAt:
Expand Down Expand Up @@ -304,6 +301,8 @@ definitions:
type: string
purchasePrice:
type: number
x-nullable: true
x-omitempty: true
purchaseTime:
description: Purchase
type: string
Expand All @@ -316,6 +315,8 @@ definitions:
type: string
soldPrice:
type: number
x-nullable: true
x-omitempty: true
soldTime:
description: Sold
type: string
Expand Down
8 changes: 4 additions & 4 deletions backend/internal/data/repo/repo_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
36 changes: 21 additions & 15 deletions docs/docs/api/openapi-2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,7 @@
"type": "string"
},
"purchasePrice": {
"type": "string",
"example": "0"
"type": "number"
},
"purchaseTime": {
"description": "Purchase",
Expand All @@ -2227,8 +2226,7 @@
"type": "string"
},
"soldPrice": {
"type": "string",
"example": "0"
"type": "number"
},
"soldTime": {
"description": "Sold",
Expand Down Expand Up @@ -2316,8 +2314,7 @@
"type": "string"
},
"purchasePrice": {
"type": "string",
"example": "0"
"type": "number"
},
"quantity": {
"type": "integer"
Expand All @@ -2340,6 +2337,9 @@
},
"repo.ItemUpdate": {
"type": "object",
"required": [
"name"
],
"properties": {
"archived": {
"type": "boolean"
Expand All @@ -2348,7 +2348,8 @@
"type": "string"
},
"description": {
"type": "string"
"type": "string",
"maxLength": 1000
},
"fields": {
"type": "array",
Expand Down Expand Up @@ -2383,7 +2384,9 @@
"type": "string"
},
"name": {
"type": "string"
"type": "string",
"maxLength": 255,
"minLength": 1
},
"notes": {
"description": "Extras",
Expand All @@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -2756,7 +2763,6 @@
"type": "string"
},
"url": {
"description": "URL field is not exposed to the client",
"type": "string"
},
"userId": {
Expand Down
13 changes: 5 additions & 8 deletions frontend/lib/api/types/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,8 +143,7 @@ export interface ItemSummary {
/** Edges */
location?: LocationSummary | null;
name: string;
/** @example "0" */
purchasePrice: string;
purchasePrice: number;
quantity: number;
updatedAt: Date | string;
}
Expand Down Expand Up @@ -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 */
Expand Down
12 changes: 12 additions & 0 deletions frontend/pages/item/[id]/index/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c6158e7

Please sign in to comment.