Compare commits

..

1 Commits

Author SHA1 Message Date
Matt Kilgore
c6158e7c9e fix: javascript handles nulls in an incredibly stupid way. 2024-10-05 15:38:31 -04:00
7 changed files with 67 additions and 49 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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

View File

@@ -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

View File

@@ -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": {

View File

@@ -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 */

View File

@@ -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);