Enhance filament schema by adding vendor reference and improving formatting
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
- Introduced a new optional field `vendor` in the filament schema to reference the vendor associated with the filament. - Improved code formatting for better readability and maintainability, including consistent indentation and line breaks. - Ensured that the `recalculate` method remains functional with updated schema structure.
This commit is contained in:
parent
766f4722ea
commit
0a1f75d050
@ -3,9 +3,11 @@ import { generateId } from '../../utils.js';
|
||||
const { Schema } = mongoose;
|
||||
|
||||
// Filament base - cost and tax; color and cost override at FilamentSKU
|
||||
const filamentSchema = new mongoose.Schema({
|
||||
const filamentSchema = new mongoose.Schema(
|
||||
{
|
||||
_reference: { type: String, default: () => generateId()() },
|
||||
name: { required: true, type: String },
|
||||
vendor: { required: false, type: Schema.Types.ObjectId, ref: 'vendor' },
|
||||
barcode: { required: false, type: String },
|
||||
url: { required: false, type: String },
|
||||
image: { required: false, type: Buffer },
|
||||
@ -14,9 +16,15 @@ const filamentSchema = new mongoose.Schema({
|
||||
density: { required: true, type: Number },
|
||||
emptySpoolWeight: { required: true, type: Number },
|
||||
cost: { type: Number, required: false },
|
||||
costTaxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false },
|
||||
costWithTax: { type: Number, required: false },
|
||||
}, { timestamps: true });
|
||||
costTaxRate: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'taxRate',
|
||||
required: false
|
||||
},
|
||||
costWithTax: { type: Number, required: false }
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
filamentSchema.index({ name: 'text', barcode: 'text', url: 'text' });
|
||||
|
||||
@ -28,7 +36,10 @@ filamentSchema.set('toJSON', { virtuals: true });
|
||||
|
||||
filamentSchema.statics.recalculate = async function (filament, user) {
|
||||
const filamentSkuModel = mongoose.model('filamentSku');
|
||||
const skus = await filamentSkuModel.find({ filament: filament._id }).select('_id').lean();
|
||||
const skus = await filamentSkuModel
|
||||
.find({ filament: filament._id })
|
||||
.select('_id')
|
||||
.lean();
|
||||
for (const sku of skus) {
|
||||
await filamentSkuModel.recalculate(sku, user);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user