fix: javascript handles nulls in an incredibly stupid way.

This commit is contained in:
Matt Kilgore
2024-10-05 15:38:31 -04:00
parent 5d3698d0d8
commit c6158e7c9e
7 changed files with 67 additions and 49 deletions

View File

@@ -2217,8 +2217,7 @@ const docTemplate = `{
"type": "string" "type": "string"
}, },
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"purchaseTime": { "purchaseTime": {
"description": "Purchase", "description": "Purchase",
@@ -2234,8 +2233,7 @@ const docTemplate = `{
"type": "string" "type": "string"
}, },
"soldPrice": { "soldPrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"soldTime": { "soldTime": {
"description": "Sold", "description": "Sold",
@@ -2323,8 +2321,7 @@ const docTemplate = `{
"type": "string" "type": "string"
}, },
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"quantity": { "quantity": {
"type": "integer" "type": "integer"
@@ -2412,7 +2409,9 @@ const docTemplate = `{
"maxLength": 255 "maxLength": 255
}, },
"purchasePrice": { "purchasePrice": {
"type": "number" "type": "number",
"x-nullable": true,
"x-omitempty": true
}, },
"purchaseTime": { "purchaseTime": {
"description": "Purchase", "description": "Purchase",
@@ -2429,7 +2428,9 @@ const docTemplate = `{
"type": "string" "type": "string"
}, },
"soldPrice": { "soldPrice": {
"type": "number" "type": "number",
"x-nullable": true,
"x-omitempty": true
}, },
"soldTime": { "soldTime": {
"description": "Sold", "description": "Sold",

View File

@@ -2210,8 +2210,7 @@
"type": "string" "type": "string"
}, },
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"purchaseTime": { "purchaseTime": {
"description": "Purchase", "description": "Purchase",
@@ -2227,8 +2226,7 @@
"type": "string" "type": "string"
}, },
"soldPrice": { "soldPrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"soldTime": { "soldTime": {
"description": "Sold", "description": "Sold",
@@ -2316,8 +2314,7 @@
"type": "string" "type": "string"
}, },
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"quantity": { "quantity": {
"type": "integer" "type": "integer"
@@ -2405,7 +2402,9 @@
"maxLength": 255 "maxLength": 255
}, },
"purchasePrice": { "purchasePrice": {
"type": "number" "type": "number",
"x-nullable": true,
"x-omitempty": true
}, },
"purchaseTime": { "purchaseTime": {
"description": "Purchase", "description": "Purchase",
@@ -2422,7 +2421,9 @@
"type": "string" "type": "string"
}, },
"soldPrice": { "soldPrice": {
"type": "number" "type": "number",
"x-nullable": true,
"x-omitempty": true
}, },
"soldTime": { "soldTime": {
"description": "Sold", "description": "Sold",

View File

@@ -171,8 +171,7 @@ definitions:
purchaseFrom: purchaseFrom:
type: string type: string
purchasePrice: purchasePrice:
example: "0" type: number
type: string
purchaseTime: purchaseTime:
description: Purchase description: Purchase
type: string type: string
@@ -183,8 +182,7 @@ definitions:
soldNotes: soldNotes:
type: string type: string
soldPrice: soldPrice:
example: "0" type: number
type: string
soldTime: soldTime:
description: Sold description: Sold
type: string type: string
@@ -242,8 +240,7 @@ definitions:
name: name:
type: string type: string
purchasePrice: purchasePrice:
example: "0" type: number
type: string
quantity: quantity:
type: integer type: integer
updatedAt: updatedAt:
@@ -304,6 +301,8 @@ definitions:
type: string type: string
purchasePrice: purchasePrice:
type: number type: number
x-nullable: true
x-omitempty: true
purchaseTime: purchaseTime:
description: Purchase description: Purchase
type: string type: string
@@ -316,6 +315,8 @@ definitions:
type: string type: string
soldPrice: soldPrice:
type: number type: number
x-nullable: true
x-omitempty: true
soldTime: soldTime:
description: Sold description: Sold
type: string type: string

View File

@@ -93,12 +93,12 @@ type (
// Purchase // Purchase
PurchaseTime types.Date `json:"purchaseTime"` PurchaseTime types.Date `json:"purchaseTime"`
PurchaseFrom string `json:"purchaseFrom" validate:"max=255"` PurchaseFrom string `json:"purchaseFrom" validate:"max=255"`
PurchasePrice float64 `json:"purchasePrice"` PurchasePrice float64 `json:"purchasePrice" extensions:"x-nullable,x-omitempty"`
// Sold // Sold
SoldTime types.Date `json:"soldTime"` SoldTime types.Date `json:"soldTime"`
SoldTo string `json:"soldTo" validate:"max=255"` SoldTo string `json:"soldTo" validate:"max=255"`
SoldPrice float64 `json:"soldPrice"` SoldPrice float64 `json:"soldPrice" extensions:"x-nullable,x-omitempty"`
SoldNotes string `json:"soldNotes"` SoldNotes string `json:"soldNotes"`
// Extras // Extras
@@ -123,7 +123,7 @@ type (
CreatedAt time.Time `json:"createdAt"` CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"` UpdatedAt time.Time `json:"updatedAt"`
PurchasePrice float64 `json:"purchasePrice,string"` PurchasePrice float64 `json:"purchasePrice"`
// Edges // Edges
Location *LocationSummary `json:"location,omitempty" extensions:"x-nullable,x-omitempty"` Location *LocationSummary `json:"location,omitempty" extensions:"x-nullable,x-omitempty"`
@@ -153,7 +153,7 @@ type (
// Sold // Sold
SoldTime types.Date `json:"soldTime"` SoldTime types.Date `json:"soldTime"`
SoldTo string `json:"soldTo"` SoldTo string `json:"soldTo"`
SoldPrice float64 `json:"soldPrice,string"` SoldPrice float64 `json:"soldPrice"`
SoldNotes string `json:"soldNotes"` SoldNotes string `json:"soldNotes"`
// Extras // Extras

View File

@@ -2210,8 +2210,7 @@
"type": "string" "type": "string"
}, },
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"purchaseTime": { "purchaseTime": {
"description": "Purchase", "description": "Purchase",
@@ -2227,8 +2226,7 @@
"type": "string" "type": "string"
}, },
"soldPrice": { "soldPrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"soldTime": { "soldTime": {
"description": "Sold", "description": "Sold",
@@ -2316,8 +2314,7 @@
"type": "string" "type": "string"
}, },
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "number"
"example": "0"
}, },
"quantity": { "quantity": {
"type": "integer" "type": "integer"
@@ -2340,6 +2337,9 @@
}, },
"repo.ItemUpdate": { "repo.ItemUpdate": {
"type": "object", "type": "object",
"required": [
"name"
],
"properties": { "properties": {
"archived": { "archived": {
"type": "boolean" "type": "boolean"
@@ -2348,7 +2348,8 @@
"type": "string" "type": "string"
}, },
"description": { "description": {
"type": "string" "type": "string",
"maxLength": 1000
}, },
"fields": { "fields": {
"type": "array", "type": "array",
@@ -2383,7 +2384,9 @@
"type": "string" "type": "string"
}, },
"name": { "name": {
"type": "string" "type": "string",
"maxLength": 255,
"minLength": 1
}, },
"notes": { "notes": {
"description": "Extras", "description": "Extras",
@@ -2395,11 +2398,13 @@
"x-omitempty": true "x-omitempty": true
}, },
"purchaseFrom": { "purchaseFrom": {
"type": "string" "type": "string",
"maxLength": 255
}, },
"purchasePrice": { "purchasePrice": {
"type": "string", "type": "number",
"example": "0" "x-nullable": true,
"x-omitempty": true
}, },
"purchaseTime": { "purchaseTime": {
"description": "Purchase", "description": "Purchase",
@@ -2416,15 +2421,17 @@
"type": "string" "type": "string"
}, },
"soldPrice": { "soldPrice": {
"type": "string", "type": "number",
"example": "0" "x-nullable": true,
"x-omitempty": true
}, },
"soldTime": { "soldTime": {
"description": "Sold", "description": "Sold",
"type": "string" "type": "string"
}, },
"soldTo": { "soldTo": {
"type": "string" "type": "string",
"maxLength": 255
}, },
"warrantyDetails": { "warrantyDetails": {
"type": "string" "type": "string"
@@ -2756,7 +2763,6 @@
"type": "string" "type": "string"
}, },
"url": { "url": {
"description": "URL field is not exposed to the client",
"type": "string" "type": "string"
}, },
"userId": { "userId": {

View File

@@ -106,15 +106,13 @@ export interface ItemOut {
notes: string; notes: string;
parent?: ItemSummary | null; parent?: ItemSummary | null;
purchaseFrom: string; purchaseFrom: string;
/** @example "0" */ purchasePrice: number;
purchasePrice: string;
/** Purchase */ /** Purchase */
purchaseTime: Date | string; purchaseTime: Date | string;
quantity: number; quantity: number;
serialNumber: string; serialNumber: string;
soldNotes: string; soldNotes: string;
/** @example "0" */ soldPrice: number;
soldPrice: string;
/** Sold */ /** Sold */
soldTime: Date | string; soldTime: Date | string;
soldTo: string; soldTo: string;
@@ -145,8 +143,7 @@ export interface ItemSummary {
/** Edges */ /** Edges */
location?: LocationSummary | null; location?: LocationSummary | null;
name: string; name: string;
/** @example "0" */ purchasePrice: number;
purchasePrice: string;
quantity: number; quantity: number;
updatedAt: Date | string; updatedAt: Date | string;
} }
@@ -181,14 +178,14 @@ export interface ItemUpdate {
parentId?: string | null; parentId?: string | null;
/** @maxLength 255 */ /** @maxLength 255 */
purchaseFrom: string; purchaseFrom: string;
purchasePrice: number; purchasePrice?: number | null;
/** Purchase */ /** Purchase */
purchaseTime: Date | string; purchaseTime: Date | string;
quantity: number; quantity: number;
/** Identifications */ /** Identifications */
serialNumber: string; serialNumber: string;
soldNotes: string; soldNotes: string;
soldPrice: number; soldPrice?: number | null;
/** Sold */ /** Sold */
soldTime: Date | string; soldTime: Date | string;
/** @maxLength 255 */ /** @maxLength 255 */

View File

@@ -65,12 +65,24 @@
return; 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 = { const payload: ItemUpdate = {
...item.value, ...item.value,
locationId: item.value.location?.id, locationId: item.value.location?.id,
labelIds: item.value.labels.map(l => l.id), labelIds: item.value.labels.map(l => l.id),
parentId: parent.value ? parent.value.id : null, parentId: parent.value ? parent.value.id : null,
assetId: item.value.assetId, assetId: item.value.assetId,
purchasePrice,
soldPrice,
}; };
const { error } = await api.items.update(itemId.value, payload); const { error } = await api.items.update(itemId.value, payload);