From 7611d1165580a271d06232c57030c3e7a340676b Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sun, 8 Mar 2026 02:07:36 +0000 Subject: [PATCH] Refactor Filament, FilamentSku, PartSku, and ProductSku models to improve code readability by restructuring columns, filters, and sorters. Enhance Filament model with a visibility condition for the divider. Clean up formatting for better consistency across models. --- src/database/models/FilamentSku.js | 40 ++++++++++++++++---- src/database/models/PartSku.js | 28 ++++++++------ src/database/models/ProductSku.js | 61 ++++++++++++++++++++---------- 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/src/database/models/FilamentSku.js b/src/database/models/FilamentSku.js index 7457e28..8b41a09 100644 --- a/src/database/models/FilamentSku.js +++ b/src/database/models/FilamentSku.js @@ -18,7 +18,8 @@ export const FilamentSku = { default: true, row: true, icon: InfoCircleIcon, - url: (_id) => `/dashboard/management/filamentskus/info?filamentSkuId=${_id}` + url: (_id) => + `/dashboard/management/filamentskus/info?filamentSkuId=${_id}` }, { name: 'reload', @@ -69,9 +70,36 @@ export const FilamentSku = { } ], url: (id) => `/dashboard/management/filamentskus/info?filamentSkuId=${id}`, - columns: ['_reference', 'barcode', 'filament', 'name', 'color', 'overrideCost', 'cost', 'createdAt', 'updatedAt'], - filters: ['_id', 'barcode', 'filament', 'filament._id', 'name', 'color', 'cost'], - sorters: ['barcode', 'filament', 'name', 'color', 'cost', 'createdAt', 'updatedAt'], + columns: [ + '_reference', + 'name', + 'filament', + + 'barcode', + 'color', + 'overrideCost', + 'cost', + 'createdAt', + 'updatedAt' + ], + filters: [ + '_id', + 'barcode', + 'filament', + 'filament._id', + 'name', + 'color', + 'cost' + ], + sorters: [ + 'barcode', + 'filament', + 'name', + 'color', + 'cost', + 'createdAt', + 'updatedAt' + ], properties: [ { name: '_id', @@ -160,9 +188,7 @@ export const FilamentSku = { const taxRate = objectData?.costTaxRate if (!cost) return undefined if (taxRate?.rateType == 'percentage') { - return ( - (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined - ) + return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined } else if (taxRate?.rateType == 'amount') { return (cost + taxRate?.rate).toFixed(2) || undefined } diff --git a/src/database/models/PartSku.js b/src/database/models/PartSku.js index 0c7721c..9961a91 100644 --- a/src/database/models/PartSku.js +++ b/src/database/models/PartSku.js @@ -71,9 +71,10 @@ export const PartSku = { url: (id) => `/dashboard/management/partskus/info?partSkuId=${id}`, columns: [ '_reference', - 'barcode', - 'part', 'name', + 'part', + + 'barcode', 'overrideCost', 'cost', 'overridePrice', @@ -82,7 +83,15 @@ export const PartSku = { 'updatedAt' ], filters: ['_id', 'barcode', 'part', 'part._id', 'name', 'cost', 'price'], - sorters: ['barcode', 'part', 'name', 'cost', 'price', 'createdAt', 'updatedAt'], + sorters: [ + 'barcode', + 'part', + 'name', + 'cost', + 'price', + 'createdAt', + 'updatedAt' + ], properties: [ { name: '_id', @@ -220,9 +229,7 @@ export const PartSku = { margin !== null && cost != null ) { - return ( - (cost * (1 + margin / 100)).toFixed(2) || undefined - ) + return (cost * (1 + margin / 100)).toFixed(2) || undefined } return objectData?.price } @@ -245,17 +252,14 @@ export const PartSku = { ? objectData?.cost : objectData?.part?.cost const margin = objectData?.margin ?? objectData?.part?.margin - if ( - priceMode == 'margin' && - margin != null && - cost != null - ) { + if (priceMode == 'margin' && margin != null && cost != null) { price = cost * (1 + margin / 100) } else { price = objectData?.price } if (price == null) return undefined - const taxRate = objectData?.priceTaxRate ?? objectData?.part?.priceTaxRate + const taxRate = + objectData?.priceTaxRate ?? objectData?.part?.priceTaxRate if (taxRate?.rateType == 'percentage') { return (price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined } else if (taxRate?.rateType == 'amount') { diff --git a/src/database/models/ProductSku.js b/src/database/models/ProductSku.js index be0f97a..871b621 100644 --- a/src/database/models/ProductSku.js +++ b/src/database/models/ProductSku.js @@ -69,9 +69,36 @@ export const ProductSku = { } ], url: (id) => `/dashboard/management/productskus/info?productSkuId=${id}`, - columns: ['_reference', 'barcode', 'product', 'name', 'overrideCost', 'cost', 'overridePrice', 'price', 'createdAt', 'updatedAt'], - filters: ['_id', 'barcode', 'product', 'product._id', 'name', 'cost', 'price'], - sorters: ['barcode', 'product', 'name', 'cost', 'price', 'createdAt', 'updatedAt'], + columns: [ + '_reference', + 'name', + 'product', + 'barcode', + 'overrideCost', + 'cost', + 'overridePrice', + 'price', + 'createdAt', + 'updatedAt' + ], + filters: [ + '_id', + 'barcode', + 'product', + 'product._id', + 'name', + 'cost', + 'price' + ], + sorters: [ + 'barcode', + 'product', + 'name', + 'cost', + 'price', + 'createdAt', + 'updatedAt' + ], properties: [ { name: '_id', @@ -87,6 +114,7 @@ export const ProductSku = { type: 'dateTime', readOnly: true }, + { name: 'name', label: 'Name', @@ -167,9 +195,7 @@ export const ProductSku = { const taxRate = objectData?.costTaxRate if (!cost) return undefined if (taxRate?.rateType == 'percentage') { - return ( - (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined - ) + return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined } else if (taxRate?.rateType == 'amount') { return (cost + taxRate?.rate).toFixed(2) || undefined } @@ -200,7 +226,8 @@ export const ProductSku = { objectData?.overridePrice && objectData?.priceMode == 'margin', value: (objectData) => { if (!objectData?.overridePrice) return undefined - const priceMode = objectData?.priceMode ?? objectData?.product?.priceMode + const priceMode = + objectData?.priceMode ?? objectData?.product?.priceMode const cost = objectData?.overrideCost ? objectData?.cost : objectData?.product?.cost @@ -211,9 +238,7 @@ export const ProductSku = { margin !== null && cost != null ) { - return ( - (cost * (1 + margin / 100)).toFixed(2) || undefined - ) + return (cost * (1 + margin / 100)).toFixed(2) || undefined } return objectData?.price } @@ -231,26 +256,22 @@ export const ProductSku = { value: (objectData) => { if (!objectData?.overridePrice) return undefined let price - const priceMode = objectData?.priceMode ?? objectData?.product?.priceMode + const priceMode = + objectData?.priceMode ?? objectData?.product?.priceMode const cost = objectData?.overrideCost ? objectData?.cost : objectData?.product?.cost const margin = objectData?.margin ?? objectData?.product?.margin - if ( - priceMode == 'margin' && - margin != null && - cost != null - ) { + if (priceMode == 'margin' && margin != null && cost != null) { price = cost * (1 + margin / 100) } else { price = objectData?.price } if (price == null) return undefined - const taxRate = objectData?.priceTaxRate ?? objectData?.product?.priceTaxRate + const taxRate = + objectData?.priceTaxRate ?? objectData?.product?.priceTaxRate if (taxRate?.rateType == 'percentage') { - return ( - (price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined - ) + return (price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined } else if (taxRate?.rateType == 'amount') { return (price + taxRate?.rate).toFixed(2) || undefined }